From 97c78f5508d01c71f98297526e24a4e4e25b0785 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Fri, 30 Sep 2022 14:04:06 +0800 Subject: [PATCH] Fix navigation block console error (#44594) --- .../src/navigation/edit/index.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index 751d33b9b501f4..6cb773e60107bd 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -282,16 +282,18 @@ function Navigation( { hasResolvedNavigationMenus && ! hasUncontrolledInnerBlocks; - 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' ) ] ); - } + 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;