From bf8a2edd69cbe5a9d82f62fa6110136761186710 Mon Sep 17 00:00:00 2001 From: Jerry Jones Date: Mon, 6 Mar 2023 16:11:29 -0600 Subject: [PATCH] Fix classic menu fallback race condition When there are no navigation or classic menus, there is a fallback to use the page list of the navigation menu. This works well, but it isn't waiting to make sure the request for classic menus has completed before deciding if it should use the classic menu conversion process or fallback to the page list. This commit adds hasResolvedClassicMenu to the useEffect hook and early return to ensure we don't check for which menu to use until we have our classic menu request. --- packages/block-library/src/navigation/edit/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index 027b3b87a0a8a..8e6c4f9b9f6c8 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -119,7 +119,8 @@ function Navigation( { // Preload classic menus, so that they don't suddenly pop-in when viewing // the Select Menu dropdown. - const { menus: classicMenus } = useNavigationEntities(); + const { menus: classicMenus, hasResolvedMenus: hasResolvedClassicMenus } = + useNavigationEntities(); const [ showNavigationMenuStatusNotice, hideNavigationMenuStatusNotice ] = useNavigationNotice( { @@ -311,6 +312,7 @@ function Navigation( { useEffect( () => { if ( ref || + ! hasResolvedClassicMenus || ! hasResolvedNavigationMenus || isConvertingClassicMenu || fallbackNavigationMenus?.length > 0 || @@ -363,6 +365,7 @@ function Navigation( { ); } }, [ + hasResolvedClassicMenus, hasResolvedNavigationMenus, hasUnsavedBlocks, classicMenus,