From 794b97025d4c56f91d49c9d1ec4775d2ea07b53a Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 9 May 2026 06:32:34 +0900 Subject: [PATCH] refac --- .../components/common/RichTextInput.svelte | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/components/common/RichTextInput.svelte b/src/lib/components/common/RichTextInput.svelte index 99fa025055..ba6c63dbf1 100644 --- a/src/lib/components/common/RichTextInput.svelte +++ b/src/lib/components/common/RichTextInput.svelte @@ -302,6 +302,8 @@ let bubbleMenuElement: Element | null = null; let element: Element | null = null; + let pendingUpdate = null; + const options = { throwOnError: false }; @@ -866,10 +868,19 @@ content: collaboration ? undefined : content, autofocus: messageInput ? true : false, onTransaction: () => { - // force re-render so `editor.isActive` works as expected - editor = editor; if (!editor) return; + // Defer Svelte reactivity trigger to rAF so we don't interleave + // DOM reads/writes with ProseMirror's updateStateInner. + if (!pendingUpdate) { + pendingUpdate = requestAnimationFrame(() => { + pendingUpdate = null; + if (editor && !editor.isDestroyed) { + editor = editor; + } + }); + } + htmlValue = editor.getHTML(); jsonValue = editor.getJSON(); @@ -1234,6 +1245,10 @@ }); onDestroy(() => { + if (pendingUpdate) { + cancelAnimationFrame(pendingUpdate); + } + if (provider) { provider.destroy(); }