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 start by exploring the repository structure and understanding the Tabs component related to this suspension bug.
- Assistant
Let me look at the Tabs component source and the PR that may have caused this.
- Assistant
Let me look at the PR #4704 and the tabs panel implementation.
- Assistant
There's also a recent tabs fix commit. Let me examine the panel and root implementations.
- Assistant
Let me read the TabsPanel and TabsRoot components to understand how they work.
- Assistant
Let me continue reading the rest of the file.
- Assistant
Let me look at TabsRoot which was changed in the related PR.
- Assistant
Let me continue reading TabsRoot and search for mounted panel registration logic.
- Assistant
Let me continue reading the automatic tab selection logic which seems key to this bug.
- Assistant
Let me continue reading the automatic selection logic.
- Assistant
Let me examine
useTransitionStatusand how panels handle mount during transitions. - Assistant
Let me check CHANGELOG and any related issues/PRs about this suspension bug.
- Assistant
Let me check the git history around Tabs and try to reproduce the issue.
- Assistant
Maybe tags are different. Let me check.
- Assistant
Let me examine the PR #4704 diff carefully since that's likely the culprit.
- Assistant
Let me look at existing tests and create a reproduction.
- Assistant
Let me check how to run tests and write a quick reproduction.
- Assistant
Let me search for Suspense-related tests and look at CompositeList.
- Assistant
Let me inspect the Dialog Suspense similarity and how tabs register.
- Assistant
I'll write a temporary reproduction test to observe the failure.
- Assistant
Let me run the test.
- Assistant
The test likely hung in watch mode. Let me check how to run it correctly.
- Assistant
I need to use
vitest runinstead of watch mode. - Assistant
Need to use pnpm exec or npx
- Assistant
The command timed out with no output. Let me try a different approach.
- Assistant
Corepack is waiting for confirmation. Let me fix the setup.
- Assistant
Good. Now let me run the tests.
- Assistant
Looking interesting - Loading stays forever. Let me inspect how the CompositeList populates tabMap.
- Assistant
Let me look at CompositeList's onMapChange and how TabsRoot uses it, and also see rest of file.
- Assistant
Interesting - CompositeList is used for panels. Let me find where tabs themselves register.
- Assistant
Let me check TabsList for tabMap.
- Assistant
I think I found the regression — empty tabMap after unregister forces value to null. Let me verify and check related tests.
- Assistant
Let me look at the test "calls onValueChange with null when the selected tab is removed and no tabs remain" and understand the intended behavior.
- Assistant
The key is distinguishing intentional empty tab list from Suspense unmounting. Let me look at TabsList and the automatic selection effect more carefully.
- Assistant
Let me verify the theory with a test that logs onValueChange.
- Assistant
Let me look at the full test output for the debug logs.
- Assistant
Let me fix the test based on the Dialog Suspense pattern — my act handling may be incorrect.
- Assistant
Confirmed: empty
tabMapduring Suspense sets value to null, which never recovers. I'll track TabsList mount presence and skip the null fallback when the list isn't mounted. - Assistant
I'll try deferring the null commit so Suspense unmount cleanups can cancel it.
- Assistant
Let me try tracking whether TabsList is mounted via context.
- Assistant
I'll implement a deferred empty-map null commit and verify with the reproduction test.
- Assistant
I need to navigate to that line first.
- Assistant
Applying a cleaner deferred fix now.
- Assistant
Let me run the reproduction test and the related “no tabs remain” test.
- Assistant
Both tests passed. Let me run the full tabs test suite to check for regressionsicht.
- Assistant
There's a stronger fix: skip automatic fallback when the root element is disconnected (e.g. during Suspense). Let me verify and switch to that.
- Assistant
Now I'll implement the isConnected check approach.
- Assistant
Need to navigate to the right line first.
- Assistant
Now let me apply the edit.
- Assistant
Now I need to attach
rootElementRefto the rendered element. - Assistant
I need to check how useRenderElement accepts refs.
- Assistant
Let me try differently.
- Assistant
Good — ref can be an array. Let me wire that up.
- Assistant
React may keep Suspense content in the DOM with
display: none, soisConnectedmight still be true. Let me test. - Assistant
isConnecteddoesn't work withdisplay: none. Reverting to the queueMicrotask approach that mispassed. - Assistant
Need to navigate first again.
- Assistant
Let me rewrite that section carefully.
- Assistant
Whitespace matching is being tricky — I'll use a Python script to edit the file.
- Assistant
I'll use Node instead.
- Assistant
Let me verify the file and re-run tests.
- Assistant
Let me check which tests might expect synchronous value changes.
- Assistant
Let me also verify withthe original
use()pattern from the bug report. - Assistant
I introduced typos in that test — rewriting it cleanly.
- Assistant
The
use()path still fails — likely act/timing. Let me refine that test. - Assistant
Let me carefully rewrite the test file without typos.
- Assistant
Typo in the command — fixing and re-running.
- Assistant
Let me check how similar deferred patterns are handled in this codebase.
- Assistant
queueMicrotask is already used in the codebase. Looking at that pattern and finalizing.
- Assistant
I'll remove the temporary test file and verify the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.