feat: memo page contents
This commit is contained in:
@@ -4,7 +4,7 @@ import serialize from "serialize-javascript"
|
||||
|
||||
import { Hydrate, dehydrate } from "@tanstack/react-query"
|
||||
|
||||
import { PageContent } from "~/components/common/PageContent"
|
||||
import PageContent from "~/components/common/PageContent"
|
||||
import { OIAButton } from "~/components/site/OIAButton"
|
||||
import { PostFooter } from "~/components/site/PostFooter"
|
||||
import PostMeta from "~/components/site/PostMeta"
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useAccountState } from "@crossbell/connect-kit"
|
||||
|
||||
import { CharacterFloatCard } from "~/components/common/CharacterFloatCard"
|
||||
import { CommentInput } from "~/components/common/CommentInput"
|
||||
import { PageContent } from "~/components/common/PageContent"
|
||||
import PageContent from "~/components/common/PageContent"
|
||||
import { ReactionLike } from "~/components/common/ReactionLike"
|
||||
import { Titles } from "~/components/common/Titles"
|
||||
import { BlockchainIcon } from "~/components/icons/BlockchainIcon"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type MutableRefObject } from "react"
|
||||
import { type MutableRefObject, memo } from "react"
|
||||
|
||||
import PostActions from "~/components/site/PostActions"
|
||||
import PostToc from "~/components/site/PostToc"
|
||||
@@ -8,7 +8,7 @@ import { renderPageContent } from "~/markdown"
|
||||
|
||||
import { PageContentContainer } from "./PageContentContainer"
|
||||
|
||||
export const PageContent = ({
|
||||
const PageContent = memo(function PageContent({
|
||||
className,
|
||||
content,
|
||||
toc,
|
||||
@@ -32,7 +32,7 @@ export const PageContent = ({
|
||||
page?: ExpandedNote
|
||||
site?: ExpandedCharacter
|
||||
withActions?: boolean
|
||||
}) => {
|
||||
}) {
|
||||
let inParsedContent
|
||||
if (parsedContent) {
|
||||
inParsedContent = parsedContent
|
||||
@@ -56,6 +56,6 @@ export const PageContent = ({
|
||||
</>
|
||||
</PageContentContainer>
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
export default PageContent
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { memo } from "react"
|
||||
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
|
||||
const Style = ({
|
||||
const Style = memo(function Style({
|
||||
content,
|
||||
children,
|
||||
}: {
|
||||
content?: string
|
||||
children?: React.ReactNode[]
|
||||
}) => {
|
||||
}) {
|
||||
let css = content
|
||||
if (!css && typeof children?.[0] === "string") {
|
||||
css = children[0].trim()
|
||||
@@ -24,6 +26,6 @@ const Style = ({
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
export default Style
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { memo } from "react"
|
||||
|
||||
import FadeIn from "~/components/common/FadeIn"
|
||||
import { Image, type TImageProps } from "~/components/ui/Image"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
const AdvancedImage = async (props: TImageProps) => {
|
||||
const AdvancedImage = memo(async function AdvancedImage(props: TImageProps) {
|
||||
let info: {
|
||||
size: {
|
||||
width: number
|
||||
@@ -15,7 +17,11 @@ const AdvancedImage = async (props: TImageProps) => {
|
||||
if (props.src?.startsWith("http")) {
|
||||
try {
|
||||
info = await (
|
||||
await fetch(`${SITE_URL}/api/image?url=${props.src}`)
|
||||
await fetch(
|
||||
`${typeof window === "undefined" ? SITE_URL : ""}/api/image?url=${
|
||||
props.src
|
||||
}`,
|
||||
)
|
||||
).json()
|
||||
} catch (error) {}
|
||||
}
|
||||
@@ -43,6 +49,6 @@ const AdvancedImage = async (props: TImageProps) => {
|
||||
/>
|
||||
</FadeIn>
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
export default AdvancedImage
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { memo } from "react"
|
||||
|
||||
import { GithubRepo as ReactGithubRepo } from "@birdgg/react-github"
|
||||
|
||||
export default function GithubRepo({ repo }: { repo: string }) {
|
||||
export default memo(function GithubRepo({ repo }: { repo: string }) {
|
||||
return <ReactGithubRepo repo={repo} />
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Image from "next/image"
|
||||
import { memo } from "react"
|
||||
import { Tweet as ReactTweet } from "react-tweet"
|
||||
import type { TweetComponents } from "react-tweet"
|
||||
|
||||
@@ -7,10 +8,10 @@ const components: TweetComponents = {
|
||||
MediaImg: (props) => <Image {...props} fill unoptimized alt="tweet-media" />,
|
||||
}
|
||||
|
||||
export default function Tweet({ id }: { id: string }) {
|
||||
export default memo(function Tweet({ id }: { id: string }) {
|
||||
return (
|
||||
<div className="flex justify-center">
|
||||
<ReactTweet id={id} components={components} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user