From e1aee89e4b424d2bd405cbdc236234a012f2d71f Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 26 Feb 2024 14:58:36 +0100 Subject: [PATCH] Block Hooks: Take controlled blocks into account for toggle state --- packages/block-editor/src/hooks/block-hooks.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/hooks/block-hooks.js b/packages/block-editor/src/hooks/block-hooks.js index 1e0b8e894d2067..de88b4fee8426b 100644 --- a/packages/block-editor/src/hooks/block-hooks.js +++ b/packages/block-editor/src/hooks/block-hooks.js @@ -35,12 +35,12 @@ function BlockHooksControlPure( { name, clientId } ) { const { blockIndex, rootClientId, innerBlocksLength } = useSelect( ( select ) => { - const { getBlock, getBlockIndex, getBlockRootClientId } = + const { getBlocks, getBlockIndex, getBlockRootClientId } = select( blockEditorStore ); return { blockIndex: getBlockIndex( clientId ), - innerBlocksLength: getBlock( clientId )?.innerBlocks?.length, + innerBlocksLength: getBlocks( clientId )?.length, rootClientId: getBlockRootClientId( clientId ), }; }, @@ -49,7 +49,7 @@ function BlockHooksControlPure( { name, clientId } ) { const hookedBlockClientIds = useSelect( ( select ) => { - const { getBlock, getGlobalBlockCount } = + const { getBlocks, getGlobalBlockCount } = select( blockEditorStore ); const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce( @@ -69,7 +69,7 @@ function BlockHooksControlPure( { name, clientId } ) { // Any of the current block's siblings (with the right block type) qualifies // as a hooked block (inserted `before` or `after` the current one), as the block // might've been automatically inserted and then moved around a bit by the user. - candidates = getBlock( rootClientId )?.innerBlocks; + candidates = getBlocks( rootClientId ); break; case 'first_child': @@ -77,7 +77,7 @@ function BlockHooksControlPure( { name, clientId } ) { // Any of the current block's child blocks (with the right block type) qualifies // as a hooked first or last child block, as the block might've been automatically // inserted and then moved around a bit by the user. - candidates = getBlock( clientId ).innerBlocks; + candidates = getBlocks( clientId ); break; }