From 3b24d79ab36d1f35ef816b8b1038b45f9154cd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 7 Dec 2021 16:54:32 +0100 Subject: [PATCH 1/2] Only call useEntityProp when process.env.GUTENBERG_PHASE === 2 ) --- .../block-library/src/navigation/edit/index.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index c6ab2f38d0e98a..c83b2f977f3c77 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -109,12 +109,18 @@ function Navigation( { layout: { justifyContent, orientation = 'horizontal' } = {}, } = attributes; - const [ areaMenu, setAreaMenu ] = useEntityProp( - 'root', - 'navigationArea', - 'navigation', - navigationArea - ); + let areaMenu, setAreaMenu; + // 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; From 12808f0e5d0653983cb42d23f9fc9022e71e3be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 7 Dec 2021 17:27:49 +0100 Subject: [PATCH 2/2] Give setAreaMenu a default value so that it can be safely called --- packages/block-library/src/navigation/edit/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index c83b2f977f3c77..486fc44c82e1d1 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -2,6 +2,7 @@ * External dependencies */ import classnames from 'classnames'; +import noop from 'lodash'; /** * WordPress dependencies @@ -109,7 +110,8 @@ function Navigation( { layout: { justifyContent, orientation = 'horizontal' } = {}, } = attributes; - let areaMenu, setAreaMenu; + 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 ) {