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
I’ll inspect the repository structure and recent Tabs-related history, then identify the v1.5 regression and its relevant tests before making a minimal fix.
- Assistant
The repository includes a later Tabs “state edge cases” commit, so I’ll compare the current implementation against the suspected #4704 change and inspect panel/root tests to determine whether the fix is already partially present or this checkout is intentionally missing the Suspense case.
- Assistant
The current root performs automatic selection correction in a layout effect. Since suspension before commit discards effect/ref state but event callbacks may retain closures from the abandoned render, I’ll isolate the selection logic and inspect exactly how #4704 moved or added state updates.
- Assistant
A likely mechanism is
useStableCallback: if it updates its callback ref during render, the still-visible Tab from the last commit can invoke a callback belonging to a suspended, uncommitted Root render. I’ll inspect that utility and the tab event path, then reproduce the exact interaction in the existing browser test harness. - Assistant
Because ripgrep is unavailable, I’ll use
grepto locate the utility and prior Suspense test patterns. I’ll also inspect commit descendants/branches for an upstream fix matching this reported regression, which can clarify the intended minimal change. - Assistant
I’ll read
useStableCallbackand its React-version behavior. The key question is whether introducing the newnotifyAutomaticValueChangestable callback shifted hook identity/order or caused a render-phase ref mutation that redirects the first click’s update into an abandoned render. - Assistant
The regression is now clear in #4704: it added an automatic
nullselection whenever the registered tab map becomes empty. When an outer Suspense boundary hides the entire Root, React detaches all refs, making that map transiently empty; the layout effect then mistakes this for removal of every tab and clears"b".I’ll build an external temporary reproduction (not a repository test), verify this state transition, and inspect the composite registration timing. Then I’ll guard the “all tabs removed” fallback based on whether the Root itself remains mounted—unlike genuine child removal, outer Suspense also clears the Root ref.
- Assistant
pnpm execattempted an interactive Corepack download, which this environment disallows. The temporary script was created successfully, so I’ll run the already-installed localtsxbinary directly. - Assistant
The runner treats
/tmpas CommonJS, so I’ll wrap the reproduction in an async function and rerun it. - Assistant
Python is also unavailable; I’ll use standard shell tools to wrap the script.
- Assistant
The original file appears to have been partially altered despite the missing Python command (likely the shell redirection occurred before command failure). I’ll inspect and normalize it once, then run.
- Assistant
The static JSDOM import must remain top-level. I’ll place only the executable body inside
main. - Assistant
Node resolves dependencies relative to the script location, so I’ll briefly place the reproduction at the repository root (not in the test suite), execute it, and remove it immediately afterward.
- Assistant
Node 24 exposes a read-only global
navigator; it is unnecessary for this reproduction, so I’ll omit that assignment and rerun. - Assistant
Tabs transitions require animation-frame globals in JSDOM. I’ll add minimal timer-backed shims and run again.
- Assistant
The reproduction exactly matches the report: after resolution neither tab is selected and Panel B is absent, confirming that the empty-map fallback changed the value to
null. I’ll implement the narrow distinction: retain the existing “all tabs genuinely removed” behavior only when the Root host element is still mounted; if its own ref is detached by Suspense, ignore the transient empty map. Then I’ll rerun the same reproduction and targeted Tabs tests. - Assistant
I’ll add an internal host ref near the other Root refs, include it in
useRenderElement, and document why an empty tab map is ignored while Suspense has detached the Root. - Assistant
The first line-based edit replaced the start of the
mountedTabPanelsdeclaration and duplicatedtabPanelRefs; I caught this in review. I’ll restore that block correctly and wire the internal ref alongside the forwarded ref. - Assistant
The state block is restored. The replacement helper did not apply the ref change despite locating it, so I’ll update the exact current line and then execute the reproduction against the fix.
- Assistant
The host ref remains attached while React hides the subtree (
display: none !important), so ref nullness is not a reliable React 19 signal. I’ll inspectCompositeListto determine why the map empties, and instrument the temporary reproduction to observe the Root element’s exact state when the fallback logic runs. This will avoid relying on assumptions about ref cleanup. - Assistant
CompositeListdoes not unregister the tabs; it filters out nodes whoseisConnectedis false. That gives the robust signal: during outer Suspense, the entire Root is disconnected at the moment the map is computed, whereas genuine removal leaves the Root connected. I’ll verifyrootElementRef.current.isConnectedat the fallback branch with temporary instrumentation, then use that condition. - Assistant
The instrumentation reveals a subtler sequence: the Root is already reconnected when the stale empty map effect runs after Suspense resolves. The composite map was emptied while nodes were disconnected, then Root’s automatic fallback effect runs before registration catches up.
A robust distinction is to retain the last non-empty tab map and, when a later map is empty, check whether any previously registered tab element is still contained by the Root. Suspense preserves/reveals those same nodes; genuine tab removal does not. I’ll inspect tests for all-tabs removal to preserve that behavior, then implement this identity-based guard.
- Assistant
I’ll read those exact tests to ensure the retained-map check does not alter expected callback timing or behavior.
- Assistant
The genuine removal test removes the old tab node from the Root before the fallback effect, so containment will be false and the existing
nullcallback remains unchanged. I’ll replace the ineffective null-ref guard with a last-nonempty-map containment check and rerun both the reproduction and this targeted test file. - Assistant
Review caught one leftover line from the prior comment and a missing blank line after the new ref. I’ll clean those, then run the exact reproduction.
- Assistant
The reproduction now resolves to “Panel B” on the first click with B selected. One comment line was duplicated by the line editor, so I’ll remove it and run the full Tabs Root and Panel test files in JSDOM using the installed Vitest binary.
- Assistant
All 146 targeted tests pass (118 active, 28 environment-skipped), including the existing “selected tab removed and no tabs remain” case. I’ll now run formatting, lint, and TypeScript checks on the changed source, and inspect the final diff for accidental files or instrumentation.
- Assistant
Formatting, ESLint, TypeScript, and diff checks all pass; only
TabsRoot.tsxis modified. Since the bug is browser-specific in the report, I’ll also run the two targeted suites in Chromium to validate real DOM/Suspense behavior before submission. - Assistant
Chromium tests could not start because the environment lacks the Playwright browser executable; this is an environment limitation, not a test failure. The same React 19 Suspense sequence was reproduced and fixed in JSDOM, and all targeted suites passed there.
Checklist:
- Successfully reproduced the reported error: Yes. The external temporary script showed first-click suspension resolving with neither tab selected and Panel B absent.
- Confirmed the fix resolves the error: Yes. The same script now resolves on the first click with Tab B selected and “Panel B” rendered.
- Considered edge cases: Yes. The fix distinguishes retained Suspense DOM nodes from genuinely removed tabs by identity/containment, preserving automatic
nullselection when all tabs are actually removed. - Ran affected existing tests: Yes. Tabs Root and Panel suites passed in JSDOM (118 passed, 28 skipped), including all-tab removal. Formatting, ESLint, TypeScript, and diff checks passed. Chromium execution was attempted but unavailable because Playwright’s Chromium binary is not installed.
I’ll verify the final status once more and submit the single-file change.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.