Skip to content

Commit

Permalink
Try using a templated page list when there are no menus or inner bloc…
Browse files Browse the repository at this point in the history
…ks, replacing the current effect
  • Loading branch information
talldan committed Sep 30, 2022
1 parent 9ae5785 commit bcdeea8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
20 changes: 3 additions & 17 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -621,14 +607,14 @@ function Navigation( {
</InspectorControls>
);

// 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 (
<TagName { ...blockProps }>
<InspectorControls>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default function UnsavedInnerBlocks( {
className: 'wp-block-navigation__container',
},
{
template: [ [ 'core/page-list' ] ],
renderAppender: hasSelection ? undefined : false,
allowedBlocks: ALLOWED_BLOCKS,
__experimentalDefaultBlock: DEFAULT_BLOCK,
Expand Down

0 comments on commit bcdeea8

Please sign in to comment.