-
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
Prevent focus loss on reusable block edition #27950
Conversation
83c6695
to
6c9399e
Compare
Size Change: -77 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
blocks: parsedContent, | ||
}, | ||
{ undoIgnore: true } | ||
); |
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.
Howdy @youknowriad 👋 I arrived at this editEntityRecord
call when debugging the PostPreviewButton
component and how it autosaves the post before showing the preview.
The trouble is that when the isEditedPostAutosaveable
selector is called, it calls hasChangedContent
, which always returns true
even if I didn't edit the post at all.
It's because this editEntityRecord
call always adds an edit when the editor is being initialized (more precisely, EditorProvider
being mounted).
hasChangedContent
checks if there are 'blocks' in edits
which is always true. The blocks
field never goes away.
What do you think would be a good way to fix this? Is the entity's blocks
field also initialized anywhere else, outside EditorProvider
? Seems to me the initial value of block
should be set on the unedited post entity, to live alongside the original content
it is derived from. Not in the edits.
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.
Isn't there a flag maybe we can pass to editEntityRecord
to mark the change as "non dirty" or something like that? (we had some kind of initial changes in the past).
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.
Currently there isn't. And edits.blocks
is not really an edit -- it's a computed property from the original entity.content
and there is no changed content. Ideally the *.blocks
field would always live on the same object as *.content
, as they are two different representations of the same underlying data.
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.
We do have a notion of transientEdits
which is what edits.blocks is about but subsequent changes to "blocks" should be considered real edits (mark the post dirty, create undo levels...). Could the first time a "transition edit" be set considered a non-dirty edit?
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.
Yes, blocks
and selection
edits are considered transient and should never trigger save. Any real edit will also edit content
, setting the value to a serialization function to it. So, we can completely ignore blocks
and rely on content
edits to be always present.
I'm fixing the hasChangedContent
selector in #45090 to ignore blocks
and look only at content
.
Follow-up to #27887
The recent reusable block refactoring highlighted a bug in the
useEntityBlockEditor
hook where the first time blocks are edited, you first get a[]
value and then you get the edited value. This was due to hooks order of execution. The fact that sometimes the block came from the edited value and sometimes from the parsed "content" value, caused this issue.This PR updates that hook to always retrieve the blocks value from the "edits" by adding an initialization to that value when the "content" changes.
This should make the "reusable-blocks" e2e test more stable as well.