Untitled conversation
- User
[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:
codeimport { 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
- Assistant
Investigating the Tabs implementation and the v1.5.0 change that likely caused suspended panel content to fail on first open.
- Assistant
Writing a test to reproduce the Suspense issue, then tracing the mount logic.
- Assistant
The test reproduces the bug. Inspecting post-resolution DOM state and tracing the mount logic.
- Assistant
Identifying the root cause: after Suspense,
TabsRoot's layout effect can run with a stale emptytabMapwhiledidRegisterTabsRefis still true, incorrectly settingvaluetonull. Implementing a fix that defers the empty-map check until tabs have re-registered. - Assistant
Implementing the fix: deferring the empty
tabMapfallback so a transient empty map after Suspense doesn't reset the selection tonull. - Assistant
The suspense test passes. Running the full Tabs test suite to check for regressions.
- Assistant
Merging the suspense test into
TabsPanel.test.tsxto match project conventions. - Assistant
Fixed a regression introduced in v1.5.0 by PR #4704 where automatic tab selection logic treated a transient empty
tabMapas “all tabs removed.”Root cause
When a tab panel child suspends and the nearest
Suspenseboundary is outsideTabs.Root, React temporarily unmounts the tabs subtree. On recovery,Tabs.Root’s layout effect could run before child tabs re-registered intabMap. BecausedidRegisterTabsRefwas stilltruefrom before the suspend, the effect treated the empty map as a permanent removal and set the value tonull. That left no tab selected and no panel rendered until the tab was clicked again.Fix
In
TabsRoot.tsx, the “all tabs removed” fallback is now deferred by one animation frame. If tabs re-register during that frame (the normal Suspense recovery path), the fallback is canceled. It only commitsnullwhen the map is still empty on the next frame (actual tab removal).Test
Added a regression test in
TabsPanel.test.tsxmatching the bug report’s Stackblitz repro: uncontrolled tabs, externalSuspenseboundary, and a suspending panel child.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.