Skip to content
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: Rerender toolbar when parent block changes #59234

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function PrivateBlockToolbar( {
isDefaultEditingMode,
blockType,
blockName,
toolbarKey,
shouldShowVisualToolbar,
showParentSelector,
isUsingBindings,
Expand Down Expand Up @@ -103,6 +104,7 @@ export function PrivateBlockToolbar( {
blockType: selectedBlockClientId && getBlockType( _blockName ),
shouldShowVisualToolbar: isValid && isVisual,
rootClientId: blockRootClientId,
toolbarKey: `${ selectedBlockClientId }${ firstParentClientId }`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add a new selected key here? Can't we concatenate on render?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need access to the firstParentClientId outside of the selector, so we'll need to add a selected key of either the firstParentClientId or the concatenated toolbarKey. I can see how firstParentClientId would be more potentially useful than a toolbarKey.

showParentSelector:
parentBlockType &&
getBlockEditingMode( firstParentClientId ) === 'default' &&
Expand Down Expand Up @@ -159,7 +161,7 @@ export function PrivateBlockToolbar( {
__experimentalOnIndexChange={ __experimentalOnIndexChange }
// Resets the index whenever the active block changes so
// this is not persisted. See https://github.com/WordPress/gutenberg/pull/25760#issuecomment-717906169
key={ blockClientId }
key={ toolbarKey }
>
<div ref={ toolbarWrapperRef } className={ innerClasses }>
{ ! isMultiToolbar &&
Expand Down
Loading