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
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me explore the packages directory, particularly the tabs component.
Assistant
Now let me look at the TabsRoot.tsx and the related context/hooks.
Assistant
Let me look at the
useTransitionStatusanduseOpenChangeCompletehooks.Assistant
Let me look at the git history and the PR #4704 that's mentioned as the likely cause.
Assistant
Let me look at the test file to understand testing conventions.
Assistant
Let me search for any existing suspense-related tests in the codebase to understand the test setup.
Assistant
Let me reproduce the issue by creating a test script. First, let me understand the renderer setup.
Assistant
Now let me create a temporary test to reproduce the issue.
Assistant
I reproduced the issue. The DOM shows Panel A content and "Loading…" together after resolving. Let me investigate the React Suspense behavior more closely. Let me check the v1.4.1 version of the code for comparison.
Assistant
The TabsPanel is identical. Let me compare TabsRoot between v1.4.1 and current.
Assistant
Now I can see the key difference. Let me write a more diagnostic test to understand the React Suspense state preservation behavior.
Assistant
Wait, in my test I made it controlled (value={val} onValueChange={setVal}). But the issue uses uncontrolled (defaultValue). Let me keep it uncontrolled to match the issue, but add logging via the Root wrapper that doesn't make it controlled. Actually, let me reconsider.
Actually, let me make it uncontrolled to match the issue exactly. Let me remove the controlled part.
Assistant
Let me get the full DOM structure and understand React's behavior better with diagnostics.
Assistant
Now I understand the React behavior. The suspended subtree's previous content is kept hidden (
display: none) while the fallback shows. Let me test the baseline React behavior with a simple example to understand state reversion.Assistant
I have a syntax error (trailing comma in JSX). Let me fix it.
Assistant
The pure React test shows the state stays "b" but content stays hidden — this is a test artifact with act. But the key difference: in my pure test, the
tabstate is held byAppwhich is ABOVE the Suspense boundary. In the Tabs case, thevaluestate is held byTabs.Rootwhich is INSIDE the boundary. Let me test this crucial difference.Assistant
The act/suspense flushing is interfering with my tests. Let me check the React version and look at how existing async tests handle this.
Assistant
React 19.2.5. Let me work around the act warning by suppressing console.error and using longer polling, to see if the bug is genuinely reproducible or a test artifact.
Assistant
The bug reproduces with Tabs. Now let me verify whether pure React (state inside boundary) works or also fails, to confirm it's a Tabs-specific bug and not a test artifact.
Assistant
The pure React case also fails in the test environment, suggesting the test env can't flush state-update-triggered suspense retries. Let me verify whether the test env can flush suspense triggered on initial render (like the DialogPortal test).
Assistant
The test env can flush initial-render suspense but not state-update-triggered suspense. Let me look at the CHANGELOG and search for any related fix or discussion.
Assistant
Let me check if the test renderer uses fake timers, which could affect suspense retry flushing.
Assistant
No fake timers.
BASE_UI_ANIMATIONS_DISABLED = true. requestAnimationFrame is mapped to setTimeout.Let me look at the
setupVitestfrom mui internal-test-utils to see if it sets fake timers.Assistant
Let me definitively understand React's behavior by examining the React source code for state updates that cause suspension.
Assistant
The React source is heavily transformed. Let me take a more direct approach: temporarily revert the #4704 effect changes to confirm they're the cause. Let me first save my repro test, then experiment.
Assistant
Let me try swapping in the v1.4.1 TabsRoot to confirm #4704 is the cause.
Assistant
The test env fails for both v1.4.1 and v1.5.0 — confirming it's a test artifact, not the real bug. Let me restore the current TabsRoot and find a different reproduction approach.
Assistant
Let me check if there are any branches or later commits that might contain the fix.
Assistant
Let me look at the React source to understand whether state updates that cause suspension are rolled back.
Assistant
Let me try resolving the promise within the same act as the click, which may let React flush the retry properly.
Assistant
Very interesting! With same-act resolution, the value became
null— both tabs unselected, no panels. This points to #4704'scommitAutomaticValueChange(null, REASONS.missing). Let me test v1.4.1's TabsRoot with this same-act scenario to confirm.Assistant
Confirmed! v1.4.1 renders Panel B correctly; v1.5.0 sets value to
null(both tabs unselected, no panels). I now have a reproducible test. Let me instrument the #4704 effect to see exactly which branch sets value tonull.Assistant
Let me add temporary instrumentation to the effect to trace which branch fires during the suspense retry.
Assistant
No python. Let me use the edit command to add instrumentation.
Assistant
I found the root cause. During the suspense retry,
tabMaptransiently becomes empty (tabs unregister then re-register), and thetabMap.size === 0branch firescommitAutomaticValueChange(null, REASONS.missing), setting value tonull. v1.4.1 just returned early whentabMap.size === 0. Let me look at the tests #4704 added for the "all tabs removed" behavior.Assistant
Let me look at how tabs register/unregister into
tabMapto understand the mechanism.Assistant
Let me see how
setTabMapis wired — theonMapChangecallback.Assistant
Let me see the full
useCompositeListItemto understand the registration lifecycle.Assistant
Let me check how
setTabMapis wired to the CompositeList and add instrumentation there.Assistant
tabMapis thesortedMap(filtered byisConnected). Let me add instrumentation to log whensetTabMapis called and with what size, to understand the transient.Assistant
This is getting messy. Let me restore and add cleaner instrumentation.
Assistant
Now let me add a clean log to the
onMapChange/setTabMappath. Let me modify the TabsList to log onMapChange, OR wrap setTabMap cleanly. Let me wrap setTabMap in TabsRoot with a stable callback but keep the name.Actually, the issue is the context type expects
setTabMapof a certain type. Let me just add logging via a wrapped function with the same signature.Assistant
Let me add logging to the
register/unregisterin CompositeList to confirm the unregister mechanism during the retry.Assistant
Let me look at how the Dialog suspense issue (#3700) was fixed, as it may provide a pattern.
Assistant
Let me restore the clean files first, then experiment with fixes.
Assistant
Let me run the existing TabsRoot tests to establish a baseline.
Assistant
Let me check if the codebase has visibility-checking utilities, and look at how the
rootRefcould be accessed.Assistant
Let me re-add register/unregister instrumentation and run the genuine "all tabs removed" test to compare
isConnectedvalues.Assistant
I now have a clear understanding. The root cause: during Suspense, the tab registrations are torn down (effects cleanup) while the tab DOM nodes remain connected (hidden via
display:none). ThetabMap.size === 0branch then incorrectly firescommitAutomaticValueChange(null, 'missing').The robust fix: when
tabMapis empty, check if the previously-registered tab nodes are still connected to the DOM. If they are (Suspense hide), preserve the value; if they're disconnected (genuine removal), fire the null fallback.Let me view the current code and implement.
Assistant
Now let me implement the fix. First, add a ref to track the last known tab DOM nodes:
Assistant
The fix looks good. Let me run the repro test (same-act scenario) to verify the bug is fixed.
Assistant
The bug is fixed — Panel B is now rendered. Now let me run the full TabsRoot test suite to ensure I didn't break the "all tabs removed" feature or anything else.
Assistant
All TabsRoot tests pass. Let me run the broader tabs test suite (panel, tab, list, indicator).
Assistant
All tabs tests pass. Let me also test the exact issue scenario (click, wait for Loading, resolve, check Panel B) to see if my fix also helps there.
Assistant
Let me see the full DOM to understand the state in this scenario.
Assistant
The "click -> loading -> resolve" flow fails due to the test env's inability to flush state-update-triggered suspense retries (a test artifact affecting even pure React, as I confirmed earlier). The same-act scenario — which properly flushes — passes with my fix, faithfully reproducing the bug mechanism (the
nullfallback firing during the Suspense hide).Let me verify there's no leftover instrumentation in TabsRoot and confirm the diff is clean.
Assistant
Clean diff — only TabsRoot.tsx changed (19 insertions), no instrumentation left. Let me view the final diff.
Assistant
My fix is validated. The "click -> loading -> resolve" flow fails only due to the test env's act-rollback for unawaited state-update-triggered suspensions (which I confirmed affects even pure React). The same-act scenario — which faithfully flushes and reproduces the bug mechanism — passes.
Now let me remove my temporary repro test (per instructions, I must not add tests) and run the full tabs suite once more to confirm everything passes.
Assistant
All tabs tests pass. Let me specifically run the #4704 feature tests to confirm the automatic-selection behavior is fully preserved.
Assistant
All 23 onValueChange tests pass — the #4704 feature is fully preserved. Let me run a TypeScript check to ensure no type errors.
Assistant
These TS6305 errors are pre-existing build-artifact issues unrelated to my change. Let me check specifically for errors in the tabs files and get the real tsc exit code.
Assistant
No non-TS6305 errors — my change is type-correct (TS6305 are pre-existing stale-build artifacts). Let me verify the
tabMapkey type to make sure mySet<Element>declaration matches, to be safe.Assistant
The types are fine (tsc confirmed no errors;
Map/Setmethods are bivariant). For precision and consistency withtabMap's declaredMap<Node, ...>key type, let me useSet<Node>instead ofSet<Element>.Assistant
The
replaceis the editor command operating on the open file. Let me use it correctly.Assistant
Now let me re-add the temporary repro test to confirm the fix still works after the type refinement, run it, then remove it and run the full tabs suite.
Assistant
Everything passes. Let me remove the temporary repro test and verify the final state.
Assistant
The diff is clean. Let me run the linter on the modified file to ensure no lint issues.
Assistant
No lint errors. Let me verify prettier formatting on the file.
Assistant
Prettier found formatting issues. Let me see the diff prettier would make, then apply it.
Assistant
Prettier reformatted the
.some()callback to one line. Let me verify the final diff and run the tests once more.Assistant
The diff is clean and prettier-formatted. Let me run the full tabs test suite one final time to confirm everything passes.
Assistant
All tests pass, ESLint clean, Prettier formatted. Let me do a final check for any leftover temporary files and confirm the final state.
Assistant
The state is clean — only
TabsRoot.tsxis modified, no leftover temp files. Let me do a final review of the complete modified effect.Assistant
The fix is complete and correct. Let me do one final full run of the tabs suite to confirm stability, plus a quick run of the composite list tests (since tabs depend on them) to be thorough.
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 →