-
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
Patterns: Don't override the rootClientID in create menu - only set if undefined #52713
Conversation
@noisysocks in relation to the above comment made here, in my testing it seems that when selecting across container blocks it is the top-level containers that are passed in as the selected block ids, which then by nature have the same parent id so it seems like |
Size Change: +978 B (0%) Total Size: 1.43 MB
ℹ️ View Unchanged
|
export default function ReusableBlocksMenuItems( { rootClientId } ) { | ||
const clientIds = useSelect( ( select ) => | ||
select( blockEditorStore ).getSelectedBlockClientIds() | ||
); |
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.
Should pass []
as the deps
for useSelect
here. Annoyingly it doesn't default to []
.
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.
thanks, fixed, we should have a lint rule for that.
const rootId = | ||
rootClientId || clientIds.length > 0 | ||
? getBlockRootClientId( clientIds[ 0 ] ) | ||
: undefined; |
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 wrong, no? It will call getBlockRootClientId
if rootClientId
is truthy. I think you need parens around the right hand side of the ||
.
const rootId = rootClientId || ( clientIds.length > 0 ? getBlockRootClientId( clientIds[ 0 ] ) : undefined );
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.
🤦 should have stuck with the nested ternary I first had, it was easier to grok 😄 It works as expected when properly bracketed and have updated, but I wonder if something like the following is clearer for our future selves and not much more verbose 🤔 :
let rootId;
if ( rootClientId ) {
rootId = rootClientId;
} else if ( clientIds.length > 0 ) {
rootId = getBlockRootClientId( clientIds[ 0 ] );
}
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.
Up to you 😀
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.
Thanks for looking into this!
For future reference this was a bug fix for #52671 which had potentially broken the menu for any plugin that was passing |
I just cherry-picked this PR to the update/packages-RC2 branch to get it included in the next release: 88e1896 |
* Filter out patterns that are not allowed in the inserter (#52675) * Remove autofocus and improve placeholder text consistency. (#52634) * Do not navigate to the styles pages unless you're in a random listing page (#52728) * Patterns: Don't override the rootClientID in create menu - only set if undefined (#52713) * Footnotes: store in revisions (#52686) * Fix: Block toolbar obscuring document tools when Top Toolbar is enabled (#52722) * Update toolbar width * Site editor needs specific width * fixes top toolbar width for post editor when not in fullscreen * remove the body rule --------- Co-authored-by: Andrei Draganescu <[email protected]> * Site Editor: Fix site link accessibility issues (#52744) * Add id to pattern inserted notice to stop multiple notices stacking (#52746) * Global Styles: Don't use named arguments for 'sprintf' (#52782) * Footnotes: Use static closures when not using '' (#52781) * removes check for active preview device type to enable the fixed toolbar preference (#52770) * Parser / Site Editor: Ensure autop is not run when freeform block is set to core/html (#52716) * Parse / Site Editor: Ensure autop is not run when freeform block is set to core/html * Switch to equals freeform instead of not equals core/html * Rename core/test-freeform to core/freeform in tests * Adding @SInCE annotation for relevant 6.3 changes. (#52820) * Navigation: Load the raw property on the navigation fallback (#52758) * Navigation: Load the raw property on the navigation fallback * Update lib/compat/wordpress-6.3/navigation-fallback.php Co-authored-by: Dave Smith <[email protected]> * Update lib/compat/wordpress-6.3/navigation-fallback.php Co-authored-by: Dave Smith <[email protected]> * Add a test for these properties * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * Update phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php Co-authored-by: Dave Smith <[email protected]> * add more comments * add necessary method * Fix php coding standards error --------- Co-authored-by: Dave Smith <[email protected]> Co-authored-by: Jerry Jones <[email protected]> * Allow styles to be changed dynamically through editor settings (#52767) * ResizableFrame: Fix styling in Firefox (#52700) * ResizableFrame: Fix styling in Firefox * Remove unused class * Patterns: Fix empty general template parts category (#52747) --------- Co-authored-by: Glen Davies <[email protected]> --------- Co-authored-by: Carolina Nymark <[email protected]> Co-authored-by: Andrea Fercia <[email protected]> Co-authored-by: Riad Benguella <[email protected]> Co-authored-by: Glen Davies <[email protected]> Co-authored-by: Ella <[email protected]> Co-authored-by: James Koster <[email protected]> Co-authored-by: Andrei Draganescu <[email protected]> Co-authored-by: George Mamadashvili <[email protected]> Co-authored-by: Andrei Draganescu <[email protected]> Co-authored-by: Andrew Serong <[email protected]> Co-authored-by: Ramon <[email protected]> Co-authored-by: Ben Dwyer <[email protected]> Co-authored-by: Dave Smith <[email protected]> Co-authored-by: Jerry Jones <[email protected]> Co-authored-by: Lena Morita <[email protected]> Co-authored-by: Kai Hao <[email protected]> Co-authored-by: Glen Davies <[email protected]>
What?
Removes the withSelect override of rootClientId added in #52671. Also refactors withSelect to useSelect
Why?
This rootClientId could be passed in by other components/plugins
How?
Only set the rootId in the menu component if the prop is not set.
Testing Instructions
Create pattern
menu appears and works as expectedCreate pattern
menu works as expected in the post editor still, and that create pattern menu does not appear in widget editorScreenshots or screencast
reusable-site-editor.mp4