diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index c1bb7378d09a0..79b4e8c6cd67c 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -193,9 +193,13 @@ function Navigation( { hasUncontrolledInnerBlocks, uncontrolledInnerBlocks, isInnerBlockSelected, - hasSubmenus, + innerBlocks, } = useInnerBlocks( clientId ); + const hasSubmenus = !! innerBlocks.find( + ( block ) => block.name === 'core/navigation-submenu' + ); + const { replaceInnerBlocks, selectBlock, diff --git a/packages/block-library/src/navigation/edit/use-inner-blocks.js b/packages/block-library/src/navigation/edit/use-inner-blocks.js index 932ec79030e8b..70a8415e1f993 100644 --- a/packages/block-library/src/navigation/edit/use-inner-blocks.js +++ b/packages/block-library/src/navigation/edit/use-inner-blocks.js @@ -17,19 +17,17 @@ export function useInnerBlocks( clientId ) { // introduce a selector like `getUncontrolledInnerBlocks`, just in // case `getBlock` is fixed. const _uncontrolledInnerBlocks = getBlock( clientId ).innerBlocks; + const _hasUncontrolledInnerBlocks = !! _uncontrolledInnerBlocks?.length; const _controlledInnerBlocks = _hasUncontrolledInnerBlocks ? EMPTY_ARRAY : getBlocks( clientId ); - const innerBlocks = _hasUncontrolledInnerBlocks - ? _uncontrolledInnerBlocks - : _controlledInnerBlocks; return { - hasSubmenus: !! innerBlocks.find( - ( block ) => block.name === 'core/navigation-submenu' - ), + innerBlocks: _hasUncontrolledInnerBlocks + ? _uncontrolledInnerBlocks + : _controlledInnerBlocks, hasUncontrolledInnerBlocks: _hasUncontrolledInnerBlocks, uncontrolledInnerBlocks: _uncontrolledInnerBlocks, controlledInnerBlocks: _controlledInnerBlocks,