From f2c6766df42a9b28d1b71a6ff60d35df86dad45a Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Mon, 17 Oct 2022 14:56:24 -0400 Subject: [PATCH 1/7] ignore warning on useUpdateEffect --- .../components/src/ui/context/context-system-provider.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/components/src/ui/context/context-system-provider.js b/packages/components/src/ui/context/context-system-provider.js index d72fac51be99f..27ff8d8b9e650 100644 --- a/packages/components/src/ui/context/context-system-provider.js +++ b/packages/components/src/ui/context/context-system-provider.js @@ -35,6 +35,11 @@ function useUpdateEffect( effect, deps ) { } mounted.current = true; return undefined; + // Disable reasons: + // 1. This hook needs to pass a dep list that isn't an array literal + // 2. `effect` is missing from the array, and will need to be added carefully to avoid additional warnings + // see https://github.com/WordPress/gutenberg/pull/41166 + // eslint-disable-next-line react-hooks/exhaustive-deps }, deps ); } From 1ba1fbd55181bbb47605aaedb0c70179f28ada18 Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Mon, 17 Oct 2022 15:05:41 -0400 Subject: [PATCH 2/7] Components: update CHANGELOG --- packages/components/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 18a230c301d46..20702cfd54764 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -54,6 +54,7 @@ - `Sandbox`: updated to satisfy `react/exhaustive-deps` eslint rule ([#44378](https://github.com/WordPress/gutenberg/pull/44378)) - `FontSizePicker`: Convert to TypeScript ([#44449](https://github.com/WordPress/gutenberg/pull/44449)). - `FontSizePicker`: Replace SCSS with Emotion + components ([#44483](https://github.com/WordPress/gutenberg/pull/44483)). +- `Context`: updated to ignore `react/exhaustive-deps` eslint rule ([#45044](https://github.com/WordPress/gutenberg/pull/45044)) ### Experimental From 9a277aa7aa33ae93df091725fa62344943c488b3 Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Mon, 17 Oct 2022 15:11:34 -0400 Subject: [PATCH 3/7] also ignore useUpdateEffect from utils directory --- packages/components/src/utils/hooks/use-update-effect.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/components/src/utils/hooks/use-update-effect.js b/packages/components/src/utils/hooks/use-update-effect.js index aaf04478b3860..f20c71e1b56f3 100644 --- a/packages/components/src/utils/hooks/use-update-effect.js +++ b/packages/components/src/utils/hooks/use-update-effect.js @@ -20,6 +20,11 @@ function useUpdateEffect( effect, deps ) { } mounted.current = true; return undefined; + // Disable reasons: + // 1. This hook needs to pass a dep list that isn't an array literal + // 2. `effect` is missing from the array, and will need to be added carefully to avoid additional warnings + // see https://github.com/WordPress/gutenberg/pull/41166 + // eslint-disable-next-line react-hooks/exhaustive-deps }, deps ); } From 4a3aa8c377f98a22c9f939687026ac5ba3205e8b Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Wed, 19 Oct 2022 14:10:39 -0400 Subject: [PATCH 4/7] fix CHANGELOG update placement --- packages/components/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 20702cfd54764..d21d912ad804d 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -23,6 +23,7 @@ - `withFocusReturn`: Refactor tests to `@testing-library/react` ([#45012](https://github.com/WordPress/gutenberg/pull/45012)). - `ToolsPanel`: updated to satisfy `react/exhaustive-deps` eslint rule ([#45028](https://github.com/WordPress/gutenberg/pull/45028)) - `Tooltip`: updated to ignore `react/exhaustive-deps` eslint rule ([#45043](https://github.com/WordPress/gutenberg/pull/45043)) +- `Context`: updated to ignore `react/exhaustive-deps` eslint rule ([#45044](https://github.com/WordPress/gutenberg/pull/45044)) ## 21.2.0 (2022-10-05) @@ -54,7 +55,6 @@ - `Sandbox`: updated to satisfy `react/exhaustive-deps` eslint rule ([#44378](https://github.com/WordPress/gutenberg/pull/44378)) - `FontSizePicker`: Convert to TypeScript ([#44449](https://github.com/WordPress/gutenberg/pull/44449)). - `FontSizePicker`: Replace SCSS with Emotion + components ([#44483](https://github.com/WordPress/gutenberg/pull/44483)). -- `Context`: updated to ignore `react/exhaustive-deps` eslint rule ([#45044](https://github.com/WordPress/gutenberg/pull/45044)) ### Experimental From 8af7a038571d9c01d38a6b63c2ced23970dce894 Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Wed, 19 Oct 2022 14:15:40 -0400 Subject: [PATCH 5/7] remove local useUpdateEffect in favor of the utils version --- .../src/ui/context/context-system-provider.js | 27 +++---------------- .../src/utils/hooks/use-update-effect.js | 1 - 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/packages/components/src/ui/context/context-system-provider.js b/packages/components/src/ui/context/context-system-provider.js index 27ff8d8b9e650..723c29c3db18d 100644 --- a/packages/components/src/ui/context/context-system-provider.js +++ b/packages/components/src/ui/context/context-system-provider.js @@ -10,39 +10,20 @@ import { createContext, useContext, useRef, - useEffect, useMemo, memo, } from '@wordpress/element'; import warn from '@wordpress/warning'; +/** + * Internal dependencies + */ +import { useUpdateEffect } from '../../utils'; export const ComponentsContext = createContext( /** @type {Record} */ ( {} ) ); export const useComponentsContext = () => useContext( ComponentsContext ); -/** - * Runs an effect only on update (i.e., ignores the first render) - * - * @param {import('react').EffectCallback} effect - * @param {import('react').DependencyList} deps - */ -function useUpdateEffect( effect, deps ) { - const mounted = useRef( false ); - useEffect( () => { - if ( mounted.current ) { - return effect(); - } - mounted.current = true; - return undefined; - // Disable reasons: - // 1. This hook needs to pass a dep list that isn't an array literal - // 2. `effect` is missing from the array, and will need to be added carefully to avoid additional warnings - // see https://github.com/WordPress/gutenberg/pull/41166 - // eslint-disable-next-line react-hooks/exhaustive-deps - }, deps ); -} - /** * Consolidates incoming ContextSystem values with a (potential) parent ContextSystem value. * diff --git a/packages/components/src/utils/hooks/use-update-effect.js b/packages/components/src/utils/hooks/use-update-effect.js index f20c71e1b56f3..ab96caf579975 100644 --- a/packages/components/src/utils/hooks/use-update-effect.js +++ b/packages/components/src/utils/hooks/use-update-effect.js @@ -13,7 +13,6 @@ import { useRef, useEffect } from '@wordpress/element'; */ function useUpdateEffect( effect, deps ) { const mounted = useRef( false ); - useEffect( () => { if ( mounted.current ) { return effect(); From 7e0cb7673cbabd87d0446df64ff3165a0f3ce103 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Thu, 20 Oct 2022 10:07:22 +0200 Subject: [PATCH 6/7] Update packages/components/src/ui/context/context-system-provider.js --- packages/components/src/ui/context/context-system-provider.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/components/src/ui/context/context-system-provider.js b/packages/components/src/ui/context/context-system-provider.js index 723c29c3db18d..6fe0053dbcd8c 100644 --- a/packages/components/src/ui/context/context-system-provider.js +++ b/packages/components/src/ui/context/context-system-provider.js @@ -14,6 +14,7 @@ import { memo, } from '@wordpress/element'; import warn from '@wordpress/warning'; + /** * Internal dependencies */ From 40318034938d9ad131dbd550579e236b9e8659d6 Mon Sep 17 00:00:00 2001 From: chad1008 <13856531+chad1008@users.noreply.github.com> Date: Thu, 20 Oct 2022 14:33:35 -0400 Subject: [PATCH 7/7] update CHANGELOG --- packages/components/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 0fa97f466e531..23053fc9049e2 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -14,6 +14,7 @@ - `AnglePickerControl`: Set Storybook Label control type to 'text' ([#45122](https://github.com/WordPress/gutenberg/pull/45122)). - `SlotFill`: updated to satisfy `react/exhaustive-deps` eslint rule ([#44403](https://github.com/WordPress/gutenberg/pull/44403)) +- `Context`: updated to ignore `react/exhaustive-deps` eslint rule ([#45044](https://github.com/WordPress/gutenberg/pull/45044)) ## 21.3.0 (2022-10-19) @@ -38,7 +39,6 @@ - `withFocusReturn`: Refactor tests to `@testing-library/react` ([#45012](https://github.com/WordPress/gutenberg/pull/45012)). - `ToolsPanel`: updated to satisfy `react/exhaustive-deps` eslint rule ([#45028](https://github.com/WordPress/gutenberg/pull/45028)) - `Tooltip`: updated to ignore `react/exhaustive-deps` eslint rule ([#45043](https://github.com/WordPress/gutenberg/pull/45043)) -- `Context`: updated to ignore `react/exhaustive-deps` eslint rule ([#45044](https://github.com/WordPress/gutenberg/pull/45044)) ## 21.2.0 (2022-10-05)