Skip to content

Commit

Permalink
Block Hooks: Do not remove toggle if hooked block is present elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jan 18, 2024
1 parent cac5e53 commit a322048
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions packages/block-editor/src/hooks/block-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,8 @@ function BlockHooksControlPure( { name, clientId } ) {
}

// If no hooked block was found in any of its designated locations,
// but it exists elsewhere in the block tree, we consider it manually inserted.
// In this case, we take note and will remove the corresponding toggle from the
// block inspector panel.
return {
...clientIds,
[ block.name ]: false,
};
// we set the toggle to disabled.
return clientIds;
},
{}
);
Expand All @@ -118,13 +113,7 @@ function BlockHooksControlPure( { name, clientId } ) {

const { insertBlock, removeBlock } = useDispatch( blockEditorStore );

// Remove toggle if block isn't present in the designated location but elsewhere in the block tree.
const hookedBlocksForCurrentBlockIfNotPresentElsewhere =
hookedBlocksForCurrentBlock?.filter(
( block ) => hookedBlockClientIds?.[ block.name ] !== false
);

if ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) {
if ( ! hookedBlocksForCurrentBlock.length ) {
return null;
}

Expand Down

0 comments on commit a322048

Please sign in to comment.