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 locating the Tabs component implementation to understand the bug.
- Assistant
Let me find the Tabs source and the related PR changes.
- Assistant
There's a fix for state edge cases (#4935) and the PR mentioned (#4704). Let me look at the tabs source code and the changes.
- Assistant
Let me examine the Tabs root and panel components in detail.
- Assistant
Let me read the panel and root components.
- Assistant
Let me see the rest of the file.
- Assistant
Now let me examine TabsRoot and how mounted panels are tracked.
- Assistant
Let me continue reading the file to understand mounted panels logic.
- Assistant
Let me continue reading the automatic selection logic and context.
- Assistant
Let me keep reading the selection and fallback logic.
- Assistant
Let me inspect
useTransitionStatuswhich controls panel mounting: - Assistant
rg not found, use grep.
- Assistant
Let me compare the panel registration logic between versions and check related issues.
- Assistant
Let me look at the diff between 1.4.1 and current for tabs panel/root. Also search github issues for related issues.
- Assistant
Let me inspect the key logical changes in PR #4704 that may have introduced this bug.
- Assistant
Let me check how tab selection is triggered — it might use transitions which matter for Suspense.
- Assistant
Let me look at onTabActivation and TabsList.
- Assistant
Let me look at TabsList onTabActivation
- Assistant
Need to use goto or just open file.
- Assistant
I'll create a repro app to understand the failure, and also review TabsPanel tests.
- Assistant
Let me dig into CompositeList and how tabMap is updated on unmount.
- Assistant
I'll reproduce the bug with a focused unit test.
- Assistant
Let me look for existing suspense-related tests in the codebase for OCR of how they test it.
- Assistant
There's a Dialog Suspense integration test — I'll use that as a guide and also check for related issues.
- Assistant
I'll write a temporary test that reproduces the reported suspense issue.
- Assistant
I'll run the temporary repro test once, then remove it so it isn't left in the repo.
- Assistant
The previous command timed out — trying a more direct vitest run.
- Assistant
Hmm the background job got stopped. Let me try a different approach.
- Assistant
Vitest seems to hang. Let me check if there's an issue with the environment.
- Assistant
Corepack is prompting for input, which hangs the run — I'll use the local pnpm directly instead.
- Assistant
Need to set COREPACK_ENABLE_DOWNLOAD_PROMPT=0 or use npm_config_yes
- Assistant
The test hung on loading; I'll refine the repro to capture console errors and check continue after resolve.
- Assistant
Let me pull the body HTML logs from the test output.
- Assistant
I'll check for open PRs or issues that already address this tabs/suspense bug.
- Assistant
Let me compare TabsPanel between v1.4.1 and now to find the behavioral change.
- Assistant
Maybe tags aren't available locally.
- Assistant
I'll switch the repro to React.lazy, matching the working Dialog Suspense test.
- Assistant
That matches the #4704 fallacy path that zeros out
value. Let me inspect CompositeList and that empty-map effect next. - Assistant
Interesting - sortedMap filters
node.isConnected. When Suspense setsdisplay: none !importanton the root - children should still be connected... - Assistant
Let me inspect tests for the "tabMap empty → null" behavior and refine the repro logging.
- Assistant
I'll read the relevant TabsRoot tests around null selection and tab removal.
- Assistant
Let me read the test about when selected tab is removed and no tabs remain, and when tabs come back.
- Assistant
Let me inspect the register/unregister logic in the composite list item.
- Assistant
I'll instrument the empty-tabMap path to confirm it's firing during Suspense.
- Assistant
Let me add debug logging temporarily and re-run the test.
- Assistant
Let me also log selectionIsMissing path and run the test.
- Assistant
Confirmed: tabMap briefly empties after a successful selection and wipes the value. I'll debounce the empty-map → null transition.
- Assistant
I'll implement a deferred empty-tabMap nulling so brief Suspense/Offscreen unregisters don't clear the value.
- Assistant
Checking whether Tabs tests use fake timers — that could affect a deferred fix.
- Assistant
Implementing the deferred empty-map handling in TabsRoot.
- Assistant
I made a ty po — fixing the edit.
- Assistant
Now I'll update the automatic value-change-effect to defer empty tabMap nulling.
- Assistant
I'll replace the sections to add timeout and defer empty map handling.
- Assistant
The replace needs an exact match — I'll move to the right place and try a smaller edit.
- Assistant
I'll rewrite that section with a Python script for a cleaner edit.
- Assistant
No python3? Try python or node.
- Assistant
Now let me run the repro test to see if the fix works.
- Assistant
Suspense case det is fixed. Next I'll run the existing TabsRoot tests for regressions.
- Assistant
All 103 tests passed. Cleaning up the temporary files and running the remaining tabs tests.
- Assistant
I'll quickly verify withsince the original
React.use()reproduction too. - Assistant
The lazy repro already covers this. Cleaning up any leftover test files.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.