From 63f5809c3bc135035fd4d58fa37f4dfe38788d59 Mon Sep 17 00:00:00 2001 From: ZLY Date: Thu, 4 Dec 2025 14:36:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(editor):=20=E4=BC=98=E5=8C=96=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E5=8A=A8=E6=80=81=E5=8A=A0=E8=BD=BD=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/EditorSection/index.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/EditorSection/index.tsx b/src/components/EditorSection/index.tsx index 6bbb027..9b9b35d 100644 --- a/src/components/EditorSection/index.tsx +++ b/src/components/EditorSection/index.tsx @@ -37,28 +37,30 @@ const EditorViewer: React.FC<{ content: string }> = ({ content }) => { export default function EditorSection({ initialContent, visible, onChange }: EditorSectionProps) { const [isClient, setIsClient] = useState(false); + const [editorLoaded, setEditorLoaded] = useState(false); const [currentContent, setCurrentContent] = useState(initialContent || ''); const editorRef = useRef(null); const editorInstanceRef = useRef(null); useEffect(() => { - if (!isSSR) { + if (!isSSR && visible && !editorRef.current) { setIsClient(true); // 动态导入编辑器组件 import('@toast-ui/react-editor').then((module) => { editorRef.current = module.Editor; + setEditorLoaded(true); // 标记编辑器已加载 }).catch((error) => { console.error('Failed to load Toast UI Editor:', error); }); } - + // 更新当前内容当初始内容变化时 setCurrentContent(initialContent || ''); }, [initialContent, visible]); // 在服务端或组件未加载完成时,使用 Viewer 模式显示内容 - if (!isClient || !editorRef.current || !visible) { + if (!isClient || !editorLoaded || !visible) { return (