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
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 understanding the repository structure and the issue. The issue is about Tabs.Panel content not rendering if a child component suspends without a boundary within Tabs.Root. Let me first explore the repository structure and then look at the relevant code.
The issue mentions this is potentially a side effect of PR #4704. Let me explore the tabs component and understand what changed.
Assistant
Let me look at the tabs package structure and find the relevant files.
Assistant
Let me look at the react package structure and find the tabs component.
Assistant
Let me look at the tabs directory.
Assistant
Let me look at the key files in the tabs component, starting with the panel and root implementations
Assistant
Let me look at them one at a time.
Assistant
Now let me look at the root component and its context to understand the
registerMountedTabPanelandunregisterMountedTabPanelfunctions.Assistant
Now let me examine the hooks used by the panel:
Assistant
Now let me look at
useOpenChangeComplete:Assistant
Let me find it.
Assistant
It's a .tsx file.
Assistant
Let me look at
useIsoLayoutEffect:Assistant
Let me look at the git history to understand what PR #4704 changed:
Assistant
Let me search for the PR that might be related. Let me look at git log for tabs-related changes
Assistant
Let me look at the changes introduced by PR #470
Assistant
Let me check the git diff for TabsPanel.tsx to see when it was last changed:
Assistant
Let me first try to reproduce the issue. Let me create a test script.
Assistant
Let me check the existing test files for tabs
Assistant
Let me first look at the playground
Assistant
Let me now try to reproduce the issue. First, let me look at how tests are structured and run:
Assistant
Let me run the existing tabs tests to see if they pass:
Assistant
All existing tests pass. Now let me create a reproduction script to confirm the issue.
Assistant
Let me place this test in the right location and run it.
Assistant
Now let me run this test:
Assistant
I've confirmed the issue. The panel content is not rendered after the suspense resolves. Let me look at what changed in PR #4704 more carefully, as the issue mentions it's potentially a side effect of that PR.
Assistant
Let me look at how
tabMapgets populated - let me check the TabsTab component.Assistant
Let me look at the CompositeList and useCompositeItem to understand how tabMap gets populated:
Assistant
Let me look at
useCompositeItemto understand itemAssistant
Let me look at
useCompositeListItem:Assistant
Let me also look at
useControlledto understand the value state management:Assistant
Let me create a more targeted test to debug the issue:
Assistant
Let me run this debug test
Assistant
Very interesting! The test reveals:
- After clicking Tab B, the value stays as "a" (Tab A still
aria-selected="true", React hides the old UI withdisplay: none) - After promise resolves, both tabs have
aria-selected="false"and no tabpanels exist — meaning value isnull
This suggests
tabMap.size === 0triggers a value reset. Let me add debug logging to trace the issue:- After clicking Tab B, the value stays as "a" (Tab A still
Assistant
Let me run this test.
Assistant
Now I see it clearly! The
onValueChange(null, "missing")is being called. Let me trace whytabMapbecomes empty. Let me add more debugging to the TabsRoot component itself.Assistant
Let me see the full effect:
Assistant
I've confirmed the issue:
onValueChange(null, "missing")is being called. Let me now trace howtabMapgets populated. I need to check howsetTabMapconnects toCompositeList:Assistant
Let me search for "setTabMap" in the tabs directory:
Assistant
Let me look at TabsList where
setTabMapis passed asonMapChangetoCompositeList:Assistant
I see
setTabMapis passed toCompositeRoot. Let me check it:Assistant
Let me check if IDs change between renders:
Assistant
Let me check the base
useId:Assistant
Let me add temporary debug logging to the TabsRoot effect to trace exactly when
tabMap.sizechanges:Assistant
Now let me run the test with this debug logging:
Assistant
Now I can see the exact problem. The effect runs with
tabMap.size: 0during the retry and resets the value. Let me check whyuseCompositeListItemre-runs. Let me add logging touseCompositeListItem:Assistant
I see there's a duplicate of the effect. Let me look at the full file and fix it:
Assistant
I accidentally broke the file. Let me restore it to its original state:
Assistant
Let me check
useStableCallback:Assistant
Now I understand the root cause. The
tabMapbriefly becomes empty during the suspense retry becauseuseCompositeListItem's cleanup effect runs (unregistering tabs) before the new effect re-registers them. This triggerssetTabMap(empty)→ TabsRoot effect seestabMap.size === 0withdidRegisterTabsRef.current === true→ resets value tonull.Let me restore the debug logging and implement the fix. First, let me restore TabsRoot.tsx:
Assistant
Now let me implement the fix. The issue is that
tabMapbriefly becomes empty during effect cleanup/registration cycles, triggering thecommitAutomaticValueChange(null, REASONS.missing)call.The fix: defer the empty-tabMap check using a microtask, and cancel it if tabs reappear before the microtask runs.
Assistant
Now let me implement the fix. I'll use a
queueMicrotaskapproach to defer the empty-map check, avoiding the transient empty state during effect cleanup/registration cycles:Assistant
Now I need to also add the cancellation of the pending check when
tabMapis non-empty. Let me add that:Assistant
Now let me run the suspense test to see if the fix works:
Assistant
The fix works! Now:
onValueChangeis only called once with{"value":"b","reason":"none"}(no spurious null reset)- Tab B has
aria-selected="true" - The panel content is properly rendered: "Panel B is rendered"
Now let me run all the existing tabs tests to make sure I haven't broken anything:
Assistant
All 172 tests pass (38 skipped), including the new suspense test. Let me now clean up the temporary test file and verify the final state:
Assistant
Let me verify the final state of the changed file:
Assistant
The diff looks clean. Let me run the full tabs test suite once more to confirm everything passes:
Assistant
All tests pass. Let me also verify no other files were modified:
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
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →
deepseek/deepseek-v4-proCompare side by side →
deepseek/deepseek-v4-proCompare side by side →
deepseek/deepseek-v4-proCompare side by side →