-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix initial block parsing #52417
Merged
Merged
Fix initial block parsing #52417
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change has had one unpleasant side effect on the undo stack. When the post editor is initially loaded, the post entity in the Core Data store will have the
content
attribute, but there is noblocks
attribute. The parsedblocks
are stored only as a local memo state in this provider component, and there is no longer anyeditEntityRecord
call that would save them in the store. Theblocks
attribute is set only on the first real edit.The first real edit will produce an
EDIT_ENTITY_RECORD
action that hasaction.meta.undo.edits.blocks
set toundefined
. Thestate.undo
reducer will create an undo stack record for this edit, and it will look like{ property: 'blocks', from: undefined, to: [ ... ] }
.Applying that undo record means that the
blocks
attribute will be set toundefined
, the value of thefrom
field of the undo record. But instead ofundefined
, it should have been the original parsedblocks
, the value is known.Setting
blocks
toundefined
means that on undo, they will need to be parsed from scratch from thecontent
string and all client IDs will be different.This will cause all blocks' edit components to be unmounted and re-created from scratch, on a simple undo operation that shouldn't do this. It should just update one little attribute of one little block.
We've seen the unpleasant effect of this when refactoring the TOC block in #54094 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that ideally the components should be unmounted and recreated from scratch but making the "blocks" edit
undefined
on undo is (in isolation) a fine.That said, I think maybe we need a way to tell
core-data
to load these transient values on initial "fetch" of the entities instead of leaving that to consumer code which will always lead to inconsistencies.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it's not fine, because conceptually the
blocks
value is known and it's notundefined
. It just lives outside the data store, in React state. Losing that value leads to losing information, namely the blocks' already assigned client IDs.I don't know how to fix it, and the issue is not terribly urgent. I mainly wanted to document that it exists and write down what I found.