-
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
SiteEditor: Refactor disable non page content blocks #56103
Conversation
Size Change: -13 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
packages/edit-site/src/components/page-content-focus-manager/disable-non-page-content-blocks.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Kai Hao <kevin830726@gmail.com>
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 testing nicely for me:
✅ Content blocks are marked as locked as expected, and only content blocks are displayed
✅ Children of query loop blocks are not marked as contentOnly
✅ Switching between content and template mode updates the lock status correctly
LGTM! ✨
return clientIds.map( ( clientId ) => { | ||
return <DisableBlock key={ clientId } clientId={ 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.
Does it matter that this will perform a new map
on each render (returning a new array), or is that mitigated by the use of key
within <DisableBlock />
?
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 doesn't matter. When React has an array of children, it compares one by one using arrays. Memoising the array is not expected.
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.
Great, thanks for confirming!
Extracted from #56000
What?
This PR refactors the
DisableNonPageContentBlocks
component to make it a bit more resilient to component remounts and also probably slightly more performant. The previous code used to filter all blocks rendered in the site editor to inject the right mode (lock/unlock content editing).In #56000 this broke because the component was being remounted which caused the filters to not run consistently. In the current PR, I avoid
editor.BlockEdit
filters entirely and I just fetch the exact blocks that I want to lock/unlock and apply the logic.Testing Instructions
1- Open the site editor
2- Ensure that if you open a page in the site editor: only "content" blocks are editable until you switch to template mode.