-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Don't request the deprecated navigation areas endpoint outside of the Gutenberg plugin #37187
Conversation
Size Change: +17 B (0%) Total Size: 1.11 MB
ℹ️ View Unchanged
|
'navigation', | ||
navigationArea | ||
); | ||
let areaMenu, setAreaMenu; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should set a default value for setAreaMenu
, probably a loadash noop
, otherwise calling it will trigger an error.
// 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this by:
- Adding a Navigation block and seeing that a request to
block-navigation-areas
was in DevTools. - Changing
GUTENBERG_PHASE
to 1 inpackage.json
and rebuilding. - Adding a Navigation block and seeing that there was no request to
block-navigation-areas
in DevTools.
… Gutenberg plugin (#37187) * Only call useEntityProp when process.env.GUTENBERG_PHASE === 2 ) * Give setAreaMenu a default value so that it can be safely called
Description
Solves #37138
The navigation areas endpoint is not shipped with core, yet the
useEntityProp
endpoint causes a HTTP request. This PR restricts that HTTP exchange to when the Gutenberg plugin is active by guarding the call touseEntityProp
with a check forprocess.env.GUTENBERG_PHASE === 2
. Normally guarding react hooks is a big no-no, but this should be okay since the variable is fixed.How has this been tested?
/wp/v2/block-navigation-areas