From 243f6754c1af90132a4c6a05b07a305e909889d3 Mon Sep 17 00:00:00 2001 From: mrsibe Date: Thu, 24 Sep 2026 18:15:15 +0800 Subject: [PATCH] fix(note): stop destroying the Tiptap editor manually MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NoteEditor registered a cleanup effect that called editor.destroy() on unmount, but @tiptap/react v3's useEditor already owns the editor lifecycle. Under React StrictMode the effect runs mount → cleanup → mount, so the manual destroy left the second mount with an already destroyed instance: the content-sync effect then read editor.storage.markdown as undefined, threw, and—with no error boundary—unmounted the whole React tree (blank window). This surfaced on "Add to Note" in chat because #15 made that path open the note editor, which mounts NoteEditor for the first time. Remove the manual destroy and let useEditor manage it. --- .../src/components/notebook/note/NoteEditor.tsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/components/notebook/note/NoteEditor.tsx b/src/renderer/src/components/notebook/note/NoteEditor.tsx index f2e8bda..e386cd3 100644 --- a/src/renderer/src/components/notebook/note/NoteEditor.tsx +++ b/src/renderer/src/components/notebook/note/NoteEditor.tsx @@ -36,14 +36,9 @@ export default function NoteEditor({ content, onChange }: NoteEditorProps): Reac } }) - // 清理编辑器实例 - useEffect(() => { - return () => { - if (editor) { - editor.destroy() - } - } - }, [editor]) + // 编辑器实例由 useEditor 管理生命周期(@tiptap/react v3 会在卸载时销毁), + // 这里不能手动 destroy:StrictMode 下 effect 会 mount → cleanup → mount, + // 手动销毁会让第二次挂载拿到已销毁的实例,editor.storage.markdown 为 undefined。 // 当外部 content 变化时同步到编辑器 useEffect(() => {