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 what we're working with.
Assistant
Now let me look at the git log for the Tabs related files:
Assistant
Now let me look at the most recent commit (b3e140591) to see what was the "fix state edge cases" commit
Assistant
Now let me look at the panel test file to understand how to write a test for this:
Assistant
Now let me check the
useTransitionStatusto understand how it works:Assistant
Now let me reproduce the issue. Let me look at how tests are typically run:
Assistant
Now let's try to reproduce the issue using a script:
Assistant
me look at the TabsTab component to understand the click handler:
Assistant
Now let me set up a test to reproduce the issue. First, let me look at how tests are run:
Assistant
Let me check existing tests that use Suspense:
Assistant
me check TabsList and TabsTab click handler logic:
Assistant
me look at how tests are structured with React Suspense:
Assistant
Now let me write a test to reproduce the issue. Let me first add a test file:
Assistant
Let me first run the existing tests to confirm the test setup works:
Assistant
Now let me create a temporary test to reproduce the issue:
Assistant
Let me look at the
useControlledhook:Assistant
Let me check the git tags and changelog:
Assistant
Let me look at the composite props for tabs:
Assistant
me run a simpler test to see what's happening:
Assistant
Let me write a test that's more focused on observing what happens:
Assistant
Let me wrap the resolvePromise in act:
Assistant
me look at git history to understand what was changed between v1.4.1 and v1.5.0:
Assistant
Let me try a different approach - add console logs to see what's happening:
Assistant
Let me see the full test output:
Assistant
me write a simpler test that observes what happens after the suspense:
Assistant
Interesting! After the promise resolves:
- Tab A is selected (
aria-selected="true") - Tab B is not selected (
aria-selected="false") - Panel A content is in the DOM (
panel-a-content) - Panel B content is NOT in the DOM (
panel-b-contentis false) - Loading fallback is still in the DOM
Wait, Loading fallback is still in the DOM? That's weird. The promise resolved but the loading is still showing.
Hmm, this is confusing. Let me check the actual rendered DOM.
Actually, let me check what's happening more carefully. The console output got truncated. Let me run again with full output.
- Tab A is selected (
Assistant
Let me look at how the existing Dialog Suspense test handles the resolve:
Assistant
Let me try without the act() wrap:
Assistant
Let me look at the CompositeList:
Assistant
Let me check the existing Dialog Suspense test to make sure it works:
Assistant
Let me first try to understand the actual behavior better with a simpler test (no Suspense):
Assistant
Now let me check what happens with Suspense inside the panel:
Assistant
me look at the DOM after the resolve to see what's happening:
Assistant
Let me try using React.lazy:
Assistant
Let me check the Dialog test more carefully:
Assistant
Let me test with a controlled value to see if the state is preserved:
Assistant
Let me check the controlled tabs test behavior and compare:
Assistant
Let me check React 19 behavior by adding some logging:
Assistant
Let me test with uncontrolled to see what's happening:
Assistant
Interesting! Looking at the output:
- Loading is shown after click
- After resolve and 200ms wait, Loading is STILL present, panel-a-content is present
- Loading eventually goes away (in the waitFor)
So the Suspense DOES resolve eventually, but with a delay. Let me see how long.
Wait, the
Loading is gonelog appears, meaning the waitFor succeeded eventually. Let me re-run to see what the actual outcome is.Assistant
So:
- Loading is shown
- Loading is gone after some time (waitFor succeeded)
- But panel-b-content is never rendered
So Loading eventually goes away, but Panel B is never rendered. So the Suspense resolved but with Panel A still being shown. This means value="a" after the resolve, not "b".
Let me check what the final DOM looks like:
Assistant
actually try v1.4.1 to see if the bug exists there too:
Assistant
OK so even with v1.4.1 of TabsRoot.tsx, the test still fails. The bug isn't specific to the v1.5.0 changes in TabsRoot.
The bug is at a different level. The Suspense resolves but Panel B is never shown - Panel A is shown. This means the value state was reset to defaultValue="a" after the Suspense.
Let me check the rendered DOM after "Loading is gone":
Assistant
With v1.4.1 of TabsRoot.tsx, the test eventually shows "panel-b-content is rendered"! Let me revert to v1.5.0 and see if it eventually works too:
Assistant
me add some logging to the TabsRoot to see what's happening:
Assistant
Let me add debug logging temporarily to understand what's happening:
Assistant
Now I understand the bug! Let me revert the debug changes and look at the related tests:
Assistant
me look at the AnimationFrame utility:
Assistant
OK AnimationFrame uses requestAnimationFrame under the hood. In tests, this might not work as expected with fake timers.
Let me think of a different approach.
Actually, let me re-think the issue. The bug is that the
commitAutomaticValueChange(null, REASONS.missing)is being called in the Suspense case.What if we just remove that branch? Then:
- When tabMap is empty, no commit happens.
- value is preserved.
This matches v1.4.1 behavior. But the "missing tab" test would fail.
Let me check what tests exist for the missing tab behavior:
Assistant
Let me try removing the new missing handling and see if it fixes the bug:
Assistant
! With my fix,
panel-b-contentis rendered! The fix works for the Suspense case.The test still "fails" but only because of the act() warnings (which is a separate issue from the bug fix).
Let me verify by checking the existing TabsRoot tests still pass:
Assistant
Let me look at the test that fails:
Assistant
Let me try a state-based approach that defers the commit by one render:
Assistant
Let me write a cleaner fix using a state-based approach:
Assistant
Let me try a different approach - use a state to track when to defer:
Assistant
! With this fix, panel-b-content is rendered! Now let me check the existing TabsRoot tests:
Assistant
Only 1 test fails now. Let me look at this test in detail to understand:
Assistant
Let me add logging to debug:
Assistant
me debug more to understand the issue:
Assistant
Let me try using a different approach to force re-render:
Assistant
me try a different approach - use a microtask to defer the commit:
Assistant
The microtask approach works for the missing tab test. Now let me check if it also works for the Suspense test:
Assistant
The microtask approach works for BOTH tests! Let me run all the TabsRoot tests to make sure nothing is broken:
Assistant
All TabsRoot tests pass. Let me run all the tabs tests:
Assistant
Only my test file (TabsRootSuspenseRepro.test.tsx) is "failing" - but it's only because of act() warnings (not the actual functionality). The fix works! Let me clean up and remove my temporary test file:
Assistant
Let me verify the final state of the fix:
Assistant
fix is simple and clean. Let me run the full TabsRoot test once more to make sure everything passes:
Assistant
All tabs tests pass. Let me also verify my fix works by creating a temporary test that reproduces the issue and confirming it passes:
Assistant
The fix works correctly. Now let me clean up the temporary test:
Assistant
Let me verify my final fix one more time:
Assistant
Let me run the tabs tests one more time to make sure everything is fine:
Assistant
tabs tests pass. Let me also run a broader set of tests to make sure my fix doesn't break anything else:
Assistant
Let me add logging to verify the fix works correctly:
Assistant
Now I see the issue! The microtask commits null AFTER the panel-b-content is rendered, but with a delay. The test passes because it checks within the waitFor timeout. Let me fix this properly using a ref for the latest tabMap:
Assistant
I see - the patch wasn't applied correctly because the placement of
tabMapRefdeclaration is wrong. ThetabMapRefis declared aftertabMap, but the assignment totabMapRef.current = tabMapis placed BEFOREtabMapRefdeclaration.Let me fix this by placing the assignment after the useState declaration:
Assistant
The fix works correctly now. The panel-b-content remains rendered even after additional wait. Let me verify the existing TabsRoot tests still pass:
Assistant
All TabsRoot tests pass! Let me also run the full tabs test suite:
Assistant
tabs tests pass. Let me also run a broader set of tests to make sure nothing else breaks:
Assistant
All 992 tests pass. Let me clean up my temporary test file and verify the final fix:
Assistant
me also verify the diff makes sense and add a test that runs the test scenarios that the user might care about:
Assistant
The fix looks good. Let me verify the diff once more:
Assistant
me also run a few more tests to make sure the fix is robust:
Assistant
All 528 tests pass. Let me also run a comprehensive check on the typecheck:
Assistant
errors are not related to my changes - they are build configuration issues. Let me verify the modified file specifically:
Assistant
These errors are just from
--ignoreConfigwhich doesn't pick up workspace path aliases. They're not related to my changes. Let me view the final fix:Assistant
me run the tabs tests one more time to make sure everything passes:
Assistant
All tabs tests pass. Let me verify my fix handles the issue from the bug report:
Assistant
The fix correctly resolves the user's issue. Let me clean up my temporary test file:
Assistant
Now let me go through the checklist one final time:
Checklist review:
-
If an error was reported in the issue description, I have successfully reproduced it. ✅ Yes. I reproduced the bug by creating a test that uses Suspense outside and a component inside a panel. The test confirmed that without the fix, the panel content was not rendered after the Suspense resolved (and in fact Panel A was incorrectly displayed). With the fix, the panel content renders correctly.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.