Skip to content

Commit

Permalink
feat: disable AdvancedImage for server side
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jan 14, 2024
1 parent 2366057 commit b62f1c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
25 changes: 4 additions & 21 deletions src/components/dashboard/DualColumnEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
import { useDebounceEffect } from "ahooks"
import type { Root } from "mdast"
import { useTranslations } from "next-intl"
import dynamic from "next/dynamic"
import { useCallback, useEffect, useMemo, useRef, useState } from "react"

import { EditorView } from "@codemirror/view"

import PageContent from "~/components/common/PageContent"
import { toolbarShortcuts } from "~/components/dashboard/toolbars"
import { editorUpload } from "~/components/dashboard/toolbars/Multimedia"
import CodeMirror from "~/components/ui/CodeMirror"
import { useIsMobileLayout } from "~/hooks/useMobileLayout"
import { useUploadFile } from "~/hooks/useUploadFile"
import { cn } from "~/lib/utils"
import { Rendered, renderPageContent } from "~/markdown"

import { Loading } from "../common/Loading"

const DynamicCodeMirrorEditor = dynamic(
() => import("~/components/ui/CodeMirror"),
{
ssr: false,
loading: () => <Loading className="flex-1 h-12" />,
},
)

const DynamicPageContent = dynamic(
() => import("~/components/common/PageContent"),
{
ssr: false,
loading: () => <Loading className="flex-1 h-12" />,
},
)

export default function DualColumnEditor({
initialContent,
onChange,
Expand Down Expand Up @@ -215,7 +198,7 @@ export default function DualColumnEditor({
return (
<div className="min-h-0 flex relative items-center w-full h-full">
{!(isMobileLayout && isRendering) && (
<DynamicCodeMirrorEditor
<CodeMirror
value={initialContent}
placeholder={t("Start writing") as string}
onChange={onChangeInside}
Expand Down Expand Up @@ -246,7 +229,7 @@ export default function DualColumnEditor({
</div>
)}
{isRendering && (
<DynamicPageContent
<PageContent
className="bg-white px-5 overflow-scroll pb-[200px] h-full flex-1"
parsedContent={parsedContent}
inputRef={previewRef}
Expand Down
10 changes: 3 additions & 7 deletions src/components/ui/AdvancedImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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"
import { cn, isServerSide } from "~/lib/utils"

const AdvancedImage = memo(async function AdvancedImage(props: TImageProps) {
let info: {
Expand All @@ -17,11 +17,7 @@ const AdvancedImage = memo(async function AdvancedImage(props: TImageProps) {
if (props.src?.startsWith("http")) {
try {
info = await (
await fetch(
`${typeof window === "undefined" ? SITE_URL : ""}/api/image?url=${
props.src
}`,
)
await fetch(`${SITE_URL}/api/image?url=${props.src}`)
).json()
} catch (error) {}
}
Expand Down Expand Up @@ -51,4 +47,4 @@ const AdvancedImage = memo(async function AdvancedImage(props: TImageProps) {
)
})

export default AdvancedImage
export default isServerSide() ? AdvancedImage : Image

0 comments on commit b62f1c1

Please sign in to comment.