Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
52e054bf5f
commit
ffbb49b523
@@ -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 || "<p></p>", { emitUpdate: false });
|
||||
if (!editor) return;
|
||||
const current = editor.getHTML();
|
||||
const incoming = value || "<p></p>";
|
||||
if (incoming !== current) {
|
||||
editor.commands.setContent(incoming, { emitUpdate: false });
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [value === ""]);
|
||||
}, [value, editor]);
|
||||
|
||||
if (!editor) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user