Skip to content

Commit

Permalink
Navigation: Improve trigger for fallback navigation (WordPress#66478)
Browse files Browse the repository at this point in the history
Co-authored-by: tyxla <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: draganescu <[email protected]>
  • Loading branch information
4 people authored and karthick-murugan committed Nov 13, 2024
1 parent b96bc6f commit 3da4c52
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
}
Expand Down

0 comments on commit 3da4c52

Please sign in to comment.