ISSUE DESCRIPTION [tabs] Tabs.Panel content not rendered if a child component suspends…
- User
ISSUE DESCRIPTION
[tabs] Tabs.Panel content not rendered if a child component suspends without boundary within Tabs.Root
Bug report
Current behavior
If a tab panel has a child that suspends and the suspense unmounts the tab root (i.e., the next boundary is outside the
Tabs.Rootcomponent), the panel content is not rendered when opening a tab for the first time.Only when clicking the trigger a second time, the panel is rendered.
Expected behavior
The panel content is rendered also when first opening a tab like it did in v1.4.1.
Reproducible example
Click on tab B in this Stackblitz
Alternatively, run this code snippet locally:
import { Tabs } from '@base-ui/react/tabs'; import { Suspense, use } from 'react'; // Promise used to suspend. const dataPromise = new Promise<string>((resolve) => setTimeout(() => resolve('Panel B is rendered'), 500) ); function SuspendingChild() { return <div>{use(dataPromise)}</div>; } export default function App() { return ( // The Suspense boundary is outside the <Tabs.Root> and the panels/panel content don't use a separate suspense boundary. <Suspense fallback={<div>Loading…</div>}> <Tabs.Root defaultValue="a"> <Tabs.List> <Tabs.Tab value="a">Tab A</Tabs.Tab> <Tabs.Tab value="b">Tab B</Tabs.Tab> </Tabs.List> <Tabs.Panel value="a">Panel A (no suspense)</Tabs.Panel> <Tabs.Panel value="b"> <SuspendingChild /> </Tabs.Panel> </Tabs.Root> </Suspense> ); }Base UI version
The only affected version is v1.5.0
v1.4.1 is not affected
Which browser are you using?
Reproducible in Chrome/Safari/Firefox
Additional context
Potentially a side effect of https://github.com/mui/base-ui/pull/4704
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /base-ui, current file: none) bash-$
Assistant
Let's write a temporary reproduction test script to confirm the bug and understand behavior.
Assistant
Now add logging to TabsRoot's automatic effect.
Assistant
Now let's run the repro test (single debug, at the end) with logging enabled.
Assistant
Good, reverted debug changes. Now let's implement the actual fix.
Assistant
Now let's implement the fix with the microtask-based deferral for missing-tab detection.
Assistant
Now let's write the repro test back (clean version) and run it to verify the fix.
Assistant
The fix works. Now let's remove the temporary repro test file and run the full TabsRoot test suite plus related tests to check for regressions.
Assistant
All tabs tests pass. Now let's run the full test suite (jsdom) to check for broader regressions, particularly other components using CompositeList since we didn't touch that file, but let's also run internals tests.
Assistant
All 279 test files pass (6369 tests passed, 895 skipped). Now let's check TypeScript type checking for the changed file.
Assistant
No TypeScript errors. Let's also run eslint on the modified file.
Assistant
Let's make all the outer effect's bare
return;statements consistent withreturn undefined;to satisfy the lint rule.Assistant
Also need the final implicit return at the end of the function (no explicit return statement) to be consistent — but consistent-return only cares about explicit
returnstatements typically; let's re-run eslint.Assistant
Need to add explicit
return undefined;at the end of the function too.Assistant
Lint passes now. Let's re-run the full tabs test suite and the reproduction test again to make sure everything still works after these edits.
Assistant
All tests pass. Now remove the temporary repro test file and run the full test suite once more (chromium too, since that's the default
testtarget) to be thorough.Assistant
Now let's run the complete test suite once more to make sure nothing broke, and also double check the prettier formatting.
Assistant
All 6369 tests pass with no regressions. Let's do a final review of the diff and clean up.
Assistant
Only the intended file is modified, and the temporary reproduction/debug files have been removed. Let's do one final full diff review.
Assistant
This looks clean and minimal. Let's go through the checklist.
Checklist Review
1. If an error was reported in the issue description, I have successfully reproduced it.
Assistant
Summary of root cause and fix:
Root cause: PR #4704 added logic to
TabsRoot's automatic-fallbackuseIsoLayoutEffectthat treats an empty (or partially empty)tabMap/missingselectedTabMetadataas "tabs were removed from the DOM" and eagerly resets the uncontrolledvaluetonull(or to the first enabled tab). However, when a descendant insideTabs.Rootsuspends and the nearestSuspenseboundary is outsideTabs.Root, React keeps the previously-committed tree mounted (hidden) and, once the promise resolves, re-establishes its effects as if freshly mounted. This causes theCompositeListused to trackTab/Panelregistrations to transiently unregister and re-register all tabs (a real, momentarytabMap.size === 0, or a temporarily-missing entry for the selected value) purely due to this effect-remount churn — not because any tab was actually removed. The effect saw this transient state and permanently committedvalue = null, and oncevaluewasnull, the "missing" detection logic no longer fired to correct it back, silently breaking tab selection until a subsequent user-triggered click resetvalueagain.Fix: In
TabsRoot.tsx, defer the "tabs missing" fallback commits (both the fully-empty-map case and the single-missing-tab case) to a microtask, re-verifying at that point whether the tabs are still missing. Because the transient re-registration churn completes synchronously (within the same commit cascade) before any microtask runs, the effect's cleanup (triggered whentabMapchanges again) cancels the pending fallback before it ever executes. Genuine removals (where the tabs really stay gone) still correctly trigger the fallback via the microtask, just one tick later — which existing tests already tolerate since they assert viawaitFor. The "disabled tab" fallback path remains synchronous since it isn't subject to this registration churn.Verified: reproduced the bug with a temporary test mimicking the issue's Suspense scenario, confirmed it failed before the fix and passed after; ran the full Tabs test suite and the entire jsdom unit test suite (6369 tests) with no regressions; ran
tscandeslint/prettierclean on the changed file.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →