[Tabs] Fix React 18 roving tabindex and dedupe invalid-value warning#48605
Merged
Conversation
Deploy previewhttps://deploy-preview-48605--material-ui.netlify.app/ Bundle size
Check out the code infra dashboard for more information about this PR. |
e3eb2cf to
abcae94
Compare
abcae94 to
3a1ad68
Compare
mj12albert
approved these changes
Jun 1, 2026
Co-authored-by: Albert Yu <albert@albertyu.co> Signed-off-by: Jan Potoms <2109932+Janpot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the
nightly-crontest_unit-react@18failures inTabs.test.js. Both reproduce only under React 18 (pass under React 19/next), and have separate causes.1.
useRovingTabIndex: active item not updating under React 18 (real bug)<Tabs>did not move the rovingtabIndexto the newly selected tab when thevalueprop changed under React 18 (confirmed withwaitFor— it never converges, so it's a behavior bug, not test timing). React 18 is a supported peer dependency, so this affects real users.The hook derived state from the
activeItemIdprop by mutating a ref during render:That isn't idempotent under StrictMode's double-render: React resets state between the two render invocations but preserves ref mutations, so on the replay the guard already sees the new value and skips the update. Switched to the documented "store the previous prop in state" pattern.
2.
Tabs: invalidvaluewarning logged from every effectThe invalid-
valuedev warning lives insidegetTabsMeta, which runs from several effects, so it logged multiple times per mount and the count varied under React 18 StrictMode. Guarded it with aWeakMapkeyed by theTabsinstance's ref, so the warning is logged once per instance (rather than once globally — a global flag would persist across instances/tests and suppress later warnings). TheWeakMapis only referenced fromprocess.env.NODE_ENV !== 'production'blocks and carries a/* @__PURE__ */annotation, so minifiers drop it (and the allocation) from production builds. Simplified the test expectation accordingly.Verification
useRovingTabIndex+Tabs+MenuList+Stepper+MobileSteppertest suites pass under both react@18 (useReactVersion ^18) and react@next (19.3.0-canary).