Skip to content

Commit 0c13990

Browse files
Mamadukaandrewserongtalldan
authored andcommitted
Components: Fix the 'useUpdateEffect' hook in strict mode (WordPress#62974)
* Components: Fix the 'useUpdateEffect' hook in strict mode * Add changelong entry Co-authored-by: Mamaduka <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: talldan <[email protected]>
1 parent 481141c commit 0c13990

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/components/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Bug Fixes
66

77
- `UnitControl`: Fix colors when disabled. ([#62970](https://github.com/WordPress/gutenberg/pull/62970))
8+
- `useUpdateEffect`: Correctly track mounted state in strict mode. ([#62974](https://github.com/WordPress/gutenberg/pull/62974))
89

910
### Internal
1011

packages/components/src/utils/hooks/use-update-effect.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useRef, useEffect } from '@wordpress/element';
66
/**
77
* A `React.useEffect` that will not run on the first render.
88
* Source:
9-
* https://github.com/ariakit/ariakit/blob/reakit/packages/reakit-utils/src/useUpdateEffect.ts
9+
* https://github.com/ariakit/ariakit/blob/main/packages/ariakit-react-core/src/utils/hooks.ts
1010
*
1111
* @param {import('react').EffectCallback} effect
1212
* @param {import('react').DependencyList} deps
@@ -25,6 +25,13 @@ function useUpdateEffect( effect, deps ) {
2525
// see https://github.com/WordPress/gutenberg/pull/41166
2626
// eslint-disable-next-line react-hooks/exhaustive-deps
2727
}, deps );
28+
29+
useEffect(
30+
() => () => {
31+
mounted.current = false;
32+
},
33+
[]
34+
);
2835
}
2936

3037
export default useUpdateEffect;

0 commit comments

Comments
 (0)