- Notifications
You must be signed in to change notification settings - Fork 4.6k
contentOnly: Fix canInsertBlockType dependencies to fix selector caching issues #72022
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
contentOnly: Fix canInsertBlockType dependencies to fix selector caching issues #72022
Conversation
| Size Change: +2 B (0%) Total Size: 1.96 MB
ℹ️ View Unchanged
|
| Flaky tests detected in 05528fa. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18266561682
|
…cies to fix selector caching issues
cc99b32 to cf1c1e0 Compare | The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
talldan left a 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.
Two bugs with one PR, nice work!
| Thanks for the help, Dan! 🙇 |
What?
Fixes #71955
Fixes #71956
Fix issues with contentOnly mode when clicking "Edit contents" after selecting a block within a pattern.
In
trunk, doing so results in the Add Before / Add After / Duplicate options being unavailable, and it not being possible to drag blocks within groups within the pattern.Why?
This appears to be because when we update the parent block to no longer be recognised as a pattern for the purposes of content only mode, the cache for the canInsertBlockType selector is not invalidated.
To put it differently, the unmemoized version of the selector performs lookups to see if its parents are section blocks / tries to figure out the block editing mode. However the current list of cache values does not include anything about the state of the parents or the derived block editing mode of the block in question.
How?
In the list ofgetInsertBlockTypeDependantsadd a call togetParentSectionBlockso that we check that for the current clientId. This ensures that if the parent section block is changed, the cache is (effectively) invalidated.However, this is likely an expensive call, so is probably not the ideal fix. My hope is that this PR can help us come up with a better fix. (The unit tests are failing because this change expects a broader set of things instate, I've left them failing while we investigate the right fix for this)Thanks to Dan's suggestion, I've updated this PR to use the
getBlockEditingMode( state, rootClientId )which is relatively inexpensive as it just useshaschecks on the computed values that are (elsewhere) updated viagetDerivedBlockEditingModesForTree. This appears to be the right fix now, I believe, as the check is inexpensive, but it's looking in the right place for determining the current state of the block.Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
For before videos, see #71955 and #71956. With this PR applied, this is possible:
2025-10-02.16.21.33.mp4