Fix crash restoring a session serialized without undo history#5989
Open
xyos wants to merge 1 commit into
Open
Conversation
EditSession.toJSON serializes the undo manager; sessions using the
default no-op undo manager serialize history as {}. fromJSON then set
UndoManager.$undoStack/$redoStack to undefined, so the first edit after
restore crashed in UndoManager.add with
'Cannot set properties of undefined (setting length)'.
Hit in kitchen-sink, which persists the session to localStorage on
unload and restores it on load (also reproducible on master).
Default missing history fields in EditSession.fromJSON and guard
UndoManager.fromJSON against null/partial input.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5989 +/- ##
==========================================
+ Coverage 93.73% 93.74% +0.01%
==========================================
Files 641 641
Lines 138167 138182 +15
Branches 14561 14559 -2
==========================================
+ Hits 129510 129539 +29
+ Misses 8657 8643 -14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Restoring a session with
EditSession.fromJSON()crashes on the first subsequent edit when the serialized session was using the default no-op undo manager:EditSession.toJSON()serializes the undo manager underhistory; a session that never had a realUndoManagerattached serializes it as{}. On restore,fromJSONthen does:clobbering the arrays the
UndoManagerconstructor just created, so the firstUndoManager.add()throws atthis.$redoStack.length = 0.Repro
This is hit in practice by the kitchen-sink demo, which persists the session to
localStorageon unload and restores it viafromJSONon the next load — after which every keystroke/paste throws. Regression from thehistoryserialization changes in #5920.Fix
EditSession.fromJSON: tolerate a missing/emptyhistoryobject and default$undoStack/$redoStackto[],mark/revto0.UndoManager.fromJSON: guard againstnull/partial input the same way.Round-tripping a session with real history is unaffected (covered by the existing
JSON serialization preserves undo/redo historytest).Open kitchen-sink @ ae482be47cbf147e7a550f1efc3487e0928f847a