Undo reverts a local editing transaction; it does not reverse a server write or another reviewer’s change. A usable history groups related typing into meaningful steps, records selection before and after each step, and invalidates redo when a new branch is created. Autosave adds another timeline: local draft, in-flight request, acknowledged server revision, and a possible conflict. The editor must separate these states so a late response cannot mark a newer draft as saved. A conditional revision at the server protects against lost updates.
Undo History, Autosave, and Revision Conflicts
Working case
Reviewer 47 edits case note 62 at revision 29. Three keystrokes become one undo step. Autosave request A carries revision 29 and document generation 6. While it runs, reviewer 47 adds another sentence, producing generation 7. Request A succeeds at server revision 30, but the editor remains dirty because generation 7 was not in that request. Reviewer 29 changes the same note before the next save; request B receives a conflict. The editor retains both local text and the newer server version for review, rather than overwriting either silently.
Implementation boundary
function saveAcknowledgesCurrent(sentGeneration, currentGeneration) {
return sentGeneration === currentGeneration;
}
console.log(saveAcknowledgesCurrent(6, 7));
// Output: falseRepresent edits as transactions with inverse information and model selection, or bounded snapshots for small documents. Limit history by count and bytes, grouping nearby typing without merging separate commands. Invalidate redo after a new edit following undo. Give each autosave payload a local generation, base server revision, and idempotency key. On response, clear dirty state only if the acknowledged generation still equals the current document generation. A conflict should present local and remote versions with an explicit resolution path; avoid automatic merge when rich structure or permissions make it ambiguous. Clean private drafts on account switch.
Cost and boundaries
Full snapshots cost O(document size times history depth); transaction history can be smaller but requires careful inverse mapping. Debounced autosave reduces request volume but raises the window of unsaved local work. Conditional writes add conflicts that require user time, yet prevent silent loss. A large rich note can exceed local storage quota or make every snapshot expensive. Track undo bytes, save latency, dirty duration, conflict frequency, and draft recovery success without collecting note text.
Failure trace
Request A succeeds and the UI shows “saved” even though generation 7 has not been sent; the reviewer closes the tab and loses a sentence. Another path presses undo after a server conflict and accidentally reverts the remote version instead of the local edit. Test out-of-order save responses, repeated idempotency keys, offline editing, undo then new typing, account switch, storage quota failure, and concurrent reviewers. Confirm that every state label corresponds to a specific local generation and server revision.
Verification
- Late save responses cannot clear newer dirty state.
- Undo history is bounded and scoped to local edits.
- Conflicts preserve local and server versions.
Practice drill
Start with revision 29 and generate two edits while the first autosave is pending. Resolve its response, then verify the editor remains dirty. Simulate a conflict on the second save and preserve both versions. Undo one local grouped step and add a new edit; redo must no longer replay the old branch. Fill history until its byte cap is reached, then inspect whether recent edits and selection remain recoverable.
Decision note
Tie undo to local transactions and autosave acknowledgment to the exact generation sent.
Common Mistakes
- Treating undo as server rollback.
- Marking the latest draft saved after an older response.
- Keeping private note history after account switch.
Connected lessons
Build Project: versioned case note editor and review Web Development: graphics and editor decisions quiz; follow Rich Document Editing and Safe Content; Editable Input, Composition, and Document Model; Selection Bookmarks and Transaction Mapping; Paste Import, Sanitization, and Link Policy; Autosave, Draft Recovery, and Conflicts; Conditional Writes and Lost-Update Prevention.
