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-related code to understand the bug.
- Assistant
The issue mentions PR #4704 as a potential cause — I'll inspect the Tabs implementation and that change next.
- Assistant
Let me look at the git history for TabsPanel and the PR 4704 changes.
- Assistant
There's also a commit
[tabs] Fix state edge cases (#4935)which might already be related. Let me look at the TabsPanel and TabsRoot components, as well as the PR 4704 changes. - Assistant
Let me read the TabsRoot and TabsPanel components carefully.
- Assistant
Let me read more of the TabsRoot file, especially the mountedTabPanels logic.
- Assistant
Let me continue reading TabsRoot and also TabsPanel.
- Assistant
Let me read the rest of TabsPanel.tsx
- Assistant
I'll inspect
useTransitionStatusnext — that likely holds the mounted-state logic tied to this bug. - Assistant
I'll compare the pre- and post-#4704 Tabs implementations to pinpoint what introduced the bug.
- Assistant
I'll check how TabsPanel registration and mounted state changed between the two versions.
- Assistant
Let me compare TabsPanel between v1.4.1 and current.
- Assistant
I'll dig through recent Tab-related fix attempts and any Suspense-specific discussion.
- Assistant
I'll try reproducing the issue with a focused test, and review how Dialog handled its Suspense bug.
- Assistant
I'll browse existing different patterns and zonk up a small reproduction to observe how it behaves.
- Assistant
I'll write a temporary reproduction test to confirm the bug and inspect its behavior.
- Assistant
I'll establish a temporary test to reproduce the reported Suspense+tabs behavior.
- Assistant
Let me find the test command.
- Assistant
Running the jsdom unit test for the repro next.
- Assistant
The test timed out—I'll try invoking vitest directly instead.
- Assistant
Need to use pnpm exec or npx with the full path
- Assistant
Vitest seems to hang. Let me check if there's something wrong with how tests are run.
- Assistant
Corepack is prompting for confirmation — I'll enable it first.
- Assistant
Good, now let's run the test.
- Assistant
I'll check whether Tabs wraps selection updates in startTransition.
- Assistant
Let me look at onTabActivation and TabsList
- Assistant
I'll go back carefully through TabsRoot.tsx and focus on selection and mount registration.
- Assistant
I'll read the rest of that effect and check how CompositeList interacts with Suspense.
- Assistant
I'll refine the reproduction: switch to React.lazy and add more logging to isolate the failure.
- Assistant
I'll inspect CompositeList and how tabs register into tabMap.
- Assistant
Let me look at CompositeList when it cleans up on unmount.
- Assistant
Let me see the onMapChange effect and cleanup
- Assistant
I'll check TabsRoot's render output and how TabsList is structured.
- Assistant
Need to open TabsRoot again.
- Assistant
I'll inspect tests covering tabMap emptying and the null fallback path.
- Assistant
I'll add debug logging to pinpoint when value collapses to null.
- Assistant
I'll check Whether the null-when-empty behavior and tests landed in #4704.
- Assistant
I'll instrument the empty-tabMap path to log when it's hit and whether the root is still connected.
- Assistant
Need to navigate to that line first or use sed.
- Assistant
I'll try skipping the null commit to verify whether that fixes the uncontrolled case.
- Assistant
Running the repro with this change to checkPDF the uncontrolled case.
- Assistant
Suspense is fixed. Next I'll run the existing Tabs tests to see what the null-fallback change broke.
- Assistant
During Suspense React // hides the primary tree with
display: none, so I can use that signal to skip the null fallback. - Assistant
Let me find useRenderElement
- Assistant
Looking at TabsRoot, useRenderElement accepts ref: forwardedRef. I can pass a local ref as well like TabsPanel does with an array.
- Assistant
I'll restore empty-map nulling via a passive effect so Suspense resume can re-register tabsistern first.
- Assistant
Need to navigate to line 287 first for the replace to work on displayed content - orignal use edit with line numbers.
- Assistant
Let me replace the section carefully.
- Assistant
I'll run the Suspense repro and the TabsRoot tests with this version of the fix.
- Assistant
Passive still misfires under Suspense. I'll base the null fallback on whether the root is_hidden via
display: none. - Assistant
Need to goto the right line.
- Assistant
Let me rewrite the whole section properly. I'll put empty-map null handling back in the layout effect, but skip when the root is hidden by Suspense (display:none).
- Assistant
The replace tool seems to only work on displayed lines. Let me goto 287 first.
- Assistant
I introduced typos in that edit — I'll restore the section from git and apply a clean fix.
- Assistant
I'll check the resume path more carefully with logging before choosing the final approach.
- Assistant
I need to add rootRef before_it's used.
- Assistant
I'll move
rootRefabove the effect so it's declared before use. - Assistant
I have a typo again. let me fix it.
- Assistant
Good. Now run the suspense_repro to see the logs.
- Assistant
I'll inspect how list items register and unregisterin layout.
- Assistant
I'll try a different deferred strategy: keep the selection on empty map and only fallmatory back if it stays empty after another layout pass.
- Assistant
Typo in the command.
- Assistant
I'll implement a deferred empty-map fallback via rAF so Suspense can re-register tabs first.
- Assistant
I need to clean up typos and make sure the layout effect always returns a cleanup consistently.
- Assistant
Running the Suspence_repro and TabsRoot tests next.
- Assistant
All tests總passed. I'll switch to the project's AnimationFrame helper if it exists and remove the temporary repro.
- Assistant
I'll switch to the AnimationFrame helper for better fake-timersupport.
- Assistant
Let me update the import and use AnimationFrame.request/cancel.
- Assistant
Now replace requestAnimationFrame with AnimationFrame
- Assistant
Let me replace rAF with AnimationFrame
- Assistant
There's an extra
}on line 317. Let me remove and fix. - Assistant
There's a duplicate line. Remove it.
- Assistant
Good. Let me also verify the refs section at the top of the effect area is clean.
- Assistant
Removing the temporary repro and re-running_all tabs tests.
- Assistant
I'll quickly verify_the original
React瞬.usecase from the_issue as well. - Assistant
python3 not found. Let me use node or cat.
- Assistant
I'll review the final diff and гр run tests one last time.
- Assistant
There's a character typo. Let me re-run the as tests properly.
- Assistant
Bad command due to autocorrect. Let me fix.
- Assistant
I'll re-verify with the exact issue scenario one more time.
- Assistant
Cleaning up any leftover temp files, then submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.