Reject stale history after replacing the document
A delayed keyboard event queues Undo just before a successful import installs another document. The old history entry then restores part of the previous document into the replacement because both documents happen to contain node p1.
- Focused work estimate
- 4h + prerequisites
- Priority in the scenario
- High
- Engineering practice
- Concurrency modeling · State transitions · History integrity
Estimated field mix
- Frontend50%
- System design30%
- Quality engineering20%
Field percentages are editorial estimates of the ticket's engineering focus. They total 100%; they are not measured time, proficiency scores, or ownership evidence.
Pattern topics
- CommandRefactor
Bind queued editor operations to the session that created them so delayed commands cannot operate on a replacement document with reused node IDs.
- MementoRefactor
Give history snapshots an explicit document-session boundary and install replacement content together with a coherent history reset.
Review it, then add it to your workspace.
The board opens an editable draft; nothing is saved until you confirm it. Sign-in and workspace permissions apply, and Demo boards remain ephemeral.
Project context
A fictional support team edits reusable troubleshooting documents with paragraphs, links, and nested sections. The browser prototype has separate toolbar and keyboard handlers, an unreliable undo stack, and mutable shared formatting objects. Create a local editor and synthetic documents; no starter assets, rich-text engine, collaborative backend, or production service is supplied.
Setup prerequisites
- Browser events
- Immutable updates
- Accessible form controls
Preceding work
Complete these dependencies, or supply their agreed outputs before taking this ticket.
- PDOC-101 · Give nested sections and paragraphs one structural contract
- PDOC-103 · Route toolbar and keyboard deletion through one command
- PDOC-104 · Restore selection together with content when undoing a deletion
- PDOC-105 · Stop closed editor tabs from receiving document updates
- PDOC-106 · Untangle the toolbar's direct calls into three side panels
- PDOC-107 · Prevent edit actions while a replacement document is importing
- PDOC-102 · Make Find next follow document order through collapsed sections
- PDOC-109 · Add text and outline export without teaching nodes about file formats
Acceptance criteria
- Bind commands and history entries to a document session identity as well as a revision.
- Replacement import commits document, logical selection, session identity, and history reset as one state transition.
- Stale queued commands and incompatible snapshots fail without modifying the active document; cancellation preserves the previous session and valid history.
Implementation constraints
- Build a deterministic event-order harness rather than timing-dependent sleeps; this ticket does not require collaborative editing or remote persistence.
Verification to include
- Interleave queued Undo, successful import, and duplicate node identities; assert the replacement never receives previous-session content.
- Fail and cancel imports at each transition boundary, then verify undo remains valid only for the preserved session.
Deliverables
- Session-bound command/history contract and interleaving regression matrix
Rollout and recovery
Introduce session identities at the local editor boundary and clear incompatible transient history once; preserve saved content separately for recovery.
Value of the work
For the engineer: Practice relating object and state patterns to real UI behavior, including undo semantics, bounded traversal, lifecycle cleanup, and memory tradeoffs.
For the team: Review whether editor changes preserve user work, keep controls consistent, and reduce maintenance effort without concealing document corruption.
Evidence boundaries
Outcome Evidence: Tests, patches, and runbooks are requested deliverables. They become Outcome Evidence only through a qualified Mission and immutable Evidence IDs.
Ownership Evidence: Independent adaptation must be observed under a declared verification policy and cite immutable Evidence IDs. Completing a planning ticket establishes no Ownership Evidence.