-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 synced pattern editing in write mode and refactor block editing mode to reducer #67026
Conversation
Size Change: +869 B (+0.05%) Total Size: 1.82 MB
ℹ️ View Unchanged
|
Flaky tests detected in 773c76d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11947756308
|
9363eb2
to
d636bac
Compare
47827e8
to
6f69a32
Compare
registry.dispatch( preferencesStore ).set( 'core', 'editorTool', mode ); | ||
|
||
if ( mode === 'navigation' ) { | ||
speak( __( 'You are currently in Write mode.' ) ); | ||
} else if ( mode === 'edit' ) { | ||
speak( __( 'You are currently in Design mode.' ) ); | ||
} | ||
|
||
dispatch( { type: 'SET_EDITOR_MODE', mode } ); |
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 is the one that I'm not sure about because some people could call registry.dispatch( preferencesStore ).set( 'core', 'editorTool', mode );
directly. Maybe it's fine I don't know
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.
Yeah, that's a good point, though I guess the spoken messages also won't work when changing the mode that way. Some options:
- (I think you mentioned this one) Always calculate the block editing modes for write mode even when in design mode, then the selector can choose the right one. This'd be a shame as I expect it'd cause a performance hit.
- Add a listener (probably an effect) that reacts to the preference change and sets the mode in the block editor store.
- Make the preference key private so that it can only be called internally. I think this preference has already shipped in the plugin, so it would need some back compat wrangling. Possibly my preferred solution though.
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.
Also, what happens on "init"? which mode is used?
I may be leaning towards the first option personally to decouple the preference setting entirely from the computation of the mode.
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.
Also, what happens on "init"? which mode is used?
It uses whatever value the preferences store has at the time of computation. I guess there could be a concern if the preferences store isn't ready yet for some reason.
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.
Apart from resolving this question, the rest of the PR is pretty finalized (I've added lots of tests).
I'll have a go at your suggestion, I think it should be pretty easy to implement, we'll probably just need an extra state property for navModeBlockEditingModes
or something. One thing on my mind is preventing this from being calculated when write mode isn't an option (I think in the post editor it's not an option), as that would be unnecessary.
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 didn't go deep in the algorithm review but the change itself feels right to me. I think it's we need some testing around it (maybe we already have)
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 works pretty great already and the removals of effects plus centralising the decision makes everything easier to grasp. I wish we'd also handle the content locking in the same place.
6f69a32
to
63d0d2f
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. |
I'm curious to know if I'm testing this correctly or if what I'm seeing is expected. When editing a post with the template preview off, the write/design mode drop down is not visible. There's functionality in the post editor, for example, in the block settings dropdown, that uses the editing mode value from the store. That means, if I leave the site editor or template preview mode after having activated "Write Mode", the post editor knows about it and won't render handy settings such as "Add before" and "Add after":
Especially swapping between site and post editors, I'd have expected to land in default editing mode for regular posting editing, and therefore have access to the block settings features. |
773c76d
to
7b25f6e
Compare
@youknowriad As per this discussion, I've updated this now so that it calculates both Also addressed some of the other review feedback. Hopefully it's good to go now. |
I'm going to merge this seeing as nobody is telling me not to 😄 The gutenberg RC was only just cut yesterday, so there should be a bit of time to resolve any issues or even revert again if needed before it lands in the next RC. |
WAIT! Just jokes. 🚢
Sounds good. If there's anything, hopefully it'll pop up in the next two weeks with all the eyes on it. |
What?
Supercedes some previous attempts #66919, #66949, and #65408!
Fixes #66424
In Write Mode, parts of synced patterns that are supposed to be non-editable are editable. This PR fixes the problem, plus undertakes some refactoring of how block editing mode works due to some performance caused by so much logic being in the
getBlockEditingMode
selector.Why?
This bug happens because Write Mode overrides the blockEditingMode of a synced pattern's inner blocks.
Pattern blocks try calling
setBlockEditingMode
for child blocks imperatively (in the pattern block's edit function). This does set the correct block editing modes in the block editor store, but when write mode is active thegetBlockEditingMode
selector returns early with a different value.#65408 tried to fix this by updating the
getBlockEditingMode
selector, but it cause a performance hit.How?
This PR fixes the issue by moving the pattern block editing modes to the block editor store, so that it can work harmoniously with the way Write Mode and Zoom Out mode determine the block editing mode.
The PR also undertakes a refactor of how block editing mode works for zoomed out and write mode to improve performance. The
getBlockEditingMode
select is called a lot (including recursively), so any code added there can cause performance regressions.The summary of the changes is:
getBlockEditingMode
selectorwithDerivedBlockEditingModes
higher order reducer, it calculates a derivedBlockEditingMode state for any actions that might require this is recomputed using a few other functions:getDerivedBlockEditingModesForTree
traverses a block tree calculating the block editing modes for all the blocks in that tree, returning them in aMap
. This can be used for the entire block tree or just a part of the block tree.getDerivedBlockEditingModeForBlock
calculates the block editing mode for a single client id. Called bygetDerivedBlockEditingModesForTree
on each block in the tree.getDerivedBlockEditingModesUpdates
used for actions that add/remove a partial subset of blocks. It should only return a value when there are block editing mode changes, meaning the store state doesn't unnecessarily change.traverseBlockTree
,getBlockTreeBlock
,findParentInClientIdsList
,hasBindings
.isContentBlock
private function to the blocks package.It's quite a lot of code, so I'm open to suggestions on how to structure it.
Testing Instructions
In addition to this, give a good test to both zoomed out and write mode, move blocks around, insert and remove stuff and make sure there are no issues. 😄
Screenshots or screencast
Before
Kapture.2024-11-13.at.17.24.45.mp4
After
Kapture.2024-11-13.at.17.28.44.mp4