Skip to content

Commit 969ec17

Browse files
Defer editor document serialization during typing (#5898)
Move full ProseMirror document JSON serialization into the existing debounced change flush so keyboard transactions stay lightweight.
1 parent c77858e commit 969ec17

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

packages/editor/src/note/index.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,22 @@ export const NoteEditor = forwardRef<NoteEditorRef, NoteEditorProps>(
537537
[taskSource, taskStorage],
538538
);
539539

540-
const onUpdate = useDebounceCallback((content: JSONContent) => {
540+
const flushChange = useCallback(() => {
541+
const view = viewRef.current;
542+
if (!view) {
543+
return;
544+
}
545+
546+
const content = view.state.doc.toJSON() as JSONContent;
541547
syncTasks(content);
542548
if (!handleChange) {
543549
return;
544550
}
545551

546552
handleChange(content);
547-
}, 500);
553+
}, [handleChange, syncTasks]);
554+
555+
const onUpdate = useDebounceCallback(flushChange, 500);
548556

549557
const plugins = useMemo(
550558
() => [
@@ -674,8 +682,7 @@ export const NoteEditor = forwardRef<NoteEditorRef, NoteEditorProps>(
674682
dispatchEditorTransaction({
675683
view: this,
676684
transaction: tr,
677-
onDocChanged: () =>
678-
onUpdate(this.state.doc.toJSON() as JSONContent),
685+
onDocChanged: () => onUpdate(),
679686
});
680687
}}
681688
attributes={{

0 commit comments

Comments
 (0)