diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js index 18e6a4210ee1b..ece549f57378b 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js @@ -43,9 +43,6 @@ function buildMenuLabel( title, id, status ) { ); } -// Save a boolean to prevent us creating a fallback more than once per session. -let hasCreatedFallback = false; - export default function SidebarNavigationScreenNavigationMenus( { backPath } ) { const { records: navigationMenus, @@ -61,21 +58,22 @@ export default function SidebarNavigationScreenNavigationMenus( { backPath } ) { isResolvingNavigationMenus && ! hasResolvedNavigationMenus; const { getNavigationFallbackId } = unlock( useSelect( coreStore ) ); + const isCreatingNavigationFallback = useSelect( + ( select ) => + select( coreStore ).isResolving( 'getNavigationFallbackId' ), + [] + ); const firstNavigationMenu = navigationMenus?.[ 0 ]; - // Save a boolean to prevent us creating a fallback more than once per session. - if ( firstNavigationMenu ) { - hasCreatedFallback = true; - } - // If there is no navigation menu found // then trigger fallback algorithm to create one. if ( ! firstNavigationMenu && ! isResolvingNavigationMenus && hasResolvedNavigationMenus && - ! hasCreatedFallback + // Ensure a fallback navigation is created only once + ! isCreatingNavigationFallback ) { getNavigationFallbackId(); }