Skip to content

Commit

Permalink
Don't request the deprecated navigation areas endpoint outside of the…
Browse files Browse the repository at this point in the history
… Gutenberg plugin (#37187)

* Only call useEntityProp when process.env.GUTENBERG_PHASE === 2 )

* Give setAreaMenu a default value so that it can be safely called
  • Loading branch information
adamziel authored and noisysocks committed Dec 13, 2021
1 parent 20d86d0 commit 424d02b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import classnames from 'classnames';
import noop from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -109,12 +110,19 @@ function Navigation( {
layout: { justifyContent, orientation = 'horizontal' } = {},
} = attributes;

const [ areaMenu, setAreaMenu ] = useEntityProp(
'root',
'navigationArea',
'navigation',
navigationArea
);
let areaMenu,
setAreaMenu = noop;
// Navigation areas are deprecated and on their way out. Let's not perform
// the request unless we're in an environment where the endpoint exists.
if ( process.env.GUTENBERG_PHASE === 2 ) {
// eslint-disable-next-line react-hooks/rules-of-hooks
[ areaMenu, setAreaMenu ] = useEntityProp(
'root',
'navigationArea',
'navigation',
navigationArea
);
}

const navigationAreaMenu = areaMenu === 0 ? undefined : areaMenu;

Expand Down

0 comments on commit 424d02b

Please sign in to comment.