-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
Description
useEffect hooks are running twice on mount when using Gutenberg 19.1.0-rc.1.
For example:
useEffect( () => {
console.log( 'mounted' );
}, [] );
Without the Gutenberg plugin, this runs one time.
With the Gutenberg plugin, this runs twice.
This is especially an issue when using a pattern like the below.
const isOnMount = useRef( true );
useEffect( () => {
if ( isOnMount.current ) {
isOnMount.current = false;
return; // Skip the first render
}
// Code to run on updates only
console.log( 'useEffect ran on update only' );
}, [ dep ] );
Using Gutenberg, code that is not intended to run on mount is running.
That being said, it's just generally a bad thing that hooks are running twice like this.
Step-by-step reproduction instructions
- Activate Gutenberg 19.0
- Implement a simple on mount hook with a
console.log()in it. - Check the different between your console when using the Gutenberg plugin and not.
Environment info
- WordPress 6.6.1
- Gutenberg 19.1.0-rc.1
Please confirm that you have searched existing issues in the repo.
- Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- Yes
Metadata
Metadata
Assignees
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended