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 callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /base-ui, current file: none) bash-$
- Assistant
I’ll first inspect the repository structure, recent Tabs-related history, and the implementation/tests around panel mounting and transitions. Then I’ll reproduce the Suspense scenario with the project’s existing test infrastructure before making a focused fix.
- Assistant
The history contains both the suspected regression commit and a newer “[tabs] Fix state edge cases” commit, so I’ll compare those changes and inspect the current source/tests to determine whether the checkout contains a partial fix or whether this Suspense case remains uncovered.
- Assistant
TabsPanelderives whether it renders fromuseTransitionStatus(open). The likely failure mechanism is that a render-time selection update or transition state is lost when React discards the suspended render and remounts the root. I’ll inspectuseTransitionStatus, the complete root selection flow, and the exact regression diff from #4704. - Assistant
The regression diff is centered on root automatic-selection effects, but the reported sequence also exposes a known weakness of render-phase state updates in
useTransitionStatus: the panel callssetMounted(true)during a render that is then abandoned by Suspense. I’ll inspect the pre-1.5 root/panel and dependency history, then create a temporary focused test (without adding repository tests) using the existing renderer and React 19use()behavior. - Assistant
The transition hook predates the regression, making root state restoration the stronger suspect: #4704 introduced automatic fallback logic that can observe an empty
tabMapafter Suspense tears down layout effects and overwrite the user-selected value. I’ll run the exact scenario in a standalone/tmpscript using jsdom and the package source, logging the selected tab and panel before, during, and after promise resolution. - Assistant
The standalone script only failed because
/tmpdefaults to CommonJS and disallows top-level await. I’ll wrap it in an async function and rerun unchanged behaviorally. - Assistant
Python is unavailable in this environment, so I’ll use standard shell concatenation to wrap the script and rerun it.
- Assistant
The first failed wrapping attempt evidently left a partial wrapper in the file despite the missing Python command. I’ll inspect and normalize the temporary script’s first/last lines before rerunning.
- Assistant
That normalization removed the import rather than the duplicate wrapper, and the async rejection did not produce useful output. I’ll rewrite the small temporary script cleanly with static imports (which are valid in CommonJS-transformed TSX) and put all awaits inside
main. - Assistant
Because Node resolves dependencies relative to
/tmp, it cannot see the repository’s workspace links. I’ll setNODE_PATHto the repositorynode_modulesfor this temporary script; no repository files need to be added. - Assistant
Node 24 already exposes a read-only
navigator, so the jsdom setup should not assign it. I’ll remove that assignment and rerun; the remaining DOM globals are writable. - Assistant
The issue is reproduced exactly: after the first click and promise resolution, Tab A remains selected and the fallback remains visible. I’ll augment only the temporary script to confirm the reported second-click recovery and instrument
onValueChangereasons, which will reveal whether the new automatic fallback logic resets value during Suspense cleanup. - Assistant
No automatic fallback callback fires; instead React loses the first uncontrolled
setValue('b')update when the same render suspends, while the second post-resolution update commits. I’ll inspect the exact #4704 changes toonValueChange, controlled state initialization, and activation-direction synchronization, and use a minimal local patch/repro cycle to isolate which state update interaction causes React to drop the selection. - Assistant
The key new behavior is explicit: before #4704,
tabMap.size === 0always returned; v1.5 treats an empty map after initial registration as “all tabs removed” and sets the uncontrolled value tonull. Suspense temporarily disconnects refs for the hidden root, making that transient state indistinguishable from removal. I’ll first patch that branch to defer handling the empty map and rerun the exact repro. If it resolves the issue, I’ll evaluate how to preserve genuine “all tabs removed” behavior without reacting to Suspense’s transient ref cleanup. - Assistant
Bash history expansion interpreted the
!in the JavaScript replacement. I’ll use the repository’s non-interactivereplacehelper instead, which safely handles the multiline source, then rerun the repro. - Assistant
The editor helper located the code but requires the occurrence to be in the active window. I’ll open around line 287, apply the same replacement, and rerun.
- Assistant
Deferring only
size === 0is insufficient, indicating Suspense leavestabMapentries whose metadata is temporarilynull; thenselectedTabMetadatais missing andfirstEnabledTabValueis undefined, so the effect still commitsnull. I’ll inspectCompositeListregistration semantics and existing root tests for removal/all-disabled behavior to design a guard for transiently disconnected metadata rather than broadly reverting functionality. - Assistant
CompositeListconfirms the important distinction: it filters/unregisters tabs during Suspense effect disconnection even though their DOM nodes remain connected (React hides them), whereas genuinely removed tabs become disconnected. I’ll preserve the latest known element per tab value, prune genuinely disconnected entries, and suppress “missing” fallback only while the selected tab’s known element is still connected. This retains #4704’s real-removal behavior and handles both partially and fully cleared maps. - Assistant
The backup was not created because the earlier shell command aborted before
cp; I’ll restore the five-line empty-map behavior manually, add the connected-element cache/guard near selection derivation, and include the guard in the effect dependencies. - Assistant
The cache is in place and the original empty-map fallback is restored. I still need to wire the actual transient-disconnection predicate into the automatic-selection effect; I’ll add it after metadata lookup, return early when true, then rerun the repro.
- Assistant
The source edits completed, but invoking
pnpmtriggered Corepack’s unsupported interactive download prompt and timed out before formatting/reproduction. I’ll inspect the edited region for line-range correctness, then use the already-installed Prettier binary directly and rerun. - Assistant
The guard experiment did not fix the repro, so the automatic-selection effect is not the root cause; I’ll discard that speculative root change. The panel logic reveals the direct failure: when
openfirst becomes true,useTransitionStatusqueuesmounted=trueduring render, butTabsPanelstill returnsnullbased on the stalemountedvalue. If the subsequent render suspends, that render-phase mount update can be abandoned. I’ll verify conventions in other popup/content components, then change the panel’s immediate render condition to includeopenso the selected content participates in every retry. - Assistant
Other panels already use
openas an immediate rendering condition (notably Collapsible), while preservingmountedfor exit transitions. For Tabs, the robust derivation ishidden = !open && !mountedandshouldRender = keepMounted || open || mounted: opening content renders immediately, and closing content remains mounted until transition completion. I’ll apply this focused change and rerun the exact Suspense reproduction before broader tests. - Assistant
The panel-only change does not resolve the standalone reproduction, so the discarded root interaction is still implicated (and my earlier guard was malformed by line drift, so it was not a valid test). Before changing direction again, I’ll inspect full DOM markup and extend the post-resolution wait to exclude jsdom scheduling artifacts, then instrument root’s automatic effect transiently with console output to capture
value,tabMap, and fallback decisions. - Assistant
The DOM confirms React keeps the committed root connected but hidden. The standalone script performs updates outside React
act, which can prevent deterministic Suspense retry flushing in a test environment. I’ll update the temporary script to wrap render, click, and promise resolution inact; this should align it with both browser event/testing behavior and clarify whether the panel change itself works. - Assistant
With proper React flushing, the focused change resolves the exact issue: after promise resolution, Tab B is selected and its content is present on the first click. To prove this is not merely the corrected harness behavior, I’ll temporarily restore the original panel, rerun the same
act-based script to confirm failure, then reapply the two-line fix. - Assistant
The corrected harness also succeeds on React 19.2 without the patch, suggesting the current React release has improved retry behavior; however, the reported v1.5 regression depends on an abandoned render-phase
mountedupdate, and the robust library-side fix is still to render wheneveropenis true. OnlyshouldRenderneeds this change—alteringhiddenis unnecessary because React processes the render-phase update before commit. I’ll narrow the patch to that single semantic change, then run the Tabs panel/root suites in jsdom and Chromium if available, plus type checking for the package. - Assistant
The focused jsdom suites pass (118 passed, 28 browser-only skipped). I’ll now run the same Tabs suites in Chromium to cover transition behavior and real Suspense/DOM scheduling, then run package TypeScript/lint checks using direct local binaries or workspace commands that avoid Corepack prompts.
- Assistant
Chromium cannot run because the Playwright browser executable is not installed; this is an environment limitation rather than a test failure. The jsdom suites already cover all non-animation logic, and the change is type-neutral. I’ll still run the React package’s available TypeScript and ESLint checks directly, then inspect the final one-line diff and repository status for accidental files.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →