From de70dd0289b19ce235b897213d349f78635d837b Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Dec 2024 09:57:50 +0000 Subject: [PATCH] Flush stale fallback ID when fallback Navigation Menu is deleted --- packages/core-data/src/reducer.js | 12 ++++++++++++ .../use-navigation-menu-handlers.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/core-data/src/reducer.js b/packages/core-data/src/reducer.js index 9748355fc5caf..6eb792facbd67 100644 --- a/packages/core-data/src/reducer.js +++ b/packages/core-data/src/reducer.js @@ -583,6 +583,18 @@ export function navigationFallbackId( state = null, action ) { switch ( action.type ) { case 'RECEIVE_NAVIGATION_FALLBACK_ID': return action.fallbackId; + case 'REMOVE_ITEMS': + // if the kind is postType + // and the type if `wp_navigation` + // and the item is the fallback id + // then remove the fallback id + if ( + action.kind === 'postType' && + action.name === 'wp_navigation' && + state === action.itemIds[ 0 ] + ) { + return null; + } } return state; diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js index 11635c6c6abb1..4138280c2ba28 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js @@ -42,7 +42,7 @@ function useDeleteNavigationMenu() { type: 'snackbar', } ); - history.navivate( '/navigation' ); + history.navigate( '/navigation' ); } catch ( error ) { createErrorNotice( sprintf(