diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index 6cb773e60107bd..44ce38ee547995 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -34,7 +34,6 @@ import { } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; import { speak } from '@wordpress/a11y'; -import { createBlock } from '@wordpress/blocks'; import { close, Icon } from '@wordpress/icons'; /** @@ -282,19 +281,6 @@ function Navigation( { hasResolvedNavigationMenus && ! hasUncontrolledInnerBlocks; - useEffect( () => { - if ( isPlaceholder && ! ref ) { - /** - * this fallback only displays (both in editor and on front) - * the list of pages block if no menu is available as a fallback. - * We don't want the fallback to request a save, - * nor to be undoable, hence we mark it non persistent. - */ - __unstableMarkNextChangeAsNotPersistent(); - replaceInnerBlocks( clientId, [ createBlock( 'core/page-list' ) ] ); - } - }, [ clientId, isPlaceholder, ref ] ); - const isEntityAvailable = ! isNavigationMenuMissing && isNavigationMenuResolved; @@ -621,14 +607,14 @@ function Navigation( { ); - // If the block has inner blocks, but no menu id, then these blocks are either: + // If no navigation menu entity is available, then these blocks are either: + // - showing the default Page List inner block when there are no menus or inner blocks of any kind. // - inserted via a pattern. // - inserted directly via Code View (or otherwise). // - from an older version of navigation block added before the block used a wp_navigation entity. // Consider this state as 'unsaved' and offer an uncontrolled version of inner blocks, // that automatically saves the menu as an entity when changes are made to the inner blocks. - const hasUnsavedBlocks = hasUncontrolledInnerBlocks && ! isEntityAvailable; - if ( hasUnsavedBlocks ) { + if ( ! isEntityAvailable ) { return ( diff --git a/packages/block-library/src/navigation/edit/unsaved-inner-blocks.js b/packages/block-library/src/navigation/edit/unsaved-inner-blocks.js index 892a86976412b3..ff4eaf2104806d 100644 --- a/packages/block-library/src/navigation/edit/unsaved-inner-blocks.js +++ b/packages/block-library/src/navigation/edit/unsaved-inner-blocks.js @@ -36,6 +36,8 @@ const ALLOWED_BLOCKS = [ 'core/navigation-submenu', ]; +const TEMPLATE = [ [ 'core/page-list' ] ]; + export default function UnsavedInnerBlocks( { blocks, clientId, @@ -82,6 +84,7 @@ export default function UnsavedInnerBlocks( { className: 'wp-block-navigation__container', }, { + template: TEMPLATE, renderAppender: hasSelection ? undefined : false, allowedBlocks: ALLOWED_BLOCKS, __experimentalDefaultBlock: DEFAULT_BLOCK,