-
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
base: trunk
Are you sure you want to change the base?
Conversation
- Remove the prev. React effect for managing pattern block editing modes - Implement higher order reducer in the block editor store ... it: - Tracks the clientIds of pattern blocks. - Uses the pattern block clientIds to manage block editing modes for pattern blocks and their inner blocks. - Updates both on any actions that change block lists.
This reverts commit e1d6ca4. It doesn't really work, since reducer won't have access to `state.blocks.tree`.
Size Change: +710 B (+0.04%) Total Size: 1.82 MB
ℹ️ View Unchanged
|
…educer. Add special handling for only adding pattern block itself as content only when not in zoomed out or nav mode
…en synced pattern overrides or when write mode is active
Flaky tests detected in 6f69a32. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11928398849
|
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
const isContent = hasContentRoleAttribute( name ); | ||
|
||
return isContent ? 'contentOnly' : 'disabled'; | ||
if ( state.derivedBlockEditingModes?.has( clientId ) ) { |
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 which case, there's no "derived block editing mode"?
@@ -112,6 +112,7 @@ function getEnabledClientIdsTreeUnmemoized( state, rootClientId ) { | |||
export const getEnabledClientIdsTree = createRegistrySelector( ( select ) => | |||
createSelector( getEnabledClientIdsTreeUnmemoized, ( state ) => [ |
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 think some of the dependencies here can probably be removed because they're not used in the selector anymore. But I don't expect that it impacts anything.
function getDerivedBlockEditingModeForBlock( | ||
state, | ||
clientId, | ||
{ |
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.
What's the difference between this argument and all the content that is already in state
?
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)
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
Testing Instructions for Keyboard
Screenshots or screencast
Before
Kapture.2024-11-13.at.17.24.45.mp4
After
Kapture.2024-11-13.at.17.28.44.mp4