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
Let me explore the repository structure and understand the issue.
Assistant
Let me look at the useTransitionStatus and useOpenChangeComplete hooks, since the issue relates to PR #4704.
Assistant
Let me look at the PR #4704 to understand what changed. Let me look at git history of the relevant files.
Assistant
Let me look at the git history of TabsPanel.tsx and related files to understand what PR #4704 changed.
Assistant
Let me look at the current TabsRoot.tsx to understand the current state.
Assistant
Let me reproduce the issue first. Let me check the version and find the v1.4.1 code for comparison.
Assistant
No tags. Let me look at the git history of the panel to find the previous version. Let me look at the commit that added the transition status to panels (52dd939ab).
Assistant
Let me reproduce the issue first with a test script. Let me check how tests are set up.
Assistant
Let me write a reproduction test to confirm the issue.
Assistant
Let me create a reproduction test file.
Assistant
Let me look at the v1.4.1 version of TabsRoot (the commit before #4704) to compare.
Assistant
Let me add debugging to understand the actual state after the click and resolution.
Assistant
After the click, there are no accessible roles - meaning the entire Tabs.Root unmounted and the fallback "Loading…" is shown. So the click triggered a suspend that unwound to the Suspense boundary, showing the fallback. The tabs are gone (hidden).
So after click: fallback shown, tabs hidden. After resolve: React retries, re-renders Tabs.Root. The value... let me check after resolve. Let me make the test not fail on console.error and see the logs. Let me mock console.error.
Actually, the test failed because
getByRole('tab')threw since the tabs are unmounted (showing fallback). So I need to handle that. Let me check the body after click to see the fallback. Let me adjust the test to capture the body html directly.Assistant
Let me check the v1.4.1 version of TabsPanel to compare.
Assistant
The TabsPanel is identical between versions. The difference is purely in TabsRoot.tsx. Let me verify by temporarily reverting TabsRoot.tsx to the pre-#4704 version.
Assistant
Interesting! Even with the OLD (v1.4.1) TabsRoot.tsx, the test fails the same way. The test environment may not be flushing React's retry. Let me restore the current version and write a more realistic test that captures the second-click behavior.
Assistant
Let me check how the DialogPortal suspense test handles resolution.
Assistant
Let me model the test like the DialogPortal test using
findByTextpolling.Assistant
The retry happens but Panel B content doesn't appear. Let me check what appears instead.
Assistant
Let me check what commit #4935 ("Fix state edge cases") changed, since the current HEAD includes it.
Assistant
Let me diff the entire tabs directory between the pre-#4704 commit and HEAD to find all changes.
Assistant
Let me look at the full TabsTab.tsx, especially the registration effect.
Assistant
Let me look at
useCompositeItemto understand how tab registration works (setTabMap).Assistant
Let me check the test-utils setup to understand timer behavior.
Assistant
Let me check the shared test-utils for fake timers and BASE_UI_ANIMATIONS_DISABLED.
Assistant
BASE_UI_ANIMATIONS_DISABLED = true in tests. So
useOpenChangeCompletecallsdone()synchronously (flushSync). Let me check the setupVitest for fake timers.Assistant
Let me check the configure.js for fake timers.
Assistant
Let me try forcing a re-render after resolve to see what value the tree reverts to.
Assistant
After rerender, no tabs selected and no panel B. So the fallback is still shown (no accessible tabs). The rerender didn't help. Hmm.
Actually,
rerenderre-renders the App component, but the Suspense boundary is still suspended (it has a pending promise that's now resolved but React hasn't retried the boundary). When you rerender the same tree, React should attempt to re-render the boundary's children. Since the promise is resolved,use(promise)returns the value, no suspend, so Panel B should render.But it shows no tabs (fallback still). Weird. Let me check the body after rerender.
Actually, maybe
resolvePromiseresolved butuse(promise)— the promise was thrown during the suspended render. After resolve,useshould return the value. But maybe the promise needs to be the SAME instance and React's internal tracking... it is the same instance.Let me check the body.
Assistant
Let me write a minimal isolated test to confirm jsdom retries
use(promise)after resolution.Assistant
The retry works for prop-triggered suspend. Let me test the state-update-inside-boundary-triggered suspend case minimally.
Assistant
The state-update-triggered suspend discards the update. Let me examine the body in test2 after resolve.
Assistant
Hmm, no output. Let me check the test ran.
Assistant
My sed broke the test. Let me rewrite it cleanly.
Assistant
Let me try the browser test mode (playwright) for a realistic reproduction, since jsdom isn't flushing the React retry for state-update suspends.
Assistant
The browser test failed at startup (probably playwright browser not installed). Let me check the error head.
Assistant
Let me install playwright chromium.
Assistant
The browser test was skipped. Let me remove the skipIf condition.
Assistant
Now in a real browser, the test fails — Panel B content is NOT visible after resolving. Let me capture the full body HTML to understand the state.
Assistant
Let me query the tab selected state and visible panel text using locators instead.
Assistant
Let me write the state into the DOM as a visible element so I can read it.
Assistant
Let me make the test fail with the diag as the assertion message so it shows in the failure output.
Assistant
page.waitForTimeoutisn't a function. Let me use a plain sleep.Assistant
Browser tests run in the browser context, so I can use
documentdirectly.Assistant
The browser result shows value becomes
nullafter resolve. Let me instrument the TabsRoot effect to find when tabMap becomes empty. Let me add temporary diagnostics.Assistant
Let me add temporary instrumentation to the effect.
Assistant
That sed approach is risky. Let me revert and use the edit command properly.
Assistant
Now I have the diagnostic trace. The key issue is clear:
code{value:"b", tabMapSize:2, did:true, sel:"b"}, // click → value="b" {value:"b", tabMapSize:0, did:true}, // suspend unmounts tabs → tabMap empty {value:null, tabMapSize:2, did:true}, // effect commits value=null (REASONS.missing) {value:null, tabMapSize:2, did:true} // boundary recovers, tabs re-register, value stays nullThe
tabMap.size === 0branch commitsvalue=nullwhen the suspense transiently unmounts the tabs. Let me look at the tests added in #4704 to understand the intended behavior of themissingreason.Assistant
Let me capture the body state during the fallback (Loading visible) in the browser to understand what's mounted.
Assistant
Let me instrument the tab register/unregister and TabsRoot mount to understand the tabMap transitions. Let me find the CompositeList register.
Assistant
Let me check how TabsRoot wires
setTabMapto CompositeList'sonMapChange.Assistant
Let me instrument register/unregister in CompositeList and TabsRoot mount/unmount to understand the transitions.
Assistant
Let me add diagnostics for tab DOM node count and root connectedness at each effect run.
Assistant
Let me re-add register/unregister logging with the raw map size to determine if unregister is the cause.
Assistant
Let me add mount/unmount logging to TabsRoot to see if it unmounts during the suspense.
Assistant
My mount log had no deps array, so it ran every render. Let me fix it to detect real mount/unmount.
Assistant
Let me look at how the Dialog Portal suspense issue (#3700) was fixed, as a similar pattern might apply.
Assistant
Let me add a root ref and log the host element's connectedness at each effect run, to distinguish suspend from removal.
Assistant
Let me revert instrumentation and try changing the automatic selection effect from
useIsoLayoutEffecttouseEffectto test if timing is the issue.Assistant
The passive effect didn't help. Let me revert and check if there's a published version of base-ui in node_modules that might contain the fix.
Assistant
Let me revert and do a focused trace with a sequence counter to understand if unregister runs before the null commit.
Assistant
Let me get the full log without truncation.
Assistant
Let me maintain a global raw map size and read it in the selection effect to compare with tabMap state.
Assistant
Key finding! At the null-commit moment:
tabMapSize:0(stale state) butraw:2(tabs actually registered). The tabs are registered but their DOM is transiently disconnected, sosortedMap(which filters byisConnected) reports 0. Let me check the git history of theisConnectedfilter in CompositeList.Assistant
I now understand the root cause. At the null-commit moment:
tabMap(thesortedMap, which filters byisConnected) is stale0because the tab DOM nodes are transiently disconnected by the Suspense boundary, but the raw registered map has2entries (tabs still registered). TheisConnectedfilter inCompositeList.sortedMapdrops all nodes when the whole list is detached by a parent Suspense, causing the transient empty that triggers thecommitAutomaticValueChange(null, 'missing').Let me revert all instrumentation and implement a targeted fix in
CompositeList: keep registered nodes when the entire list is detached (don't filter to empty), so consumers don't observe a transient empty list during Suspense.Assistant
Let me implement the targeted fix in
CompositeList— keeping registered nodes (in insertion order) when the entire list is detached, so consumers don't observe a transient empty list during a parent Suspense.Assistant
Now let me test the fix in the browser:
Assistant
The "diag" test always fails by design. Let me restore the actual suspense test that verifies Panel B is rendered.
Assistant
The fix alone didn't resolve it. Let me re-run the diagnostic to see the new state.
Assistant
Let me re-add the raw map logging to check if unregister is happening with the fix.
Assistant
My CompositeList fix didn't help because the
tabMapstate is stale (the raw map is2but the state hasn't caught up). The cleanest fix is to expose the synchronous raw registered count to the selection effect. Let me look at TabsList to understand the plumbing.Assistant
Let me look at CompositeRoot which TabsList uses.
Assistant
Let me revert instrumentation and carefully test whether React unregisters the tabs during suspense (which determines the right fix). Let me apply the CompositeList fix and log raw map + sortedMap size at onMapChange.
Assistant
The
sortedMapis computed when the raw map is empty (React unregisters tabs during deactivate), but byonMapChangetime the map is repopulated (raw:2). So the raw map is the only synchronous signal. Let me revert the CompositeList fix and test whether checking the root's DOM for tabs at the null-commit works (simpler than plumbing a ref).Assistant
The grep didn't match (the log key is different). Let me check the actual log key. The test asserts
'MC'but the log is__lognot__mc. Let me fix the test assertion to read__log.Assistant
I've confirmed the root cause: at the null-commit,
tabMapSize:0(stale state) buttabsInRoot:2(tab elements still present in the DOM). ThesortedMapis computed during a transient empty window when React unregisters tabs during Suspense deactivation, but the state hasn't caught up by the time the selection effect runs.The cleanest targeted fix: in the selection effect, when
tabMapreports empty, verify tabs are actually gone from the DOM before committingnull. Let me revert all instrumentation and implement this.Assistant
Let me reconsider and look at the exact effect code to implement the fix cleanly.
Assistant
Now let me implement the fix. I'll add a
rootRefto TabsRoot and guard the empty-tabMapnull commit by checking if tab elements are actually still present in the DOM (transient Suspense state) versus truly removed.Assistant
Let me use the
editcommand instead, which handles this more cleanly. First, add therootRef:Assistant
Now wire the
rootRefinto the rendered element:Assistant
Now let me add the guard in the empty-
tabMapbranch:Assistant
There's a duplicate
}at line 306. Let me fix it:Assistant
Now let me test the browser suspense test:
Assistant
The browser suspense test now passes. Let me also test the second-click scenario and the "value persists" scenario, plus verify the existing removal tests still work.
Assistant
Let me check the actual failure detail:
Assistant
That failure is just my buggy assertion — Panel A isn't in the DOM (not
keepMounted), sogetByTextthrows (which is actually correct behavior). Let me fix the test assertion:Assistant
Both browser tests pass. Now let me clean up the temporary test files and run the existing tabs tests to make sure I haven't broken anything.
Assistant
All tabs tests pass, including the removal tests. Let me verify the CompositeList wasn't left modified and run the composite tests:
Assistant
Only TabsRoot.tsx is modified. Let me run the composite tests and the broader test suite to confirm nothing breaks:
Assistant
Let me verify the jsdom behavior with the fix (to understand if the test environment limitation still applies):
Assistant
In jsdom, the fallback still persists due to a test-environment limitation with state-update-triggered suspends (React's retry isn't flushed). Let me try flushing with
actto confirm it's just a test-env artifact:Assistant
The jsdom test-env can't reproduce this (state-update-triggered suspends don't retry in jsdom — a known testing artifact); the browser test validates the real fix. Note that with the fix, jsdom now keeps
value="a"(Panel A) instead ofnull, and the browser correctly renders Panel B. Let me clean up and review the final diff.Assistant
The diff is clean. Let me run TypeScript and lint checks on the modified file:
Assistant
TypeScript and ESLint pass. Let me run the full tabs test suite once more to confirm everything is green:
Assistant
All tests pass. Let me do a final check that no temporary files remain and verify the complete change:
Assistant
The change is complete and clean. Let me run one final broader smoke test on components that consume Tabs/composite to be safe:
Assistant
All tests pass — including the analogous Select "falls back to null when removed" tests and the Menu/Select removal behavior. The fix is complete and doesn't break any composite-based component.
Summary
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.