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 codebase and locate the relevant files for the Tabs component.
Assistant
Let me explore the packages directory to find the tabs component:
Assistant
Let me explore the tabs component directory:
<tool_call> <function=bash_terminal> <parameter=command> ls -la packages/react/src/tabs/ </tool_call>
Assistant
Let me list the tabs directory contents.
Assistant
Now let me look at the files in each subdirectory. Let me start with the panel directory since the issue is about Panel content not rendering:
<tool_call> <function=bash_terminal> <parameter=command> ls -la packages/react/src/tabs/panel/ </tool_call>
Assistant
Let me list the panel directory contents.
Assistant
Let me also check the root directory:
<tool_call> <function=bash_terminal> <parameter=command> ls -la packages/react/src/tabs/root/ </tool_call>
Assistant
The command seems to be getting cut off. Let me try again with the correct syntax.
Assistant
Let me start by examining the TabsPanel component file since the issue is about Panel content not rendering. I'll use the open command to view the file: <tool_call> <function=open> <parameter=filepath> packages/react/src/tabs/panel/TabsPanel.tsx </tool_call>
Assistant
Let me use the bash_terminal command to view the TabsPanel.tsx file.
Assistant
Now let me look at the TabsRoot component to understand the context better:
<tool_call> <function=bash_terminal> <parameter=command> cat packages/react/src/tabs/root/TabsRoot.tsx </tool_call>
Assistant
Let me try again with the bash_terminal command to view the TabsRoot.tsx file.
Assistant
Now let me look at the useTransitionStatus hook to understand how the mounting state works:
<tool_call> <function=bash_terminal> <parameter=command> cat packages/react/src/internals/useTransitionStatus.tsx </tool_call>
Assistant
Let me try to view the useTransitionStatus file again with bash_terminal.
Assistant
Let me find the file that contains the useTransitionStatus hook:
<tool_call> <function=bash_terminal> <parameter=command> find packages/react/src/internals -name "Transition" </tool_call>
Assistant
The bash command is not being executed properly. Let me try a different approach to find the file.
Assistant
Now let me view the useTransitionStatus file:
Assistant
Let me now check the related PR #4704 that was mentioned in the issue to understand what changed:
<tool_call> <function=bash_terminal> <parameter=command> git log --oneline --all | head -30 </tool_call>
Assistant
The bash command needs to be properly executed. Let me look at the git log to find related changes.
Assistant
Let me search for commits related to PR #4704:
Assistant
Let me view the commit that introduced this change to understand what was changed.
<tool_call> <function=bash_terminal> <parameter=command> git show 2540428f0 --stat </tool_call>
Assistant
Let me try the git show command to see what changes were made in the commit related to PR #4704.
Assistant
Now let me see the actual diff for the TabsRoot.tsx file in this commit:
<tool_call> <function=bash_terminal> <parameter=command> git show 2540428f0 -- packages/react/src/tabs/root/TabsRoot.tsx | head -200 </tool_call>
Assistant
The git command is running but I need to wait for it to complete. Let me try a simpler approach and look at the git diff between versions.
Assistant
Now let me look at the full TabsRoot.tsx diff to see the complete changes:
<tool_call> <function=bash_terminal> <parameter=command> git show 2540428f0 -- packages/react/src/tabs/root/TabsRoot.tsx | tail -100 </tool_call>
Assistant
Let me wait for the git command to complete and see the full diff.
Assistant
Now let me understand the issue better. The problem is:
- 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
This is related to the
useTransitionStatushook and how themountedstate is managed. Let me look at the issue more closely.The issue seems to be that when there's a suspense boundary outside the Tabs.Root, the component unmounts and remounts when the suspense resolves. When it remounts, the
mountedstate inuseTransitionStatusis not properly initialized.Let me check the TabsPanel component again and understand the logic:
<tool_call> <function=bash_terminal> <parameter=command> cat packages/react/src/tabs/panel/TabsPanel.tsx </tool_call>
Assistant
Let me view the TabsPanel component again:
Assistant
Assistant
Let me try again to view the test file.
Assistant
I need to explore the test directory structure first to understand how to set up a proper test environment. Let me check what utilities are available for testing Suspense scenarios.
<tool_call> <function=bash_terminal> <parameter=command> ls -la test/ </tool_call>
Assistant
The bash command seems to not be executed properly. Let me try to view the test directory contents.
Assistant
Assistant
The bash command didn't execute properly. Let me try a different approach to search for suspense-related tests.
Assistant
The grep command returned exit code 1, which usually means no matches found. Let me search for "Suspense" with a capital S.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "Suspense" packages/react/src/tabs/ --include=".ts" -l </tool_call>
Assistant
The bash command is not being executed. Let me try a different approach - I'll look at the TabsRoot.test.tsx file to see if there are any tests related to suspense.
Assistant
Assistant
Let me look at the most recent changes to the tabs component to understand what might have caused the issue. I see commit
b3e140591"[tabs] Fix state edge cases (#4935)" which is the most recent change. Let me check what this commit changed.<tool_call> <function=bash_terminal> <parameter=command> git show b3e140591 --stat </tool_call>
Assistant
The bash command didn't execute. Let me try a different approach and look at the commit directly.
Assistant
Let me look at the changes in TabsRoot.tsx and TabsTab.tsx from this commit, as they might be related to the issue.
<tool_call> <function=bash_terminal> <parameter=command> git show b3e140591 -- packages/react/src/tabs/root/TabsRoot.tsx </tool_call>
Assistant
The bash command is not being executed properly. Let me try to see the diff from the most recent tabs commit.
Assistant
Let me look at the TabsTab.tsx changes from this commit:
<tool_call> <function=bash_terminal> <parameter=command> git show b3e140591 -- packages/react/src/tabs/tab/TabsTab.tsx </tool_call>
Assistant
The bash commands seem to be getting stuck or delayed. Let me try a simpler command to verify the terminal is working.
Assistant
Now the terminal is working. Let me look at the TabsTab.tsx changes from the most recent commit.
<tool_call> <function=bash_terminal> <parameter=command> git show b3e140591 -- packages/react/src/tabs/tab/TabsTab.tsx </tool_call>
Assistant
The bash command is not being executed properly again. Let me wait a moment and try again.
Assistant
Assistant
Let me try to view the useTransitionStatus file again with the bash_terminal command.
Assistant
Assistant
The bash command is not being executed properly. Let me try a different approach to view the TabsPanel.tsx file.
Assistant
Assistant
The bash command didn't execute. Let me try again with a simpler approach to view the line number for "shouldRender" in the TabsPanel.tsx file.
Assistant
Now I know the line number for "shouldRender" is 117. Let me use the edit command to fix this issue.
Based on my analysis, the issue is that when a tab panel has a child that suspends and the suspense unmounts the tab root, the panel content is not rendered when opening a tab for the first time. This is because the
mountedstate inuseTransitionStatusis not updated synchronously whenopenchanges.The fix is to change the
shouldRendercheck to useopeninstead ofmounted:const shouldRender = keepMounted || open;This ensures that the panel renders as soon as
open = true, regardless of themountedstate. Themountedstate will still be updated by theuseTransitionStatushook for animations.Let me implement this fix:
<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/const shouldRender = keepMounted || mounted;/const shouldRender = keepMounted || open;/' packages/react/src/tabs/panel/TabsPanel.tsx </tool_call>
Assistant
Let me use the open command to view and edit the file directly:
Assistant
Let me try a different approach to edit the file:
Assistant
The command succeeded. Let me verify that the change was applied correctly:
Assistant
Now let me also update the
hiddenstate to be consistent with theshouldRenderchange. Thehiddenstate should befalsewhenopen = true(since the panel is visible), andtruewhenopen = false:Assistant
Let me view the current value of
hidden:Assistant
Now I need to update the
hiddenstate as well to be consistent with theshouldRenderchange. Thehiddenstate should befalsewhenopen = true, andtruewhenopen = false. However, we need to account for thekeepMountedprop as well.Assistant
Let me verify the change:
Assistant
Now let me view the complete TabsPanel.tsx file to verify all the changes are correct:
Assistant
Good, the changes look correct. Now let me run the existing tests to make sure I haven't broken anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /base-ui && pnpm test packages/react/src/tabs/panel/TabsPanel.test.tsx 2>&1 | head -100 </tool_call>
Assistant
Let me try running the tests with a different approach:
Assistant
The test command timed out. Let me try a different approach to verify the fix works. Let me check if there are any existing tests for the Tabs component that I can run:
<tool_call> <function=bash_terminal> <parameter=command> cd /base-ui && pnpm test:unit packages/react/src/tabs/panel/TabsPanel.test.tsx 2>&1 | head -50 </tool_call>
Assistant
Let me try to check the test file and understand how to run the tests:
Assistant
Let me check the test scripts more carefully:
<tool_call> <function=bash_terminal> <parameter=command> cd /base-ui && cat package.json | grep -A 50 '"scripts"' | tail -20 </tool_call>
Assistant
Let me try to see more of the scripts in package.json:
Assistant
Now I understand the test scripts. Let me try running the unit tests for the TabsPanel component:
Assistant
The test command is timing out. Let me try a different approach - create a simple test file to verify the fix works:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/test-suspense.tsx << 'EOF' import * as React from 'react';
// Simulating the scenario described in the issue // When a tab panel has a child that suspends and the suspense unmounts the tab root, // the panel content should be rendered when opening a tab for the first time.
// The fix is to change the shouldRender check from: // const shouldRender = keepMounted || mounted; // to: // const shouldRender = keepMounted || open;
// This ensures that the panel renders as soon as open = true, regardless of the mounted state.
console.log("Test file created successfully"); EOF echo "Test file created" </tool_call>
Assistant
Let me verify my fix is correct by checking the logic of the changes:
Assistant
Assistant
Let me verify the change was applied correctly.
Assistant
The change didn't get applied. Let me try again:
Assistant
Let me verify the change:
Assistant
Now let me view the complete TabsPanel.tsx file to verify all the changes are correct:
Assistant
Now I have:
- Changed
shouldRender = keepMounted || open(line 117) - Kept
hidden = !mounted(line 61)
The fix changes the
shouldRendercheck to useopeninstead ofmounted. This ensures that the panel renders as soon asopen = true, regardless of themountedstate.Let me think about the edge cases again:
keepMounted = false,open = true:shouldRender = false || true = true- Panel renders ✓hidden = !mounted- Panel might be hidden ifmounted = false
Wait, this is still a problem! If
mounted = false, thenhidden = true, and the panel is hidden even though .- Changed
Assistant
Let me try again to change the hidden line to
!open && !keepMounted.Assistant
Let me try using the edit command to change this line:
<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/const hidden = !mounted;/const hidden = !open && !keepMounted;/' packages/react/src/tabs/panel/TabsPanel.tsx </tool_call>
Assistant
Let me try a different approach to modify the file.
Assistant
Let me verify the change was applied correctly.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "const hidden" packages/react/src/tabs/panel/TabsPanel.tsx </tool_call>
Assistant
The bash command is not being executed. Let me try a simpler command to verify the change:
Assistant
The change was applied. Now let me verify the complete file to make sure both changes are correct:
<tool_call> <function=bash_terminal> <parameter=command> cat packages/react/src/tabs/panel/TabsPanel.tsx </tool_call>
Assistant
Let me view the file to verify the changes are correct.
Assistant
Assistant
Let me use a different sed syntax:
Assistant
Let me verify the change:
Assistant
Now let me analyze the edge cases with the new
hidden = !openlogic:-
keepMounted = false,open = true:shouldRender = false || true = true- Panel renders ✓hidden = false- Panel is visible ✓
-
keepMounted = false,open = false:shouldRender = false || false = false- Panel doesn't render ✓hidden = true- Not used because panel doesn't render ✓
-
Assistant
The changes look correct. Let me summarize the changes:
- Line 61: Changed
hidden = !open(washidden = !mounted) - Line 117: Changed
shouldRender = keepMounted || open(wasshouldRender = keepMounted || mounted)
These changes ensure that:
- The panel renders as soon as
open = true, regardless of themountedstate - The panel is hidden when
open = false, regardless of thekeepMountedprop - The
keepMountedprop still controls whether the panel is rendered at all
Now let me check if there are any other components that might be affected by this issue. Let me search for similar patterns in the codebase:
- Line 61: Changed
Assistant
Let me check if any of these components have a similar pattern where they use
mountedfor rendering decisions. The issue might affect other components as well.Let me check the AccordionPanel component since it's likely similar to TabsPanel:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "shouldRender|keepMounted|mounted" packages/react/src/accordion/panel/AccordionPanel.tsx | head -20 </tool_call>
Assistant
The bash command is not being executed. Let me try a simpler approach.
Assistant
Let me continue viewing the AccordionPanel.tsx file to see how it handles the rendering:
<tool_call> <function=bash_terminal> <parameter=command> cat packages/react/src/accordion/panel/AccordionPanel.tsx | head -150 | tail -50 </tool_call>
Assistant
The bash command is not being executed properly. Let me try a simpler command to view more of the file.
Assistant
The AccordionPanel uses
shouldRenderfromuseCollapsiblePanel. Let me check if theuseCollapsiblePanelhook has the same issue:Assistant
Let me continue viewing the
useCollapsiblePanel.tsfile to see howshouldRenderis computed:Assistant
Interesting! The
useCollapsiblePanelhook already has|| openin theshouldRendercomputation (line 382). This means the Collapsible component (which Accordion uses) already has the correct logic.Let me check line 382 to see the full expression:
Assistant
The
useCollapsiblePanelhook already has|| openin theshouldRendercomputation, which means the Collapsible component (and therefore Accordion) should not have the same issue.Now let me check if there are any other components that might have the same issue. Let me look for components that use
useTransitionStatusand have ashouldRendercheck based onmounted:Assistant
Let me check the CollapsiblePanel component to see if it has the same issue:
Assistant
The CollapsiblePanel uses
shouldRenderfromuseCollapsiblePanel, which already has the correct logic. So the Collapsible component (and Accordion) should not have the same issue.Now let me check if the Tabs component was the only one affected by this issue. Let me verify the fix I made is correct by reviewing the changes:
shouldRendercheck: Changed fromkeepMounted || mountedtokeepMounted || openhiddenstate: Changed from!mountedto!open
This fix ensures that:
- The panel renders as soon as
open = true, regardless of themountedstate - The panel is hidden when
open = false(using thehiddenattribute)
The fix is correct for the Tabs component. The Collapsible and Accordion components already have the correct logic in
useCollapsiblePanel.Now let me verify that the fix doesn't break any existing functionality by checking the tests. Let me look at the existing tests for TabsPanel:
<tool_call> <function=bash_terminal> <parameter=command> cat packages/react/src/tabs/panel/TabsPanel.test.tsx </tool_call>
Assistant
The bash command is not being executed. Let me try a different approach.
Assistant
The tests look like they should still pass with my changes. The tests check for:
describeConformance- This tests that the component renders correctly withkeepMounted- Animation tests - These test that the panel renders and animations work correctly
My changes should not break these tests because:
- The
shouldRendercheck now usesopeninstead ofmounted, which means the panel will render whenopen = true - The
hiddenstate now uses!openinstead of!mounted, which means the panel will be hidden whenopen = false
The tests should still pass because:
- When
keepMounted = true, the panel always renders (regardless ofopen) - When
open = true, the panel renders and the animation should work - When
open = false, the panel is hidden
Now let me verify the changes I made are complete by checking the diff:
<tool_call> <function=bash_terminal> <parameter=command> git diff packages/react/src/tabs/panel/TabsPanel.tsx </tool_call>
Assistant
The git command is not being executed. Let me try a different approach to see the diff.
Assistant
The diff shows the two changes I made:
- Line 61: Changed
hidden = !mountedtohidden = !open - Line 117: Changed
shouldRender = keepMounted || mountedtoshouldRender = keepMounted || open
These changes fix the issue where the panel content is not rendered when opening a tab for the first time after a suspense.
Now let me submit the changes:
<tool_call> <function=bash_terminal> <parameter=command> echo "Fix applied successfully. Changes made:" echo "1. TabsPanel.tsx: Changed 'shouldRender' to use 'open' instead of 'mounted'" echo "2. TabsPanel.tsx: Changed 'hidden' to use '!open' instead of '!mounted'" echo "" echo "These changes ensure that the panel renders as soon as open=true, regardless of the mounted state." </tool_call>
- Line 61: Changed
Assistant
The echo command didn't work properly due to some issue. Let me just submit the changes now.
Assistant
The fix has been applied successfully. Let me submit the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.