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 call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Assistant
I’ll inspect the repository structure, locate the Tabs implementation and its recent history around the referenced change, then identify focused tests and reproduce the suspension behavior before editing.
- Assistant
A very recent
[tabs] Fix state edge casescommit is present, so I’ll inspect both the current implementation/tests and that commit’s diff, as it may overlap with or clarify the regression while still leaving this Suspense case uncovered. - Assistant
The referenced commit changed automatic selection and registration behavior in
TabsRoot, which is likely interacting with React’s discarded suspended render. I’ll compare pre/post-#4704 root code and examine how tabs register and panels determine visibility. - Assistant
The suspicious branch is the new “all tabs unregistered after previously registering” fallback: when the outer Suspense boundary hides/unmounts the root during a transition, tab registration cleanup can set the uncontrolled value to
null. On retry, clicking B again restores it. I’ll inspect exact registration timing and test utilities/React version so I can build a regression test that distinguishes genuine tab removal from a suspended discarded tree. - Assistant
The registration map can become empty both when all tabs are intentionally removed and when Suspense temporarily hides the already-committed tree. Removing the empty-map fallback outright would regress the new
onValueChange(..., reason: 'missing')contract, so I’ll inspect those tests and React’s hidden-tree DOM/ref behavior to find a reliable guard (most likely root connectivity/visibility) rather than special-casing the example. - Assistant
I’ll reproduce this outside the test suite with a temporary standalone JSDOM script (removed afterward), logging the DOM and automatic change callbacks while the promise is pending and after it resolves. This also lets me verify whether the root remains connected but hidden during Suspense, which is important for choosing the guard.
- Assistant
pnpm execattempted an interactive Corepack download, which this environment disallows. I’ll use the already-installed local binaries directly and first check which TypeScript runner is available; the temporary file remains outside the repository. - Assistant
The local
tsxrunner is available. I’ll recreate and run the same focused reproduction with it, adding a forced process termination after logging so pending library timers cannot keep the script alive. - Assistant
The runner emits temporary files as CommonJS, so top-level await is unsupported. I’ll wrap the dynamic imports and reproduction flow in an async
main(); this does not affect the behavior under test. - Assistant
Module resolution is based on the temporary file’s directory, so
/tmpcannot see the workspace’s package store. I’ll place the same temporary script at the repository root, run it, and immediately remove it as permitted for reproduction scripts. - Assistant
Node 24 exposes a read-only global
navigator, so the setup failed before rendering. I’ll rerun without assigning that unnecessary global. - Assistant
The Base UI transition hook also expects browser animation-frame APIs. I’ll polyfill them with timers in the reproduction harness and rerun.
- Assistant
The reproduction confirms the exact regression: React keeps the root connected with
display: none !important, destroys its layout effects (which empties tab registration), then on reveal the new fallback commitsnullbefore tabs re-register. I’ll check repository branches/tags for an existing upstream fix pattern; otherwise I’ll preserve the selection across that effect-disconnect/reconnect window and defer genuine empty-list handling until registration has had a chance to settle. - Assistant
A minimal lifecycle-aware fix fits the existing
didRegisterTabsRef: reset it when the root’s layout effects disconnect. Normal removal of allTabs.Tabchildren does not disconnectTabs.Root, so it still reports a missing selection; Suspense disconnects the root first, so an empty map on reveal is treated like pre-registration and ignored until tabs re-register. I’ll implement that narrow change and rerun the reproduction. - Assistant
The line-based edit replaced the adjacent disabled-default ref and left the original registration ref duplicated. I’ll correct that block before testing: retain
shouldHonorDisabledDefaultValueRef, declaredidRegisterTabsRefonce, then add the lifecycle cleanup. - Assistant
The source block is now correct. I’ll rerun the identical temporary Suspense reproduction, specifically checking that no
null/missingcallback occurs and Panel B is present immediately after resolution. - Assistant
The first attempt exposed an extra ordering detail: on reveal,
TabsRootfirst sees the stale pre-hide non-empty map and marks registration complete, then receives the cleanup-empty map. I’ll track the exact map snapshot present when effects disconnect and ignore it; registration is considered restored only after a new non-empty map arrives. This handles both an explicit empty intermediate update and a directly batched fresh non-empty map. - Assistant
The second line-number edit was applied after the first edit shifted the file, so it landed inside
commitAutomaticValueChange. I’ll repair the entire affected effect prefix in one atomic replacement, restoring the helper exactly and placing the reconnect guard after it. - Assistant
The effect is repaired and passes whitespace validation. I’ll rerun the focused reproduction against this snapshot-aware implementation.
- Assistant
The reported scenario now passes: the pending fallback appears, resolution renders Panel B on the first click, B remains selected, and no spurious
null/missingchange is emitted. Next I’ll run the full Tabs root and panel unit suites in JSDOM, including the existing “selected tab removed/no tabs remain” cases to ensure normal missing-selection behavior still works. - Assistant
All 118 applicable Tabs root/panel tests pass, including the existing removal and disabled fallback coverage. I’ll now review the final diff, run formatting and TypeScript checks for the React package, and confirm there are no temporary or unintended files.
- Assistant
The final diff is limited to
TabsRoot.tsxand is Prettier-clean. I’ll invoke the locally installed compiler directly against the package project and lint the changed file; this avoids the environment’s interactive Corepack prompt. - Assistant
Validation is clean: TypeScript build and ESLint both pass. The snapshot guard preserves normal behavior because intentional tab removal occurs while
Tabs.Rooteffects remain connected; only an ancestor hide/disconnect activates the re-registration wait. It also accepts a fresh non-empty map whether React exposes an intermediate empty map or batches directly to re-registration.Checklist:
- Successfully reproduced the reported error. The temporary JSDOM/React 19 script showed the fallback, then a spurious
null/missingupdate and absent Panel B after promise resolution. - Confirmed the fix resolves the error. The same script now renders “Panel B is rendered” after the first click, leaves B selected, and emits only the user’s
bchange. - Considered edge cases. The implementation distinguishes stale pre-Suspense registration maps from fresh maps by identity, handles empty intermediate maps, preserves controlled behavior, and leaves ordinary all-tab removal fallback intact.
- Successfully reproduced the reported error. The temporary JSDOM/React 19 script showed the fallback, then a spurious
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.