docs/plans/2026-05-20-slate-v2-document-state-undo-selection-bug.md
status: done created: 2026-05-20 completion_id: 019e3627-238b-7993-a8cf-26be45504c47 scope: .tmp/slate-v2/site/examples/ts/document-state.tsx, .tmp/slate-v2/packages/slate-react/src/editable
Fix the Document State example crash where undo from the external title input tries to focus the Slate editor and exhausts pending-operation retries.
<video-transcripts>
<video-transcript title="Document State undo selection bug">
[00:00] (The application displays a "Q2 Planning Brief" document title field and a Slate editor content area.)
[00:01] (The user clicks into the "Q2 Planning Brief" title field.)
[00:02] (The user types the letter "p" at the end of the title.)
[00:03] (The title field now displays "Q2 Planning Briefp".)
[00:04] (The user presses Command + Z to undo the title change.)
[00:05] (The application triggers an error state.)
[00:06] (The screen transitions to a browser error page showing "Could not focus, editor seems stuck with pending operations".)
[00:07] (The error log highlights the file "slate-dom/src/plugin/dom-editor.ts" at line 826.)
[00:08] (The error message indicates that retries are exhausted while the editor is focused.)
[00:09] (The user presses Command + Shift + Z to attempt a redo operation.)
</video-transcript>
</video-transcripts>
DOMEditor.focus, so the likely bug is event or
history ownership leaking from an external app input into model-owned repair.Could not set focus, editor seems stuck with pending operations in the
user's Next/Turbopack dev surface.bun test ./packages/slate-history/test/document-state-history-contract.tsPLAYWRIGHT_RETRIES=0 bun playwright playwright/integration/examples/document-state.test.ts --project=chromiumbun --filter slate-history typecheckbun typecheck:sitebun typecheck:rootbun lint:fixPLAYWRIGHT_RETRIES=0 bun playwright playwright/integration/examples/document-state.test.ts --project=chromium --grep "repeated undo"
proving second undo from the title input removes the editor p while keeping
title focus.PLAYWRIGHT_RETRIES=0 bun playwright playwright/integration/examples/document-state.test.ts --project=chromiumbun typecheck:sitebun typecheck:rootbun test ./packages/slate-history/test/document-state-history-contract.tsbun test ./packages/slate-dom/test/dom-coverage.ts --bail 1bun lint:fixdev-browser --connect http://127.0.0.1:9222 on
http://localhost:3100/examples/document-state with editor type -> title
type -> keyboard undo -> keyboard undo. After second undo:
activeLabel:"Document title", editorFocused:false,
commit:"commit:5;ops:remove_text;state:none;tags:historic",
model/DOM text no longer contain nodes.p, overlayText:null,
pageErrors:[]. Screenshot:
/Users/zbeyens/.dev-browser/tmp/document-state-title-repeated-undo-fixed.pngdev-browser --connect http://127.0.0.1:9222 on http://localhost:3100/examples/document-state
with editor type -> title type -> Undo document change. Screenshot:
/Users/zbeyens/.dev-browser/tmp/document-state-undo-fixed.pngbun test ./packages/slate-dom/test/dom-coverage.ts --bail 1PLAYWRIGHT_RETRIES=0 bun playwright playwright/integration/examples/document-state.test.ts --project=chromium --grep "undo redo"PLAYWRIGHT_RETRIES=0 bun playwright playwright/integration/examples/document-state.test.ts --project=chromiumbun --filter slate-dom typecheckbun --filter slate-history typecheckbun typecheck:sitebun typecheck:rootbun lint:fixdev-browser --connect http://127.0.0.1:9222 with editor type ->
title type -> keyboard undo -> keyboard redo. Screenshot:
/Users/zbeyens/.dev-browser/tmp/document-state-title-undo-redo-fixed.pngtags:historic. Screenshot:
/Users/zbeyens/.dev-browser/tmp/document-state-title-shortcut-owned-history.pngPLAYWRIGHT_RETRIES=0 bun playwright playwright/integration/examples/document-state.test.ts --project=chromiumbun test ./packages/slate-dom/test/dom-coverage.ts --bail 1bun test ./packages/slate-history/test/document-state-history-contract.tsbun typecheck:sitebun typecheck:rootbun lint:fix