From af2e1ef3d757cebd5a7300d250552a87cee1a741 Mon Sep 17 00:00:00 2001 From: Zhang Minghan Date: Wed, 4 Oct 2023 10:31:39 +0800 Subject: [PATCH] fix editor in production env --- app/src/components/EditorProvider.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/components/EditorProvider.tsx b/app/src/components/EditorProvider.tsx index 29bb629f..3438a9c1 100644 --- a/app/src/components/EditorProvider.tsx +++ b/app/src/components/EditorProvider.tsx @@ -35,12 +35,16 @@ function RichEditor({ const [openPreview, setOpenPreview] = useState(!mobile); const [openInput, setOpenInput] = useState(true); - useEffect(() => { + const handler = () => { if (!input.current) return; const target = input.current as HTMLElement; const preview = target.parentElement?.querySelector( ".editor-preview", - ) as HTMLElement; + ) as HTMLElement | null; + if (!preview) { + setTimeout(handler, 100); + return; + } const listener = () => { preview.style.height = `${target.clientHeight}px`; @@ -54,7 +58,8 @@ function RichEditor({ preview.style.height = `${target.clientHeight}px`; if (openInput) target.focus(); - }, [input]); + }; + useEffect(handler, [input]); return (