Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs: Fix infinite loop in useEffect #58861

Merged
merged 2 commits into from Feb 9, 2024
Merged

Tabs: Fix infinite loop in useEffect #58861

merged 2 commits into from Feb 9, 2024

Conversation

mirka
Copy link
Member

@mirka mirka commented Feb 8, 2024

What?

Removes an extraneous dependency in a Tabs useLayoutEffect that can cause an infinite loop crash.

Why?

Fixes a bug that manifests in WP Core (first breaking commit), but not within the Gutenberg repo. (I have not yet looked into why.)

Testing Instructions

Set up

  1. Check out and build this PR branch.
  2. Clone the wordpress-develop repo and follow the instructions to set up a local dev environment. (Don't forget to read the extra steps for Apple Silicon if that applies to you.)
  3. Copy the packages/components/build-module from the gutenberg directory to the node_modules/@wordpress/components/build-module of the wordpress-develop directory. (Something like rsync --recursive ../gutenberg/packages/components/build-module/ node_modules/@wordpress/components/build-module.) I don't know why, but simply aliasing the @wordpress/components in package.json to the locally-built package file didn't work for me.
  4. npm run build:dev in wordpress-develop

Steps

Go to the post editor and toggle the Settings sidebar on and off and on again. The editor should not crash. (Also, doing this same thing in the gutenberg dev env should also not crash, as before.)

Settings sidebar toggle

@mirka mirka added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Feb 8, 2024
@mirka mirka requested review from youknowriad and a team February 8, 2024 21:49
@mirka mirka self-assigned this Feb 8, 2024
@mirka mirka requested a review from ajitbohra as a code owner February 8, 2024 21:49
Copy link

github-actions bot commented Feb 8, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: andrewhayward <andrewhayward@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@@ -151,13 +151,7 @@ function Tabs( {
if ( tabsHavePopulated.current && !! selectedTabId && ! selectedTab ) {
setSelectedId( null );
}
}, [
isControlled,
selectedId,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectedId is not referenced inside this hook, and nothing in the history suggests that it was an intentional addition to the dep array. I have to think it was just a mistake.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that selectedTab is explicitly derived from selectedId, and selectedId isn't used inside the hook, the change works for me.

Copy link
Contributor

@andrewhayward andrewhayward left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting to the bottom of this, @mirka!

@@ -151,13 +151,7 @@ function Tabs( {
if ( tabsHavePopulated.current && !! selectedTabId && ! selectedTab ) {
setSelectedId( null );
}
}, [
isControlled,
selectedId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that selectedTab is explicitly derived from selectedId, and selectedId isn't used inside the hook, the change works for me.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this change on top of trunk (modified node_modules) and it does fix the issue for me. Thank you.

@youknowriad youknowriad merged commit 194d208 into trunk Feb 9, 2024
60 checks passed
@youknowriad youknowriad deleted the fix/tabs-crash branch February 9, 2024 13:17
@github-actions github-actions bot added this to the Gutenberg 17.7 milestone Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants