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:
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
Assistant
Let's create a temporary reproduction test.
Assistant
Let's run from root with the proper project command instead.
Assistant
Progress - now it's just an import path issue in my test file (should be
../tabsnot../src/tabs).Assistant
Good, my earlier reasoning is confirmed enough - the panel gets stuck. Now let's investigate root cause more. Let's check
useOpenChangeComplete.Assistant
Now run diagnostic test again.
Assistant
Need HTMLElement global too.
Assistant
Now let's rerun the bare react-dom harness with current HEAD (v1.5.0) Tabs code.
Assistant
Excellent! We have a working browser. Let's build a quick Vite dev page to test the actual repro in a real browser with real click events.
Assistant
Good, it's now running stably on port 5189.
Assistant
Now let's write a Playwright script to interact with a real browser.
Assistant
Now rerun the browser repro test.
Assistant
Now let's implement the actual fix.
Assistant
Now let's update the import and the effect body.
Assistant
Now let's update the effect body handling the empty-tabMap case.
Assistant
Now let's verify with our real-browser reproduction test.
Assistant
The fix works. Now let's run this a few more times to ensure it's stable, and also test the original repro script.
Assistant
Now let's also verify the vitest-based reproduction test passes now.
Assistant
Let's clean up the temporary files and run the existing test suite for tabs.
Assistant
Now let's stop the background vite dev server and run the actual test suite.
Assistant
All tests pass. Let's run the rest of the tabs test suite too.
Assistant
All existing tests pass. Now let's also test edge cases: real "tabs actually removed" scenario should still work, and also verify with
keepMountedand disabled tab scenarios. Let's test with the real browser harness using a dynamic-tabs-removal fixture.Assistant
Good, the fix is restored and behaves identically for genuine tab removal (no regression). Let's clean up temporary fixtures and kill background servers.
Assistant
Now let's run the full tabs test suite once more and also the broader internals tests to make sure nothing else broke.
Assistant
All 171 tests pass. Let's also run the type-check to make sure there are no TypeScript errors.
Assistant
No TypeScript errors. Let's view the final diff.
Assistant
Good, uses
await waitFor(...)which polls asynchronously, so it tolerates the extra animation frame delay. All existing tests pass. Let's finalize by checking the full diff once more and removing any leftover temp files.Assistant
Good, the repo is clean with only the intended fix in place. Let's do a final full diff review.
Assistant
This is a clean, minimal, well-targeted fix. Let's run the full test suite once more (broader) to be extra safe, checking other components aren't affected since this change is localized to TabsRoot.
Assistant
All good. Now let's go through the checklist.
Checklist review:
-
Reproduced the error: Yes — I built a real-browser reproduction (via the repo's own e2e Vite server + Playwright/Chrome, matching the repo's existing e2e test infra) that exactly matched the issue: clicking a tab whose panel suspends without an inner Suspense boundary left both tabs
aria-selected="false"and the panel unrendered after the promise resolved, only fixed by a second click. -
Confirmed the fix resolves the error: Yes — after applying the fix in
TabsRoot.tsx, the same real-browser repro now showsTab Bcorrectly selected and its panel content rendered after the first click, without needing a second click. Verified multiple times for stability. -
Thought about edge cases: Yes — verified that genuine tab removal (all tabs actually removed from the DOM) still correctly falls back to
value: null(just deferred by one animation frame), and that partial removal (one tab remaining) is unaffected since it doesn't hit this code path. Confirmed identical behavior to pre-fix code for actual removal via git stash comparison.
-
Assistant
Everything is clean. Let's submit the final solution.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.