Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't request the deprecated navigation areas endpoint outside of the Gutenberg plugin #37187

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's fine to ignore the rule of hooks. Won't this break other hooks since they need to be accessed in a known order?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it's okay because we can guarantee that GUTENBERG_PHASE won't change during the lifecycle of the application (it's a constant) and therefore the order in which the hooks are called won't change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, true, I guess that's ok then.

[ areaMenu, setAreaMenu ] = useEntityProp(
'root',
'navigationArea',
'navigation',
navigationArea
);
}

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

Expand Down