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
Let me start by exploring the repository structure to understand the
Assistant
Let me look at the PR mentioned in the issue to understand what changed.
Assistant
Assistant
me check the package.json and set up to reproduce the issue.
Assistant
Now let me look at how the test runner is set up to understand how to write a reproduction
Assistant
Let me create a reproduction script to confirm the issue first.
Assistant
Let me look at the existing tests to understand what they look like, then write a test that reproduces the issue:
Assistant
Let me write a reproduction test that demonstrates the issue:
Assistant
Let me look at
useRenderElementto understand what's happening:Assistant
Let me check the
useOpenChangeCompleteto understand:Assistant
Let me also check the test output for more context. Let me re-run with more infoLet me trace through what happens. Let me first check what state the system is in when the suspense happens:
Assistant
Let me check what React version is used:
Assistant
Let me check the most recent commit that touched tabs - this might have additional fixes:
Assistant
OK so this commit changed the code to use
initialDefaultValueRef.currentinstead ofdefaultValuePropdirectly. This was becauseuseControlledwarns ifdefaultValuechanges after mount, so they switched to using a ref.Now let me check the previous version (v1.4.1) to see how it handled things:
Assistant
Let me look at the tests related to "automatic" tab selection:
Assistant
me look at the previous version of the code:
Assistant
Let me check the actual tags to understand what changed in v1.4.1 vs v1.5.0:
Assistant
Let me check the
useControlledhook:Assistant
me add some logs to understand the behavior:
Assistant
Let me check if TabsPanel changed between v1.4.1 and v1.5.0:
Assistant
me actually check the v1.4.1 behavior by running the test with the old code:
Assistant
me restore the current code:
Assistant
Now let me update my test to handle the suspense properly:
Assistant
me look at the issue differently and add some logging to see what's happening:
Assistant
Let me check React version used in v1.4.1 vs current:
Assistant
React version went from 19.2.4 to 19.2.5 between v1.4.1 and v1.5.0. That's a patch release, shouldn't change Suspense behavior.
Let me check the @testing-library/react version too:
- 16.3.2 in both
Assistant
add some console.log to TabsRoot to see what's happening:
Assistant
Let me add console.log to TabsRoot to debug what's
Assistant
Let me add debug logs to see what's happening:
Assistant
Now let me update the test to spy on console.log and check the values:
Assistant
Let me see more of the output:
Assistant
Let me clean up the debug logs and check the actual issue more carefully:
Assistant
approach this differently. Let me write a test where the promise is already resolved, so no suspension needs to happen:
Assistant
Let me try the test in a browser instead of JSDOM to see if the behavior is different:
Assistant
try a different approach. Let me check the TabsRoot v1.4.1 by checking out the tag and running my test:
Assistant
Now let me run the test with the v1.4.1 code:
Assistant
! Even with v1.4.1 code, the test fails. So the issue isn't actually in the TabsRoot changes from v1.4.1 to v1.5.0.
Let me restore the current TabsRoot and think about this differently.
Assistant
Let me look more carefully at what's different between v1.4.1 and v1.5.0 in the entire tabs code:
Assistant
Let me check what happens with composite items and tabs when they suspend:
Assistant
Let me try a simpler reproduction outside of the Tabs component to understand React 19 Suspense behavior:
Assistant
Let me create a more focused test that examines what's happening:
Assistant
Let me check with a similar structure - stateful component inside Suspense:
Assistant
Let me try with fireEvent.click which is more synchronous:
Assistant
Let me check if the click handler is being called by adding logs:
Assistant
Let me fix the test syntax:
Assistant
Let me check the actual React state by adding a debug element:
Assistant
Let me check if Tabs.Root is being unmounted by adding more logging:
Assistant
Let me look at the test setup more carefully and try to handle Suspense correctly:
Assistant
Let me check by adding a useState to Tabs.Root and seeing if it persists:
Assistant
Let me check if there's a different behavior with useEffect:
Assistant
Let me check React's actual behavior with Suspense - check if state is truly preserved:
Assistant
me re-test the Tabs scenario with proper act() wrapping:
Assistant
me test v1.4.1 with proper act() wrapping:
Assistant
EUREKA!** v1.4.1 PASSES, v1.5.0 FAILS! Let me restore the current code and identify the difference:
Assistant
Let me add detailed logging to see what's happening in the v1.5.0 effect:
Assistant
I found the bug! Let me search for related tests:
Assistant
Let me check the relevant tests to understand the new feature:
Assistant
Now I understand the bug. The v1.5.0 added a new behavior to call
onValueChangewithnullandREASONS.missingwhen all tabs are removed. But this also triggers during Suspense, which causes the value to be reset to null.Let me implement the fix - we need to skip this fallback when the value was changed by the user:
Assistant
Now I'll implement the fix. The fix is to only trigger the missing fallback when the value is the initial default value, not when it was set by the user (which is the case during Suspense):
Assistant
Now let me run the test to see if the fix works:
Assistant
The fix works! Let me also test with a longer timeout that matches the user's scenario:
Assistant
Both tests pass. The fix:
- Resolves the original issue (panel content renders after suspense resolves)
- Doesn't break the new feature (calling onValueChange with null when all tabs are removed)
Let me run the existing tabs tests to make sure nothing else is broken:
Assistant
All 173 tests pass (38 are skipped due to JSDOM environment). Let me also run more tests to be sure:
Assistant
All 6261 tests pass (895 are skipped due to environment). My fix doesn't break anything.
Let me now clean up the test file and remove the debug logs:
Assistant
Let me verify the final fix is in place:
Assistant
Let me also verify the fix with one more test using a controlled value pattern to ensure my fix doesn't break edge cases:
Assistant
All edge cases pass. Let me also run the full tabs test suite to make sure my fix is robust:
Assistant
All 174 tests pass. Now let me clean up the test file (it was a temporary reproduction file) and make sure my fix is complete:
Assistant
Only the fix is changed. Let me look at the final diff:
Assistant
The fix is minimal and clean. Let me also verify the file looks correct:
Assistant
The fix is in place. Let me run the full test suite one more time to confirm everything still works:
Assistant
All 171 tests pass. The fix is complete.
Summary
Problem
The bug reported in the issue is that when a
<Tabs.Panel>has a child that suspends, and the nearest<Suspense>boundary is outside<Tabs.Root>, the panel content is not rendered when opening a tab for the first time. The user must click the trigger a second time for the content to appear.Root Cause
In v1.5.0, PR #4704 added a new behavior to call with and when all tabs are removed. This was added to handle the case where users explicitly remove all tabs (e.g., via conditional rendering).
Assistant
Now let me address the checklist:
Checklist:
-
If an error was reported in the issue description, I have successfully reproduced it.
- Yes, I created a reproduction test that confirmed the bug. With the current v1.5.0 code, the test failed because the panel content was not rendered. I also tested the same scenario with v1.4.1 code and it passed, confirming the regression.
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Yes, with my fix in place, the reproduction test passes. The panel content is now correctly rendered when the promise resolves after clicking a tab.
-
I have thought about edge cases and made sure my fix handles them as well.
- Yes, I tested multiple edge cases:
- The original bug scenario (default value, click Tab B, promise resolves)
- Switching back and forth between tabs (Tab B with suspension, then Tab A)
- Yes, I tested multiple edge cases:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.