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.
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.
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.
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.
Yeah, true, I guess that's ok then.
noisysocks
left a comment
There was a problem hiding this comment.
I tested this by:
- Adding a Navigation block and seeing that a request to
block-navigation-areaswas in DevTools. - Changing
GUTENBERG_PHASEto 1 inpackage.jsonand rebuilding. - Adding a Navigation block and seeing that there was no request to
block-navigation-areasin 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
useEntityPropendpoint causes a HTTP request. This PR restricts that HTTP exchange to when the Gutenberg plugin is active by guarding the call touseEntityPropwith 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