diff --git a/src/components/documents/rich-text-editor.tsx b/src/components/documents/rich-text-editor.tsx index 330cd27..5ccd75b 100644 --- a/src/components/documents/rich-text-editor.tsx +++ b/src/components/documents/rich-text-editor.tsx @@ -59,13 +59,18 @@ export function RichTextEditor({ }, }); - // Keep editor in sync when value is reset externally + // Keep editor in sync when value is reset/loaded externally (e.g. opening a saved pleading). + // Only re-sync when the incoming value differs meaningfully from the current editor HTML so + // we don't fight the user's typing on every keystroke. useEffect(() => { - if (editor && value !== editor.getHTML()) { - editor.commands.setContent(value || "

", { emitUpdate: false }); + if (!editor) return; + const current = editor.getHTML(); + const incoming = value || "

"; + if (incoming !== current) { + editor.commands.setContent(incoming, { emitUpdate: false }); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [value === ""]); + }, [value, editor]); if (!editor) return null;