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
I'll investigate the Tabs component and the changes from PR #4704 that likely introduced this Suspense-related regression.
- Assistant
I'll add a failing test that reproduces the Suspense behavior, then trace the root cause.
- Assistant
The old
shouldRenderusedopendirectly; the transition refactor tied it only tomounted, which can block the first render. I'll apply that fix and run the test. - Assistant
The issue is
hidden = !mounted: whenopenis true butmountedis still false (e.g. after Suspense), the panel stays hidden. Collapsible useshidden = !open && !mountedinstead. - Assistant
Rewriting the suspense test to match the DialogPortal pattern and adding a focused unit test.
- Assistant
Adding a ref guard in
useOpenChangeCompleteto prevent stale closures, then running the full test suite. - Assistant
Fixed the regression in
Tabs.Panelintroduced when transition support was added in v1.5.0.Root cause
When transition attributes were added (#3880), panel visibility was tied to the internal
mountedtransition state instead of the selected tab:- Before:
hidden = !open,shouldRender = open || keepMounted - After (broken):
hidden = !mounted,shouldRender = mounted || keepMounted
When a child suspends and React hides the subtree via Suspense/Activity, the panel can resume with
open=truebutmounted=false. In that state the panel stayed hidden (hidden=true) or wasn't rendered at all (shouldRender=false) — matching the “tab selected, no content until second click” behavior.Fix
In
TabsPanel.tsx, aligned with the Collapsible pattern:hidden = !open && !mounted— an active panel is not hidden while its mount transition is in progress.
- Before:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.