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 start by exploring the repository structure to understand the
Assistant
Let me look at the PR #4704 that was mentioned as the potential cause:
Assistant
me check the existing tests for the tabs to understand how they work:
Assistant
Let me look at the version history to understand when this changed:
Assistant
look at the recent commit that fixed state edge cases:
Assistant
let me look at the
useTransitionStatushook and understand the mounting behavior:Assistant
Let me look at the existing tests to understand how to test this:
Assistant
Let me now create a script to reproduce the issue:
Assistant
Now let me set up a test to reproduce the issue:
Assistant
let me look at the previous version of TabsRoot.tsx (before PR #4704):
Assistant
Let me look at how the tests are structured:
Assistant
Let me create a test script that reproduces the issue:
Assistant
Let me see the full output of the test failure:
Assistant
Let me add some debug logging to understand the issue:
Assistant
OK so
useControlledis straightforward. It usesuseStateto manage the uncontrolled value.Now let me trace through the issue. I want to verify my hypothesis that
Tabs.Rootis being unmounted.Looking at the test output:
- Tab A: aria-selected="true"
- Panel A is shown
- "Loading…" fallback is also shown
If Tabs.Root was unmounted, neither tab nor panel would be shown. But the output shows both Panel A and the Loading fallback. This suggests Tabs.Root is NOT unmounted; instead, the Suspense fallback is shown alongside the existing content.
Assistant
Let me check what's actually happening by adding some logging:
Assistant
Let me update the test to use a stable approach and add detailed logging:
Assistant
Let me add some logging to the TabsRoot to understand what's happening:
Assistant
Now let me update the test to wait for the promise to resolve properly:
Assistant
Let me look at the inner HTML structure to understand what is happening with the suspense:
Assistant
Let me check what React version is being used:
Assistant
Let me look at how the test is structured:
Assistant
Let me look at how composite items register:
Assistant
OK let me check how the
onMapChangecallback is called and what triggers a re-render of Tabs.Root.Looking at
CompositeList:useIsoLayoutEffect(() => { onMapChange(sortedMap); }, [onMapChange, sortedMap, elementsRef, labelsRef, mapTick]);- This calls
onMapChangewith the sorted map.
Looking at
TabsRoot.tsx:- The
setTabMapcallback is what's passed toonMapChange.
Looking at the
setTabMap:jsconst setTabMap = React.useState( () => new Map<Node, CompositeMetadata<TabsTab.Metadata> | null>(), )[1];Wait,
setTabMapis from auseStatebut it's aMap. SosetTabMapwould replace the entire map.But looking at the
CompositeList.onMapChange:jsuseIsoLayoutEffect(() => { onMapChange(sortedMap); }, [onMapChange, sortedMap, elementsRef, labelsRef, mapTick]);Assistant
Let me add some logging to TabsRoot to understand when it mounts/unmounts:
Assistant
The log line is in the wrong place because
tabMapis defined after it. Let me look at the code more carefully.Assistant
Now I see! Let me add more logs to Panel to understand the state:
Assistant
Let me check if React.use has special behavior:
Assistant
Let me add logging to
SuspendingChildto see what's happening:Assistant
Let me check the panel element rendering:
Assistant
OK so the Panel renders
elementwhich includes the children. The children are<SuspendingChild />.Let me check what's happening more carefully. Maybe the issue is that the Panel's children are not being rendered because of how the Panel's render works.
Let me check `renderTag
Assistant
Let me check by putting the Suspense boundary inside the Panel:
Assistant
The test is failing because of React warning, not the assertion. Let me wrap things in act:
Assistant
When Suspense is inside the Panel, it works! Let me now confirm the failure case:
Assistant
Let me check if Tabs.Root is being unmounted by Suspense:
Assistant
Let me check
useStableCallback:Assistant
Let me try a controlled value to confirm the behavior:
Assistant
Let me try storing the value outside the Suspense boundary:
Assistant
Even when the value state is in the parent component (outside Suspense), the panel doesn't render. This is because the parent component (Parent) is being unmounted by Suspense.
Wait, the parent component (Parent) is NOT inside the Suspense boundary. Let me re-check the structure:
jsxfunction Parent() { const [value, setValue] = React.useState('a'); return <TestApp value={value} onChange={setValue} />; } render(<Parent />);Assistant
Let me look at the actual code from before the PR:
Assistant
Let me look at git history for any related tests:
Assistant
Now let me look at the Panel more carefully to understand the structure:
Assistant
Let me revert my debug changes and look at the proper fix:
Assistant
Now let me implement the fix. I'll wrap the children in a Suspense boundary inside the Panel:
Assistant
The replacement was botched. Let me restore and try again:
Assistant
Let me restore and take a cleaner approach:
Assistant
Now let me run the test to see if this works:
Assistant
Now the test is failing differently - the outer fallback is no longer shown. This is the expected behavior with the inner Suspense. Let me update the test:
Assistant
The test fails because of the console.error warning. Let me suppress the warning. But first, let me check if the panel content is rendered.
Assistant
The test passes. Now let me check if I broke any existing tests:
Assistant
All existing tests pass. Let me also verify my fix handles the case where there's an inner Suspense boundary (from the user's bug report example):
Assistant
Both tests pass. Let me also clean up the test file (it was just for my testing, I shouldn't leave it in the codebase):
Assistant
Let me verify the final state of my changes:
Assistant
Let me run all the tabs tests to verify:
Assistant
All tests pass. Let me also think about edge cases. Let me think about what happens when:
Assistant
Let me think about edge cases and verify them:
Assistant
I need to fix the render prop case. Let me take a different approach:
Assistant
Now let me check how
useRenderElementhandles the children. Looking at the mergeProps function:Actually, I'm passing
{ children: ... }as the last item in the props array. This should override any children fromelementProps. Let me check.Looking at
useRenderElement:jsconst resolvedProps = enabled && props ? resolveRenderFunctionProps<TagName>(props) : undefined;And
resolveRenderFunctionProps:jsAssistant
Let me try a different approach. I'll revert and add the Suspense at the Tabs.Root level:
Assistant
me verify my approach works for the
renderprop case:Assistant
The "works with custom render prop" test now passes. The other failure is just a typo in my test. Let me fix the test and run all tabs tests:
Assistant
All edge case tests pass. Let me also run all the tabs tests to verify nothing is broken:
Assistant
All tests pass. Let me also verify the original bug report's example works:
Assistant
The bug report test passes. Let me clean up the temporary test files:
Assistant
Now let me also check the final state of the changes:
Assistant
fix is minimal and targeted. Let me run all tabs tests once more to make sure everything is good:
Assistant
All tests pass. Let me view the final diff:
Assistant
The fix is clean and minimal. Let me also do a final check by running the linter:
Assistant
ESLint passes. Let me also run TypeScript check.
Assistant
The TypeScript errors are about pre-existing build issues, not related to my fix. Let me check the relevant TabsPanel.tsx file specifically
Assistant
These errors are about the build not being run, not related to my fix. Let me run the broader test suite to make sure I haven't broken anything in other components:
Assistant
All tests pass. Let me check the final state of the fix:
Assistant
verify that my fix doesn't break the render prop case:
Assistant
3 render prop tests pass. Let me clean up the test file:
Assistant
Let me also do a final check on the fix:
Assistant
me do a final check by running all tabs tests:
Assistant
All 171 tests pass. Let me also verify the final state of my changes once more:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.