Skip to content

Commit 5e52943

Browse files
saphidclaude
andcommitted
perf(web): check composer undo ownership once per draft document
Ownership is evaluated on every keydown. Cache the serialized-draft check by the immutable editor document so held arrow keys on a reopened draft do not reserialize it each time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 970d591 commit 5e52943

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,11 +1506,18 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
15061506
useEffect(() => {
15071507
if (!editor) return;
15081508
// Any serialized draft (text, chips, rules, empty fences) keeps the
1509-
// shortcut; serialize only once history is empty, as this runs per keydown.
1510-
return registerEditableUndoHistory(
1511-
editor.view.dom,
1512-
() => undoDepth(editor.state) > 0 || serializeEditorDoc(editor.state.doc).value.length > 0,
1513-
);
1509+
// shortcut. This runs on every keydown, so serialize only once history is
1510+
// empty and once per document (selection changes keep the same doc).
1511+
let checkedDoc: ProseMirrorNode | null = null;
1512+
let hasDraft = false;
1513+
return registerEditableUndoHistory(editor.view.dom, () => {
1514+
if (undoDepth(editor.state) > 0) return true;
1515+
if (editor.state.doc !== checkedDoc) {
1516+
checkedDoc = editor.state.doc;
1517+
hasDraft = serializeEditorDoc(checkedDoc).value.length > 0;
1518+
}
1519+
return hasDraft;
1520+
});
15141521
}, [editor]);
15151522

15161523
useEffect(() => {

0 commit comments

Comments
 (0)