-
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 broken undo history stack for Pattern Overrides #57088
Conversation
Size Change: +171 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Flaky tests detected in f5c1a78. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7296946839
|
8d94ddf
to
703f0a7
Compare
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.
Briefly tested and read through the code. I think this is an interesting idea.
Will try to do more thorough testing later this week.
P.S. Tried to use the state.blocks.isPersistentChange
flag when working on a fix for the ToC block, but I couldn't get it working 😅
// Ignore pushing undo stack for the updated blocks. | ||
const updatedBlocks = select.getBlocks(); | ||
undoIgnoreBlocks.add( updatedBlocks ); |
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.
It would be nice to be more explicit here and store only updated blocks instead of every block. Probably something for the future and before API is stable.
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.
It's storing the updated blocks reference in a WeakSet
so it shouldn't create extra memory nor leak it. In a way it's actually faster to not do any transformation here 😆. We can probably achieve the same thing with a flag in the store, like what isPersistentChange
does, but the higher-order reducer makes it unnecessarily hard 😅. We can revisit this part in a future API design.
Thanks for testing it out! ❤️
I tried using |
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 tested well for me. Without this there was an additional step in the undo history for pattern overrides, but with the PR the stack has the expected number of entries.
Although as noted this doesn't yet work with all blocks, given that its usage is currently limited to the new pattern block behind an experimental flag I think it is safe to merge and iterate.
569b503
to
f5c1a78
Compare
I'll merge this and we can iterate on the API design in the future. It's currently still private anyway. Thanks for the reviews! |
What?
The undo history is a bit broken for Pattern Overrides. This PR tries to fix it.
Why?
For better editing experience.
How?
This PR removes the
syncDerivedBlockAttributes
action introduced in the original PR (#56235) an instead introduce a new private higher-order actionsyncDerivedUpdates
.The signature of
syncDerivedUpdates
looks like:Any updates inside the callback should not push additional undo history stacks nor should be persistent. This serves as a escape hatch to make updates to the block editor completely invisible to the core's undo manager. This means we can call
setAttributes
to set theoverrides
of the pattern block without worrying that it might break the history stack.Example usage:
The goal is to make something like this stable enough so that third-party developers can leverage it too. We probably can use it solve some of the longstanding undo bugs too (#8119 (comment), #41031 (comment)).
Note
This API currently doesn't work 100% of the time for other blocks so it should remain private for now. The top priority of this PR is to fix the existing issue for Pattern Overrides. We can work on finalizing the API across different use cases in the future.
Testing Instructions
Screenshots or screencast
Kapture.2023-12-19.at.14.22.05.mp4