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 understanding the Tabs component implementation.
Assistant
I'll explore the repository structure first.
Assistant
Let me look at the key files for the Tabscomponent.
Assistant
Now let me look at the TabsPanel component.
Assistant
Let me look at the
useTransitionStatusanduseOpenChangeCompletehooks.Assistant
Now let me look at the PR #4704 that's mentioned as potentially causing this issue. Let me check the git history.
Assistant
Let me look at the PR #4704 changes:
Assistant
Let me look at the more recent tabs commit too:
Assistant
Let me look at the TabsRootContext and the test setup to understand how to reproduce this:
Assistant
Let me write a reproduction test to understand the issue. First, let me look at the existing test file to understand the test patterns:
Assistant
Let me create a reproduction test to confirm the issue:
Assistant
Need to build the utils package. Let me check how the build works:
Assistant
The
@base-ui/utilspackage points toutils/buildwhich doesn't exist. Let me build the utils package:Assistant
Now let me run the test:
Assistant
The setupVitest is at the root level and references
@base-ui/utils/error. The error is about the@base-ui/utils/errorimport. Let me check the build output:Assistant
The build looks good. The issue is that the symlink
node_modules/@base-ui/utils -> ../../../utils/buildis set up at thepackages/reactlevel, but the setupVitest.ts is at the root, which uses rootnode_modules. Let me check the root node_modules:Assistant
Let me try running an existing test to see if the environment is set up correctly:
Assistant
The root test setup uses
@base-ui/utils/errorwhich needs to be resolvable from the root. The rootnode_modules/@base-uionly hasmonorepo-tests. Theutilspackage is symlinked atpackages/react/node_modules/@base-ui/utilsbut not at the root.Wait, but the setupVitest.ts uses
@base-ui/utils/error. This means the tests probably need a build of utils at the root level. Let me check the pnpm workspace to understand the package linking. Maybe the utils package'ssrcis what should be resolved, since the source package.json exports./*": "./src/*.ts".Actually, let me re-check. The
packages/utils/package.jsonexports./*": "./src/*.ts". But the symlink inpackages/react/node_modules/@base-ui/utilspoints to../../../utils/build.The setup file at root resolves
@base-ui/utilsfrom root node_modules. Since pnpm is used, packages should be linked. Let me check pnpm-workspace and the actual linking.Assistant
So the root
node_modules/@base-uidoesn't have theutilssymlink. Thetestpackage is a workspace package and the setupVitest.ts is run from the root. Let me look at the test package's dependencies.Assistant
So the
testpackage'snode_modules/@base-ui/utilspoints to../../../packages/utils/build. So the build exists. But the issue is that the setupVitest.ts is at the root leveltest/setupVitest.tsand when vitest runs frompackages/react, the setup file resolves@base-ui/utilsfrom the rootnode_modules, not from the test package's node_modules.Actually, vite would resolve from the setup file's directory. The setup file is at
/base-ui/test/setupVitest.ts. So it would resolve@base-ui/utilsstarting from/base-ui/test/and looking up the directory tree. Let me check:/base-ui/test/node_modules/@base-ui/utilsexists as a symlink to../../../packages/utils/build=/base-ui/packages/utils/build.But wait, I built the utils package, so the build directory should exist. Let me verify.
Assistant
Let me check the vite shared config for resolve settings:
Assistant
The vite config uses
process.cwd()for aliases, so I should run from the root directory. Let me try:Assistant
I've reproduced the issue. The panel content is not rendered. Let me look at the TabsTab component to understand the tabindex/selection logic:
Assistant
Let me look at the TabsList component to understand the highlighted tab logic:
Assistant
Let me create a more diagnostic test to understand the exactmechanism:
Assistant
Now I've confirmed the issue. After the promise resolves, both panels are gone. After a second click, Panel B appears. Let me see the full DOM after resolving:
Assistant
Let me instrument with value tracking to understand what's happening to the value:
Assistant
The smoking gun! After the suspense resolves, the automatic value change effect fires with
reason=missingand sets value tonull. Let me look at the composite registration to understand the tabMap timing:Assistant
The root cause is clear: after the suspense resolves, the automatic value change effect fires with
reason=missingand sets value tonullbecausetabMap.size === 0at that moment (withdidRegisterTabsRef.currentstill true). Let me verify this is the cause by testing with a controlled value (where the effect returns early):Assistant
Confirmed — with a controlled value (where the effect returns early), the bug doesn't happen. The root cause is the automatic value change effect. Let me add temporary instrumentation to understand the tabMap timing:
Assistant
Let me add temporary logging to understand the effect timing:
Assistant
Now I see the exact sequence. When the click happens and suspense suspends, the tree is detached,
tabMapgoes from 2 → 0 → 2, and the effect fires "missing" setting value tonull. Let me check whether this is due toisConnectedfiltering or actual unregistration in the composite:Assistant
Let me add temporary instrumentation to the composite to check whether it's the
isConnectedfilter or actual unregistration:Assistant
The logs are interleaved between the two CompositeList instances (tabs and panels). Let me make the instrumentation cleaner by logging only in the
onMapChangeeffect (which only the tabs composite uses to set tabMap):Assistant
Now I understand — during suspense, the
sortedMapbecomes empty (size 0) because nodes are detached, and this stale empty map is passed tosetTabMap, triggering the "missing" effect. Let me look at the tests PR #4704 added to understand what behavior must be preserved:Assistant
Let me check the git history of the
isConnectedfilter to understand why it was added:Assistant
The
isConnectedfilter was added in PR #3372. Let me compare the genuine-removal case vs the suspense case by running the existing removal test with my instrumentation:Assistant
The difference is clear:
- Genuine removal:
sortedMap.size=0 map.size=0(raw map empty, unregister called) - Suspense:
sortedMap.size=0 map.size=2(nodes retained, just disconnected/stale)
The raw
map.sizedistinguishes them. Let me look at what PR #3372 (which added the filter) was fixing, to make sure I don't regress it:- Genuine removal:
Assistant
Let me look at the TabsPanel changes in #3372 to understand the keepMounted scenario:
Assistant
Now I understand the issue fully. Let me remove my instrumentation and apply the fix. First, let me revert the instrumentation:
Assistant
Let me check if there are existing tests for the composite that might be affected:
Assistant
Now I'll apply the fix to
CompositeList. The fix keeps registered nodes in the map when they're all temporarily disconnected (e.g., during a Suspense hide), so consumers don't mistakenly treat the list as empty. This only changes the all-disconnected case (partial disconnects still filter as before):Assistant
Now let me apply the fix. I'll modify the
sortedMapcomputation to keep registered nodes when they're all temporarily disconnected (the Suspense case), while still filtering partial disconnects for sort quality:Assistant
Now let me recreate the reproduction test and verify the fix works:
Assistant
The fix didn't fully resolve it. Let me re-add instrumentation to understand what's happening now:
Assistant
The memo is still computing 0 at some point. Let me add logging inside the memo itself to see the actualcomputation:
Assistant
Let me re-apply the fix and look at how composite items register:
Assistant
I reverted the fix by accident. Let me re-apply it and add memo-level logging to understand:
Assistant
The key insight:
nodes=0during the suspense — the map is genuinely emptying (register/unregister being called), not just disconnected. Let me confirm by logging register/unregister:Assistant
Now I understand the real mechanism: during Suspense hide/show, the composite items'
register/unregistereffects are torn down and re-run (React Offscreen behavior), causingtabMapto transiently become empty. Theregisterruns before the TabsRoot layout effect, but thetabMapSTATE lags (async), so the layout effect sees a stale emptytabMapand fires "missing". Let me revert my ineffective composite change and look at the full effect to plan a proper fix:Assistant
Let me look at how
notifyAutomaticValueChangeis defined to mirror the pattern for extractingcommitAutomaticValueChange:Assistant
I'll implement the fix in
TabsRoot. The key insight: when the subtree is hidden by a Suspense boundary, React tears down and re-runs the tab registration effects, sotabMapis momentarily empty even though tabs aren't actually removed. I'll defer the "all tabs removed" fallback to a passive effect (which runs after registration settles), so it only fires when tabs are genuinely gone. First, let me extractcommitAutomaticValueChangeto a stable callback so both effects can use it:Assistant
The search failed because the indentation or exact text differs. Let me check the exact text around line 149.
Assistant
Let me open the file and use the edit command with line numbers:
Assistant
commitAutomaticValueChangereferencesshouldNotifyInitialValueChangeRefwhich is declared later. Let me place the extracted callback after the refs are declared. Let me view that area:Assistant
Let me view the exact lines of the effect toedit:
Assistant
Let me view the end of the layout effect to know where to add the passive effect:
Assistant
Now I'll make the edits. First, replace the nested function and the
tabMap.size === 0block with an early-return (with explanatory comment):Assistant
The
replacecommand only searches visible lines. Let me navigate to line 263 first:Assistant
Now let me make the edits. First, extract
commitAutomaticValueChangeto a stable callback before the layout effect, and replace the nested function + empty block:Assistant
Now let me remove the duplicate nested function and replace the
tabMap.size === 0block with an early-return:Assistant
Now let me add the passive effect for the "all tabs removed" case and add
commitAutomaticValueChangeto the layout effect deps. Let me view the deps area:Assistant
Let me fix the missing blank line between the passive effect and
const state:Assistant
Now let me recreate the reproduction test and run it:
Assistant
Still failing. Let me add logging to understand whether the passive effect is firing during the suspense:
Assistant
The passive effect fires during the suspense too. Let me add markers to understand exactly when
tabMap=0happens relative to click/resolve:Assistant
Let me re-add instrumentation to the original code with markers in the test to understand the exact timing:
Assistant
This is complex. Let me re-apply my TabsRoot fix and add marker logging to the passive effect to see exactly when it fires relative to the recovery:
Assistant
Let me re-apply the fix with logging in the passive effect:
Assistant
Let me re-do the edits. First extract commitAutomaticValueChange, then change the empty block, then add the passive effect with logging.
Edit 1: extract commitAutomaticValueChange (lines 254-261, replace didRegisterTabsRef line + the comment + effect start).
Assistant
Now remove the duplicate nested function and the empty block:
Assistant
Now add
commitAutomaticValueChangeto the layout effect deps and add the passive effect with logging:Assistant
Let me fix the missing blank line and run the test with markers:
Assistant
I realize the real issue is the composite passing a stale
sortedMap(memoized from a render where the map was empty) toonMapChange— this stale empty map is what produces the spurioustabMap=0after the register. Let me revert the TabsRoot changes and instead fix the composite to pass the fresh map in theonMapChangeeffect:Assistant
Now let me implement the composite fix: extract the sorted-map computation into a helper and use the fresh map in the
onMapChangeeffect (so it never passes a stale empty map). Let me view the rest of the file to find where to add the helper:Assistant
Now let me extract the sorted-map computation into a helper and use the fresh map in the
onMapChangeeffect:Assistant
Now update the
onMapChangeeffect to use the fresh map, and add thecomputeSortedMaphelper:Assistant
Now let me add the
computeSortedMaphelper function nearsortByDocumentPosition:Assistant
Now let me recreate the reproduction test and run it:
Assistant
The composite fresh-recompute fix works. Let me remove the repro test and run the existing tabs tests:
Assistant
All tabs tests pass. Now let me run the composite tests and other components that use the composite (select, menu, combobox, radio, etc.):
Assistant
Excellent! All composite-using components pass, including the genuine-removal cases ("resets to default when the selected item is removed", "falls back to null when both selected and initial default are removed"). Let me run the full react test suite to be thorough:
Assistant
All 6259 tests pass. Let me write a comprehensive edge-case test to verify various scenarios, then remove it:
Assistant
All edge cases pass. Let me remove the edge test and run a TypeScript check on the changed files:
Assistant
TypeScript compiles cleanly. Let me review the final diff:
Assistant
The diff is clean and minimal. Let me run the linter on the changed file to ensure code style compliance:
Assistant
Lint passes. Let me verify the working tree is clean except for the one changed file:
Assistant
Let me verify the utils build directory (which I created earlier for running tests) isn't an unintended untracked change:
Assistant
The utils build is gitignored, so it won't be submitted. Let me do a final review of the complete changed file:
Assistant
The fix is clean and complete. Let me do a final confirmation run of the tabs and composite tests to ensure everything passes in the final state:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.