-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Make getBlockEditingMode() return 'default' when parent is 'contentOnly' #51185
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
Conversation
Change the behaviour of getBlockEditingMode() so that a block's children is considered "content" that is editable when the editing mode is 'contentOnly'. Therefore getBlockEditingMode( foo ) should be 'default' when getBlockEditingMode( getParent( foo ) ) is 'contentOnly'. The benefit of this is that block subtrees can be enabled by simply setting the parent container to 'contentOnly' rather than each individual block to 'default'. This is much more performant as each call to setBlockEditingMode() invalidates the cache.
…g-mode-performance
|
Just thinking out loud, it's not important right now, but I wonder if an object containing flags would be more flexible than encapsulating everything into function MyBlockEdit( { attributes } ) {
useBlockEditingMode( {
selection: false,
movers: false,
settingsMenu: false,
removeButton: false,
inserter: false,
} );
return ( ... );
} |
|
Size Change: -32 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
tellthemachines
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.
Changes LGTM, with the disclaimer that I'm no expert in these methods!
All blocks should be locked except for the Post Title, Post Featured Image and Post Content blocks.
Testing content editing with the patch applied mostly works as expected. One question: should we be able to edit the heading level of the Post Title block? That seems more like template editing functionality.
| state, | ||
| 'b3247f75-fd94-4fef-97f9-5bfd162cc416' | ||
| ) | ||
| ).toBe( 'disabled' ); |
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.
Did anything change in what these tests check for, or did you just unfold the loop for better legibility?
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 unfolded the loop so as to change one key thing which is that if the parent block has an editing mode of 'contentOnly' then the child block will now have an editing mode of 'default' not 'contentOnly'.
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.
Oh, got it, that makes sense!
|
Thanks @tellthemachines!
In the other PR I've got some code that disables editing the heading level. |
…ly' (WordPress#51185) Change the behaviour of getBlockEditingMode() so that a block's children is considered "content" that is editable when the editing mode is 'contentOnly'. Therefore getBlockEditingMode( foo ) should be 'default' when getBlockEditingMode( getParent( foo ) ) is 'contentOnly'. The benefit of this is that block subtrees can be enabled by simply setting the parent container to 'contentOnly' rather than each individual block to 'default'. This is much more performant as each call to setBlockEditingMode() invalidates the cache.
…ly' (WordPress#51185) Change the behaviour of getBlockEditingMode() so that a block's children is considered "content" that is editable when the editing mode is 'contentOnly'. Therefore getBlockEditingMode( foo ) should be 'default' when getBlockEditingMode( getParent( foo ) ) is 'contentOnly'. The benefit of this is that block subtrees can be enabled by simply setting the parent container to 'contentOnly' rather than each individual block to 'default'. This is much more performant as each call to setBlockEditingMode() invalidates the cache.
What?
Follows #50643.
Needed to fix the failing performance tests in #50857.
Change the behaviour of
getBlockEditingMode()so that a block's children is considered "content" that is editable when the editing mode is'contentOnly'. ThereforegetBlockEditingMode( foo )should be'default'whengetBlockEditingMode( getParent( foo ) )is'contentOnly'.Why?
The benefit of this is that block subtrees can be enabled by simply setting the parent container's editing mode to
'contentOnly'rather than setting the editing mode of every descendant block to'default'. This is much more performant as each call tosetBlockEditingMode()invalidates the cache.To illustrate, this is what we had to do before to allow the full editing of nested blocks within the Post Content block:
But now we can simply do this:
It's much more performant because each nested block within Post Content (there could be thousands) doesn't need to call
setBlockEditingMode().Testing Instructions
Unit tests should cover this pretty well.
You can also check that
useBlockEditingModefunctions correctly by:pbpaste | git apply.To test the existing
contentOnlyfunctionality for regressions: