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 understand the issue:
-
In Base UI v1.5.0, when using
Tabs.Rootwith aSuspenseboundary outside it (i.e., wrappingTabs.Root), and a child component inside aTabs.Panelsuspends, 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. -
This is a regression from v1.4.1, potentially caused by https://github.com/mui/base-ui/pull/4704
Let me start by exploring the repository structure and understanding how Tabs works.
-
Assistant
Let me explore the repository structure, focusing on the Tabs component.
Assistant
Let me explore the tabs directory structure.
Assistant
Let me explore the relevant source files. Let me look at the panel and root components, and also check the git log for PR #4704.
Assistant
Let me look at the relevant files one at a time
Assistant
Now let's look at the TabsPanel component:
Assistant
Now let me look at the
useTransitionStatushook:Assistant
Let me check the git log to understand PR #4704:
Assistant
Let me search for the PR #4704 in the git
Assistant
Found it! Let me look at the diff from this commit:
Assistant
Let me look at the diff to understand what changed in TabsRoot
Assistant
Let me look at the `useOpenChangeComplete
Assistant
Let me find this file.
Assistant
It's a .tsx file.
Assistant
Let me check if there are existing tests related to Suspense or the Tabs panel:
Assistant
Let me look at how to run the tests for tabs
Assistant
Let me look at the playground directory to see if I can create a reproduction
Assistant
Let me look at what we have in the playground:
Assistant
Assistant
Let me try to understand the bug by running the existing tabs tests.
Assistant
Let me look at the
useControlledhookAssistant
Let me look at
useControlled:Assistant
Let me check the most recent tabs-related fix
Assistant
Let me see what that commit changed in TabsRoot
Assistant
Let me look at the
useCompositeListItemhookAssistant
Let me look at CompositeList component
Assistant
Let me search for any related issues or PRs about Suspense
Assistant
Let me look at the Dialog Suspense fix for clues
Assistant
Let me look at the FloatingPortal change
Assistant
Let me look at the full diff for that
Assistant
Let me create a reproduction script to test the Suspense issue. But first, let me look at how tests import things
Assistant
Let me check the React version
Assistant
Let me create a test to reproduce the issue
Assistant
Let me try running this test
Assistant
Let me place the test in the tabs directory
Assistant
Let me run the test
Assistant
The bug is reproduced! The panel is not rendered. Let me understand what's happening better by checking the DOM state more
Assistant
Let me run the test to see debug output
Assistant
Now I can see the issue clearly. After the promise resolves:
- Neither tab is selected (
aria-selected="false") - No panels are rendered at all
Let me look at the TabsTab component to understand how
setTabMapworks:- Neither tab is selected (
Assistant
Let me look at
useCompositeItem:Assistant
Let me look at the TabsRootContext
Assistant
Let me search for where
setTabMapisAssistant
So
setTabMap<|DSML|tool_calls> <|DSML|invoke name="bash_terminal"> <|DSML|parameter name="command" string="true">cat packages/react/src/tabs/list/TabsList.tsx</|DSML|parameter> </|DSML|invoke> </|DSML|tool_calls>
Assistant
Let me continue.
Assistant
Let me look at
CompositeRootAssistant
Let me add better debugging to the test to understand what's happening
Assistant
Let me run this test
Assistant
The test shows the value becomes
nullafter the promise resolves. Let me look at theuseAnimationsFinishedhook and check if there's something clearing state:Assistant
Let me add temporary logging to TabsRoot to understand what's happening
Assistant
Let me look at the
useIsoLayoutEffectin TabsRoot more carefullyAssistant
Let me use the goto command properly.
Assistant
Let me look at TabsRoot before PR #4704
Assistant
Let me look at
useRefWithInitAssistant
Let me add temporary logging to the TabsRoot effect to understand the issue
Assistant
I see a duplicate line. Let me fix that
Assistant
Now let me run the test
Assistant
Now I can see the problem clearly. The issue is:
- After the promise resolves,
tabMap.sizetemporarily becomes0 - This triggers
commitAutomaticValueChange(null, REASONS.missing)becausedidRegisterTabsRef.currentistrueandvalueis notnull - This resets the value to
null, breaking the tabs
The old code (before PR #4704) simply returned early when
tabMap.size === 0without resetting. The fix is to restore that behavior. Let me revert the problematic change:- After the promise resolves,
Assistant
Good, I've made the fix. The key change is to simply return early when
tabMap.size === 0instead of resetting the value tonull. Now let me run the test:Assistant
The fix works! The test passes now. Let me run the existing Tabs tests to make sure I haven't broken anything:
Assistant
There's a failing test. Let me look at it to understand what behavior it expects:
Assistant
Let me look at the failing test:
Assistant
Let me see the full
Assistant
The test reveals the issue: my fix breaks the feature that resets value to null when all tabs are removed. Let me refine the fix to handle both cases. Let me look at how the tabs are removed vs. the suspense retry case differently.
Assistant
I need a better fix. Let me look at this differently. Instead of immediately resetting when
tabMapis empty, I can defer the check. Let me look at how to properly handle both cases.Assistant
The
queueMicrotaskapproach won't work becausetabMapis captured by closure. Let me take a different approach - let me understand whytabMapbecomes empty during the suspense retry by adding logging to CompositeList.Assistant
Let me try a different approach using a ref to track the latest
tabMapvalue, so the deferred check can see the updated state:Assistant
Let me check the file looks correct
Assistant
Now let me remove the debug console.log I added earlier
Assistant
Good, no console.log left. Let me run both tests:
Assistant
There's a parse error. Let me check line 361
Assistant
The code is corrupted. Let me look at the full context around this area and fix it
Assistant
I need to restore the corrupted code. Let me check git diff to see what happened
Assistant
I see the problem - my earlier edit accidentally removed the
const stateandconst elementdeclarations. Let me restore them.Assistant
Let me check that the code is syntactically correct by verifying the return statement is properly preceded
Assistant
Good, now let me run
Assistant
Both tests pass now! Let me also run the other tabs-related tests to make sure everything is fine
Assistant
All tests pass. Let me clean up the temporary test file and verify the final state of my changes
Assistant
Now let me verify the final diff to make sure my changes are clean
Assistant
The diff is clean. Let me also run the full test suite to make sure nothing else is broken
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.