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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- `Placeholder`: Fix Global Styles typography settings bleeding into placeholder component ([#58303](https://github.com/WordPress/gutenberg/pull/58303)).
- `PaletteEdit`: Fix palette item accessibility in details view ([#58214](https://github.com/WordPress/gutenberg/pull/58214)).
- `Snackbar`: Fix the auto-dismissal timers ([#58604](https://github.com/WordPress/gutenberg/pull/58604)).
- `Tabs`: Fix infinite loop in `useEffect` ([#58861](https://github.com/WordPress/gutenberg/pull/58861)).

### Experimental

Expand Down
8 changes: 1 addition & 7 deletions packages/components/src/tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

selectedTab,
selectedTabId,
setSelectedId,
] );
}, [ isControlled, selectedTab, selectedTabId, setSelectedId ] );

useEffect( () => {
if ( ! isControlled ) {
Expand Down