Skip to content

Commit

Permalink
Only request fallback menu if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj committed Jul 19, 2023
1 parent 0ad4169 commit 55544a5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function Navigation( {
const [ overlayMenuPreview, setOverlayMenuPreview ] = useState( false );

const {
navigationMenus,
hasResolvedNavigationMenus,
isNavigationMenuResolved,
isNavigationMenuMissing,
Expand Down Expand Up @@ -226,16 +227,18 @@ function Navigation( {

const { getNavigationFallbackId } = unlock( useSelect( coreStore ) );

const navigationFallbackId = ! ( ref || hasUnsavedBlocks )
? getNavigationFallbackId()
: null;

useEffect( () => {
// If:
// - we haven't resolved the menus request and there isn't one missing, OR
// - there is an existing menu, OR
// - there are existing (uncontrolled) inner blocks
// ...then don't request a fallback menu.
if ( ref || hasUnsavedBlocks || ! navigationFallbackId ) {
if (
! navMenuResolvedButMissing ||
navigationMenus.length > 0 ||
ref ||
hasUnsavedBlocks
) {
return;
}

Expand All @@ -244,14 +247,15 @@ function Navigation( {
* The fallback should not request a save (entity dirty state)
* nor to be undoable, hence why it is marked as non persistent
*/

__unstableMarkNextChangeAsNotPersistent();
setRef( navigationFallbackId );
setRef( getNavigationFallbackId() );
}, [
ref,
setRef,
hasUnsavedBlocks,
navigationFallbackId,
navigationMenus,
navMenuResolvedButMissing,
getNavigationFallbackId,
__unstableMarkNextChangeAsNotPersistent,
] );

Expand Down

0 comments on commit 55544a5

Please sign in to comment.