Skip to content
TheChatArchiveThe Chat Archive
QwenQwen/Qwen3.6-27B· alibabaHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [tabs] Tabs.Panel content not rendered if a child component suspends…

  1. 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.Root component), 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

    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 using git reset --hard command. Additionally, you can use git stash and git stash pop to 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 submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /base-ui, current file: none) bash-$

  2. Qwen Assistant

    Let me analyze this issue. The bug is about Tabs.Panel content not being rendered when a child component suspends without a boundary within Tabs.Root. The issue mentions this is a regression in v1.5.0, potentially caused by PR #4704.

    Let me start by exploring the repository structure to understand the codebase and find the relevant files.

  3. Qwen Assistant

    Let me look at the TabsRoot.tsx file first to understand how the tabs state is managed.

  4. Qwen Assistant

    The open command seems to have failed. Let me try a different approach.

  5. Qwen Assistant

    Now let me look at the TabsPanel.tsx file to understand how the panel content is rendered:

  6. Qwen Assistant

    Let me look at the useTransitionStatus hook to understand how the mounted state is tracked:

  7. Qwen Assistant

    Now let me look at the PR #4704 that's mentioned as the potential cause of the issue. Let me check the git log:

  8. Qwen Assistant

    Let me check the specific PR #4704 that's mentioned as potentially causing the issue:

  9. Qwen Assistant

    Let me see the actual diff for the TabsRoot.tsx in that PR:

  10. Qwen Assistant

    Now let me understand the issue better. The issue is about Suspense - when a child of a Tab panel suspends and the Suspense boundary is outside the Tabs.Root, the panel content doesn't render on the first tab activation. Let me think about what's happening:

    1. User clicks on tab B
    2. Tab B's panel tries to render
    3. A child component suspends
    4. React unwinds the render and the Tabs.Root gets unmounted temporarily
    5. When React retries, the panel content doesn't render

    The key part is in TabsPanel.tsx. The issue is likely related to the useTransitionStatus hook where mounted state is managed. When the component suspends and the whole Tabs.Root unmounts, the mounted state is lost.

    Let me also look at how the mounted state interacts with the panel registration:

  11. Qwen Assistant

    Let me look more carefully at the TabsPanel code. The issue is that when a Suspense boundary causes a re-render, the mounted state in useTransitionStatus might not be set properly. Let me check the exact flow:

  12. Qwen Assistant

    Let me see the rest of the file, specifically the registration effect:

  13. Qwen Assistant

    Now I understand the issue better. The problem is in the useIsoLayoutEffect that registers/unregisters the tab panel:

    useIsoLayoutEffect(() => {
        if (hidden && !keepMounted) {
          return undefined;
        }
        // ...
        registerMountedTabPanel(value, id);
        return () => {
          unregisterMountedTabPanel(value, id);
        };
      }, [hidden, keepMounted, value, id, registerMountedTabPanel, unregisterMountedTabPanel]);
    

    When a panel suspends:

    1. User clicks on tab B
    2. open becomes true for panel B
    3. useTransitionStatus sets mounted to true (in render phase)
    4. The panel renders, but its child suspends
    5. React catches the suspense and re-renders from a boundary outside Tabs.Root
    6. During the re-render, the selectedValue is still "b", but since the component tree is being thrown away, mounted state is lost
    7. On the retry render, mounted starts as false again (initial state is based on open)
    8. But wait - useTransitionStatus sets mounted during render when open && !mounted

    Let me look at useTransitionStatus more closely:

  14. Qwen Assistant

    Now let me look at the useIsoLayoutEffect that's used - is it a client-only effect that doesn't run during server rendering?

  15. Qwen Assistant

    command

  16. Qwen Assistant

    Now let me trace through what happens when a child suspends:

    1. Tab B is clicked, selectedValue changes to "b"
    2. Panel B's open becomes true
    3. In useTransitionStatus, since open is true and mounted is initially false, it calls setMounted(true) synchronously during render
    4. Panel renders, but SuspendingChild throws a promise
    5. React suspends and the nearest boundary (outside Tabs.Root) catches it
    6. The entire Tabs.Root tree is thrown away (unmounted) during the fallback render
    7. When the promise resolves, React retries rendering
    8. But now Tabs.Root remounts fresh - selectedValue is still "b" but all state is fresh
    9. Panel B re-renders with open = true, and useTransitionStatus should set mounted = true

    Wait, actually the issue might be more subtle. Let me re-read the useTransitionStatus hook:

    const [mounted, setMounted] = React.useState(open);
    

    If open is true initially, mounted starts as true. But when the component suspends and the tree is thrown away, the state should be reset when it remounts.

    Actually, I think I need to look at how open is computed. When the component first mounts after a suspense recovery, selectedValue should still be "b" if the user had selected tab B. But the issue says the panel content isn't rendered.

    Let me look at the registration logic more carefully:

    useIsoLayoutEffect(() => {
        if (hidden && !keepMounted) {
          return undefined;  // <-- early return when hidden
        }
        // ...
        registerMountedTabPanel(value, id);
        // ...
      }, [hidden, keepMounted, value, id, registerMountedTabPanel, unregisterMountedTabPanel]);
    

    The hidden variable is !mounted. So if mounted is false, hidden is true, and the registration effect returns early without registering the panel.

    But wait, let me re-check. The shouldRender check is:

    const shouldRender = keepMounted || mounted;
    if (!shouldRender) {
      return null;
    }
    

    If keepMounted is false (default) and mounted is false, the panel returns null early and doesn't render at all!

    The problem might be that when a suspense happens and then recovers:

    1. After suspense recovery, the panel re-renders
    2. useTransitionStatus starts fresh
    3. useState(open) - if open is still true, mounted should be true

    Hmm, but if the value "b" was set by clicking, it should persist. Let me think about this differently.

    Let me check what happens when selectedValue changes. The issue says clicking tab B for the first time doesn't show the panel content, but clicking a second time does. This suggests that on the first click:

    1. selectedValue changes to "b"
    2. Panel B re-renders with open = true
    3. useTransitionStatus sees open = true, sets mounted = true
    4. Panel renders but suspends
    5. Suspense boundary catches and shows fallback
    6. The whole Tabs.Root is unmounted during fallback

    When the promise resolves and React retries: 7. Tabs.Root remounts 8. Panel B re-renders

    But wait - since Tabs.Root is uncontrolled, its state is lost! When it remounts, value goes back to defaultValue="a". So selectedValue is now "a" again!

    That's the bug! When the Suspense boundary unmounts the Tabs.Root, the selected value reverts to the default value, and the panel that was being viewed is no longer selected.

    Let me verify this theory by checking how the TabsRoot manages its value:

  17. Qwen Assistant

    Yes, I can confirm my theory. The TabsRoot uses useControlled for its value state. When the Suspense boundary causes the Tabs.Root to unmount and then remount, the state is lost, and value reverts to defaultValue.

    Now let me look at the test file to see if there are existing tests for this behavior:

  18. Qwen Assistant

    No existing tests for Suspense. Let me now think about the actual fix. The issue is that when a panel's child suspends and the suspense boundary is outside the Tabs.Root, the Tabs.Root is unmounted and its state (the selected value) is lost.

    Looking back at the issue description:

    The only affected version is v1.5.0 v1.4.1 is not affected

    This suggests the issue was introduced in a recent change. Let me check what changed between v1.4.1 and v1.5.0 related to tabs:

  19. Qwen Assistant

    The issue mentions PR #4704 as the potential cause. But looking at the git history, there's also a more recent commit [tabs] Fix state edge cases (#4935) that might be relevant. Let me check what that fix does:

  20. Qwen Assistant

    This commit doesn't seem to be directly related to the suspense issue. Let me now look at what changed in PR #4704 that could have introduced this regression. Looking at the diff more carefully, I think the key change is in the automatic value change logic. But let me first create a test script to reproduce the issue:

  21. Qwen Assistant

    Let me look at the test setup to understand how to run tests:

  22. Qwen Assistant

    Let me understand the current behavior more deeply. The issue says the panel isn't rendered when first opening a tab after a suspense. Let me trace through the code flow again.

    Looking at the issue more carefully - when a child suspends and the suspense boundary unmounts the tab root, the problem is that the panel's mounted state gets lost. Let me check if there's something specific about how the useTransitionStatus initial state works:

  23. Qwen Assistant

    I think I now understand the issue better. Let me re-trace what happens:

    1. Tabs.Root with defaultValue="a" renders initially
    2. User clicks tab B, value changes to "b"
    3. Panel B's open becomes true, useTransitionStatus sets mounted = true during render
    4. Panel B renders, but child suspends
    5. Suspense boundary catches and shows fallback - Tabs.Root is completely unmounted
    6. Promise resolves, React retries
    7. Tabs.Root remounts with defaultValue="a", so value is "a" again
    8. Panel B has open = false (since value is "a"), so mounted starts as false
    9. Panel B returns null since !keepMounted && !mounted

    Wait, that would mean after suspense recovery, tab A would be selected again, not tab B. But the issue says "Only when clicking the trigger a second time, the panel is rendered." This suggests that the tab B trigger still shows as selected, but the panel content is not shown.

    Let me re-read the issue more carefully. The issue says:

    the next boundary is outside the Tabs.Root component

    So the suspense boundary unmounts the Tabs.Root. After recovery:

    • If uncontrolled: value goes back to default
    • But the user sees they clicked tab B and it should still be selected

    Actually, wait. Let me re-read the Stackblitz example. The defaultValue is "a". When clicking tab B:

    1. Value changes to "b"
    2. Panel B suspends
    3. Entire tree is thrown away (including the value state)
    4. Fallback shows
    5. After recovery, Tabs.Root remounts with value = "a" (default)

    But wait, that would mean tab A is selected again after recovery. The issue says clicking a second time works, which means after recovery, the user would need to click tab B again to see its content.

    Let me check if there's something else going on. Maybe the issue is about a different scenario - where the suspense boundary catches the error but the Tabs.Root state is somehow preserved, but the panel's mounted state is reset.

    Let me look at the pnpm installed version to understand what version we're working with:

  24. Qwen Assistant

    Now let me think about this more carefully. Let me re-read the bug report:

    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.Root component), 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.

    So the flow is:

    1. Initial render: Tab A is selected, Panel A shows (no suspense)
    2. User clicks Tab B
    3. Panel B's child suspends
    4. Suspense boundary outside Tabs.Root catches it
    5. After recovery: Tab B should still be selected (value is "b"), but Panel B's content doesn't render
    6. User clicks Tab B again
    7. Now Panel B renders

    This suggests that after recovery, the value state in TabsRoot is preserved (value = "b"), but something about the panel's mounted state is wrong.

    But if the Tabs.Root was completely unmounted, how could the value be preserved? Unless... the suspense doesn't actually unmount the Tabs.Root, but rather React throws the render and retries without fully unmounting?

    Let me think about this differently. When React encounters a suspended component:

    1. React renders Tabs.Root with value "b"
    2. Panel B tries to render but suspends
    3. React catches the suspense at the boundary outside Tabs.Root
    4. React shows the fallback
    5. During this time, the entire tree including Tabs.Root is discarded
    6. When the promise resolves, React starts fresh from the Suspense boundary
    7. Tabs.Root remounts

    But the key insight is: when Tabs.Root remounts, what is its value?

    If defaultValue="a" is used (uncontrolled), then value will be "a" on remount. But the issue says clicking a second time works, which implies the tab trigger for B is still visually selected.

    Actually, I think I might be overcomplicating this. Let me create a test script to reproduce the issue first:

  25. Qwen Assistant

    The test is taking too long. Let me try running it with a timeout and focus on a specific test:

  26. Qwen Assistant

    `

  27. Qwen Assistant

    I need to run a command to check the pnpm version and proceed with investigating the issue.

  28. Qwen Assistant

    Let me look at the version history to find what changed between v1.4.1 and v1.5.0:

  29. Qwen Assistant

    No tags found. Let me investigate the code more directly to understand the suspense issue.

  30. Qwen Assistant

    Let me explore the useBaseUiId hook and useOpenChangeComplete to understand the full picture:

  31. Qwen Assistant

    Let me now think more deeply about the issue. The problem is:

    1. When a tab panel's child suspends, and the Suspense boundary is outside Tabs.Root
    2. The panel content is not rendered when opening a tab for the first time
    3. Only when clicking the trigger a second time, the panel is rendered

    The key insight is that when React suspends and the boundary is outside Tabs.Root, the entire Tabs.Root tree is thrown away. When React retries, Tabs.Root remounts with fresh state.

    But wait - the issue says "when opening a tab for the first time" which suggests the user hasn't yet selected that tab. So the scenario is:

    1. Tabs.Root mounts with defaultValue="a" - Panel A is shown
    2. User clicks tab B
    3. Panel B's open becomes true, useTransitionStatus sets mounted = true during render
    4. Panel B renders its children, but SuspendingChild suspends
    5. React catches at Suspense boundary (outside Tabs.Root)
    6. The entire Tabs.Root tree is thrown away and fallback is shown
    7. Promise resolves, React retries
    8. Tabs.Root remounts with defaultValue="a" (since it's uncontrolled)
    9. Now Panel B has open = false (since value is "a")
    10. Panel B's useTransitionStatus initializes with mounted = false
    11. Panel B returns null because !keepMounted && !mounted

    But the issue says clicking a second time works. After step 8-10, if the user clicks tab B again: 12. value changes to "b" 13. Panel B's open becomes true 14. Panel B renders... but wait, should it suspend again?

    Actually, no! The promise has already resolved, so the SuspendingChild won't suspend this time. Panel B renders successfully.

    So the real issue is: after the first suspense recovery, Tabs.Root's value reverts to the default value "a", so tab B is no longer selected. The user has to click tab B again.

    But this seems like expected behavior - if the component unmounts, its state is lost. The issue says this worked in v1.4.1 but not in v1.5.0.

    Hmm, let me re-read the issue more carefully:

    The panel content is not rendered also when first opening a tab like it did in v1.4.1.

    This suggests that in v1.4.1, after the suspense recovered, the panel content WAS rendered. So there must be something different about how the panel rendering works.

    Wait, I think I need to look at this more carefully. The key line in TabsPanel.tsx is:

    const shouldRender = keepMounted || mounted;
    if (!shouldRender) {
      return null;
    }
    

    And mounted comes from useTransitionStatus(open). In useTransitionStatus:

    const [mounted, setMounted] = React.useState(open);
    
    if (open && !mounted) {
      setMounted(true);
      setTransitionStatus('starting');
    }
    

    So when open is true, mounted should be set to true synchronously during render. This means if Panel B has open = true, it should render.

    But after the suspense recovery, if Tabs.Root reverts to value "a", then Panel B has open = false and mounted = false, so it returns null.

    The issue description says the user clicks tab B and the panel doesn't render. But if after recovery, value is "a", then tab B wouldn't be selected, so the panel wouldn't be expected to render.

    Unless... the issue is that the value DOES persist somehow, but the panel's mounted state doesn't.

    Let me think about this differently. What if the Suspense boundary doesn't completely unmount Tabs.Root but only throws the render?

    Actually, React's suspense model works like this:

    1. During render, if a component suspends (throws a promise), React catches it
    2. React "rolls back" the render for the subtree under the suspended component
    3. The Suspense boundary shows its fallback
    4. The promise resolves
    5. React retries the render

    The key question is: does React unmount the entire subtree from the Suspense boundary down, or does it just rollback the render?

    For a Suspense boundary that's outside Tabs.Root, when Panel B suspends:

    1. React tries to render the entire tree
    2. Panel B suspends
    3. React catches at the Suspense boundary
    4. React discards the work for the entire subtree (including Tabs.Root)
    5. Fallback is shown
    6. Promise resolves
    7. React retries from the Suspense boundary

    When React retries, it starts fresh. The Tabs.Root remounts, so all its state is reset.

    But wait, what if the Tabs.Root is actually kept mounted and only the Panel B is the one that gets retried? That depends on the structure...

    Looking at the example code:

    <Suspense fallback={<div>Loading…</div>}>
      <Tabs.Root defaultValue="a">
        ...
        <Tabs.Panel value="b">
          <SuspendingChild />
        </Tabs.Panel>
      </Tabs.Root>
    </Suspense>
    

    When Panel B suspends, React will:

    1. Show the fallback
    2. Discard the entire Tabs.Root tree
    3. When promise resolves, retry from the Suspense boundary

    So Tabs.Root will remount with fresh state, including value = "a" (the defaultValue).

    But the issue says the problem is that "panel content is not rendered when opening a tab for the first time" and "only when clicking the trigger a second time, the panel is rendered." This suggests that after recovery, tab B IS selected (value is "b") but the panel doesn't render.

    Hmm, let me reconsider. Maybe the issue is about the useId hook. Let me check if useId uses state:

    <tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/utils/src/useId.ts 2>/dev/null </tool_call>

  32. Qwen Assistant

    Let me use the correct tool call syntax.

  33. Qwen Assistant

    The tool call succeeded. Let me continue investigating the issue.

  34. Qwen Assistant

    Let me check the git history for TabsPanel.tsx to see what changes might have affected this behavior:

  35. Qwen Assistant

    Let me look at the PR #4704 that's mentioned in the issue as potentially causing the regression. Let me also check the TabsPanel changes that might have introduced this bug. Let me look at the commit [tabs] Fix Panel keepMounted behavior (#3372) which might be relevant.

  36. Qwen Assistant

    This commit looks relevant. Let me see the TabsPanel changes in detail:

  37. Qwen Assistant

    This is very interesting! Let me look at the diff more carefully:

    Before (v1.4.1 or earlier):

    const hidden = tabPanelValue !== selectedValue;
    // ...
    { children: hidden && !keepMounted ? undefined : children },
    

    After (the commit that changed behavior):

    const hidden = value !== selectedValue;
    // ...
    useIsoLayoutEffect(() => {
        if (hidden && !keepMounted) {
          return undefined;
        }
        // register the panel
      });
    
      const shouldRender = !hidden || keepMounted;
      if (!shouldRender) {
        return null;
      }
    

    So in the old version, the panel was always rendered but with children set to undefined when hidden. This means the panel element itself was always in the DOM.

    In the new version, the panel returns null when hidden, so it's not rendered at all. This is the key difference!

    But wait, this doesn't directly explain the suspense issue. Let me think about this more...

    Actually, I think the issue is that in the new version:

    1. When Panel B opens and suspends, React catches at the Suspense boundary
    2. The fallback is shown and the entire Tabs.Root tree is discarded
    3. When React retries, Tabs.Root remounts with fresh state
    4. Panel B's open is still true (because the value is still "b" in the parent's click handler)... wait, no. If Tabs.Root is uncontrolled, its state is lost.

    Hmm, but the issue says the user needs to click tab B again to see the content. This implies that after recovery, tab B is NOT selected. So clicking tab B again selects it and the content renders (because the promise has resolved).

    So this might actually be expected behavior - when a component unmounts and remounts, its state is lost.

    But the issue says "like it did in v1.4.1". Let me think about why it worked in v1.4.1...

    Wait! I see it now! In the old version:

    { children: hidden && !keepMounted ? undefined : children }
    

    The panel element was always rendered (even when hidden), just with undefined children. This means the panel was always registered in the TabsRoot context!

    In the new version:

    const shouldRender = !hidden || keepMounted;
    if (!shouldRender) {
      return null;
    }
    

    When the panel is hidden, it returns null and doesn't register itself with the TabsRoot.

    But this still doesn't fully explain the suspense issue...

    Actually, let me look at the current code again. The current code uses useTransitionStatus which has mounted state:

    const { mounted, transitionStatus, setMounted } = useTransitionStatus(open);
    const hidden = !mounted;
    

    So hidden is based on mounted, not on open. The panel uses a transition animation.

    And:

    const shouldRender = keepMounted || mounted;
    if (!shouldRender) {
      return null;
    }
    

    So the panel renders when keepMounted is true OR mounted is true.

    In useTransitionStatus:

    const [mounted, setMounted] = React.useState(open);
    
    if (open && !mounted) {
      setMounted(true);
      setTransitionStatus('starting');
    }
    

    So when open is true, mounted is set to true synchronously during render.

    Now, when Panel B suspends:

    1. User clicks tab B
    2. Panel B's open becomes true
    3. useTransitionStatus sets mounted = true during render
    4. shouldRender is true
    5. Panel renders but suspends in its child
    6. React catches at Suspense boundary
    7. Fallback is shown
    8. After promise resolves, React retries

    When React retries, Tabs.Root has been completely discarded and remounts. The key question is: what is the value of Tabs.Root after remount?

    If it's uncontrolled with defaultValue="a", then value is "a" again. So Panel B's open is false, mounted is false, and it returns null.

    But the issue says the problem is that the panel "is not rendered when opening a tab for the first time" and works "when clicking the trigger a second time". This sounds like after recovery, tab B IS selected (otherwise clicking a second time wouldn't be needed - the user would need to click tab B from tab A).

    So maybe the value IS preserved? Let me think about this differently...

    Actually, wait. I think I've been misunderstanding the scenario. Let me re-read the issue:

    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.Root component), the panel content is not rendered when opening a tab for the first time.

    "when opening a tab for the first time" - this is the initial render, not after clicking!

    So the scenario might be:

    1. Tabs.Root mounts with defaultValue="a"
    2. Panel A renders normally
    3. But what if Panel A also suspends? Or what if the user navigates to a different page and then comes back?

    Actually, I think the scenario is:

    1. Tabs.Root mounts with defaultValue="a"
    2. User clicks tab B
    3. Panel B's open becomes true, mounted becomes true
    4. Panel B renders but suspends
    5. Fallback is shown
    6. After promise resolves, React retries
    7. Tabs.Root remounts with defaultValue="a"
    8. Tab B is no longer selected
    9. User clicks tab B again
    10. Now Panel B renders (promise already resolved, no suspense)

    But the issue says the expected behavior is that the panel should render "like it did in v1.4.1". So in v1.4.1, after step 6, the panel content WAS rendered.

    The difference between v1.4.1 and the current version might be in how the panel registration works. In the old version, the panel was always rendered (just with undefined children). In the new version, it returns null when hidden.

    But that still doesn't explain why v1.4.1 would work... unless the registration of panels affects whether the value is preserved.

    Actually, I think I need to look at this from a different angle. The PR #4704 mentions "Fire onValueChange for automatic tab selection". Let me see if there's something in that PR that affects the behavior when tabs register/unregister.

    Let me look at the current code flow:

    1. Panel registers itself with TabsRoot via registerMountedTabPanel
    2. Panel unregisters via cleanup function in the effect

    If a panel suspends before the effect runs, it never registers. Then when it retries, it might try to register again...

    Wait! I think I found the issue!

    Look at the useIsoLayoutEffect in TabsPanel.tsx:

    useIsoLayoutEffect(() => {
        if (hidden && !keepMounted) {
          return undefined;
        }
        // ...
        registerMountedTabPanel(value, id);
        return () => {
          unregisterMountedTabPanel(value, id);
        };
      }, [hidden, keepMounted, value, id, registerMountedTabPanel, unregisterMountedTabPanel]);
    

    When a panel suspends, the render is interrupted and effects never run. So the panel never registers itself with TabsRoot!

    Now, in TabsRoot, there's logic that checks if the current selection is valid:

    const selectionIsMissing = selectedTabMetadata == null && value !== null;
    

    If the selected panel hasn't registered (because it suspended), selectedTabMetadata might be null... but wait, selectedTabMetadata is about tabs, not panels.

    Let me re-read TabsRoot.tsx:

    const selectedTabMetadata = React.useMemo(() => {
        for (const tabMetadata of tabMap.values()) {
          if (tabMetadata != null && tabMetadata.value === value) {
            return tabMetadata;
          }
        }
        return undefined;
      }, [tabMap, value]);
    

    This is about tabs (the triggers), not panels. The tabs register themselves separately.

    OK, let me look at the mountedTabPanels state:

    const [mountedTabPanels, setMountedTabPanels] = React.useState(
        () => new Map<TabsTab.Value | number, string>(),
      );
    

    This maps panel values to their IDs. It's used for aria-controls and aria-labelledby.

    I think the key issue might be in the automatic value change logic in TabsRoot. Let me look at it:

    useIsoLayoutEffect(() => {
        if (isControlled) {
          return;
        }
    
        // ...
    
        if (tabMap.size === 0) {
          if (!didRegisterTabsRef.current || value === null) {
            return;
          }
          commitAutomaticValueChange(null, REASONS.missing);
          return;
        }
    
        didRegisterTabsRef.current = true;
    
        const selectionIsDisabled = selectedTabMetadata?.disabled;
        const selectionIsMissing = selectedTabMetadata == null && value !== null;
        // ...
        if (selectionIsDisabled || selectionIsMissing) {
          const fallbackValue = firstEnabledTabValue ?? null;
          // ...
          commitAutomaticValueChange(fallbackValue, fallbackReason);
          return;
        }
        // ...
      }, [...]);
    

    This effect runs when tabs register. If the selected tab is disabled or missing, it automatically falls back to the first enabled tab.

    But wait, this is about tabs, not panels. The tabs (triggers) register independently of the panels.

    Let me think about the actual flow again:

    1. User clicks tab B
    2. onValueChange is called, setValue("b")
    3. TabsRoot re-renders with value = "b"
    4. Panel B's open becomes true
    5. Panel B's useTransitionStatus sets mounted = true during render
    6. shouldRender is true (because mounted is true)
    7. Panel B renders its element
    8. Panel B renders its children, which includes <SuspendingChild />
    9. <SuspendingChild /> suspends (throws a promise)
    10. React catches at the Suspense boundary outside TabsRoot
    11. The entire TabsRoot tree is discarded and fallback is shown
    12. Promise resolves
    13. React retries rendering from Suspense boundary
    14. TabsRoot remounts with value = defaultValue = "a" (state is lost)
    15. Now tab A is selected, not tab B

    So after recovery, the value reverts to the default. This is expected for an uncontrolled component.

    But the issue says the expected behavior is that the panel should render. This implies that in v1.4.1, after the suspense recovery, tab B was still selected.

    How could that happen? Unless v1.4.1 didn't use the same state management...

    Actually, let me re-read the issue one more time. The key sentence is:

    Only when clicking the trigger a second time, the panel is rendered.

    This suggests that after recovery, clicking tab B again shows the panel. If the value reverted to "a", clicking tab B would change it to "b" again, and the panel would render.

    So the issue might be that after the first click:

    1. Value changes to "b"
    2. Panel B suspends
    3. After recovery, value is back to "a"
    4. User clicks tab B again
    5. Value changes to "b"
    6. Panel B renders (no suspense because promise resolved)

    But wait, this seems like expected behavior! Why would it be different in v1.4.1?

    Unless... the issue is that after the first click, even though the value reverts to "a", the user expects tab B to still be selected. This is a UX issue, not a code issue.

    Actually, I think I've been overthinking this. Let me re-read the Stackblitz example:

    export default function App() {
      return (
        <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>
      );
    }
    

    When the user clicks tab B:

    1. Value changes to "b"
    2. Panel B tries to render
    3. SuspendingChild suspends
    4. Suspense catches and shows fallback
    5. TabsRoot is unmounted
    6. Promise resolves
    7. TabsRoot remounts with value = "a" (default)

    Now, after step 7, the user sees tab A selected (because value is "a"). The user then clicks tab B again, and the panel renders.

    The issue says this worked in v1.4.1. So in v1.4.1, after step 6, the panel content WAS rendered. This means the value was still "b" after recovery.

    How could the value be preserved? The only way is if the TabsRoot didn't completely unmount.

    Actually, wait. Let me reconsider React's Suspense behavior. When a component suspends:

    1. React catches the thrown promise
    2. React rolls back the render of the suspended subtree
    3. The Suspense boundary shows its fallback
    4. BUT - the state of components above the suspended component is preserved!

    In this case, the suspended component is <SuspendingChild /> which is a child of <Tabs.Panel>. The Suspense boundary is outside <Tabs.Root>. So when <SuspendingChild> suspends:

    1. React rolls back from <SuspendingChild> up to the Suspense boundary
    2. This includes <Tabs.Panel> and <Tabs.Root>
    3. The fallback is rendered

    But here's the key: when React rolls back, does it call cleanup effects? Does it "unmount" the components?

    According to React's documentation, when Suspense catches a promise, it "rolls back" the render phase. This means:

    • Render phase state updates are discarded
    • Effects don't run for the rolled-back subtree
    • Components are NOT unmounted in the traditional sense - they just haven't committed yet

    So when the promise resolves and React retries:

    • TabsRoot is NOT remounted - it's the same instance
    • Its state (value = "b") is preserved
    • Panel B tries to render again

    But wait, if that's the case, then value should still be "b" after recovery. Let me re-read my understanding...

    Actually, I think there are two different Suspense behaviors:

    1. During initial render (mount): If a component suspends during mount, React rolls back and shows fallback. When the promise resolves, React retries the mount. State IS preserved because the component instance is the same.

    2. After commit: If a component suspends after it has already been committed, React unmounts it, shows fallback, and remounts when the promise resolves. State is NOT preserved because the component was unmounted.

    In our case, the user clicks tab B (this is an event, so TabsRoot is already committed). Then Panel B suspends. This is case 2: React needs to unmount the subtree and show fallback.

    Hmm, but actually, when the user clicks tab B, setValue("b") triggers a re-render. This re-render commits the change. But if Panel B suspends during this render, the render is interrupted before commit.

    So the flow is:

    1. User clicks tab B
    2. setValue("b") is called
    3. React starts rendering with value = "b"
    4. Panel B renders but suspends
    5. React catches at Suspense boundary
    6. React rolls back the render (the value = "b" update is discarded)
    7. Fallback is shown with value = "a" (the previous committed state)
    8. Promise resolves
    9. React retries the render with value = "b" (the update is still pending!)

    Wait, is that right? Let me think about this more carefully...

    When setValue("b") is called, React schedules a state update. Then it starts rendering. During render, Panel B suspends. React catches and rolls back. The rollback discards the render phase, but what about the state update?

    In React 18+, when a render is interrupted by a Suspense boundary, the state update that triggered the render is NOT discarded. It's retried when the promise resolves.

    So the flow should be:

    1. User clicks tab B
    2. setValue("b") is called, scheduling a state update
    3. React starts rendering with value = "b"
    4. Panel B suspends
    5. React rolls back the render
    6. Fallback is shown (with the previous committed state, value = "a")
    7. Promise resolves
    8. React retries the render with value = "b" (the pending update is still there!)
    9. Panel B renders successfully

    If this is correct, then after step 8, value should be "b" and Panel B should render!

    But the issue says the panel doesn't render. So something else must be going on...

    Let me look at the useTransitionStatus hook again:

    const [mounted, setMounted] = React.useState(open);
    
    if (open && !mounted) {
      setMounted(true);
      setTransitionStatus('starting');
    }
    

    When React retries with value = "b":

    • Panel B's open is true
    • useState(open) - this initializes mounted based on the current open value
    • Since open is true, mounted starts as true

    Wait, but React state initialization only happens once per component instance. If the component didn't fully mount (because it suspended), and then React retries, the state initialization should still be based on the initial value passed to useState.

    But here's the thing: if React rolls back the render, the component instance is discarded and a new one is created on retry. So useState(open) is called again, and mounted is initialized to open (which is true).

    So after retry, mounted should be true and the panel should render!

    Unless... there's something about how the state update is batched or how React handles the suspended render.

    OK let me think about this differently. What if the issue is not about the state being lost, but about the id being different?

    Looking at useBaseUiId:

    export function useBaseUiId(idOverride?: string): string | undefined {
      return useId(idOverride, 'base-ui');
    }
    

    And useId:

    export function useId(idOverride?: string, prefix?: string): string | undefined {
      if (maybeReactUseId !== undefined) {
        const reactId = maybeReactUseId();
        return idOverride ?? (prefix ? `${prefix}-${reactId}` : reactId);
      }
      return useGlobalId(idOverride, prefix);
    }
    

    React's useId is stable for a component instance. But if the component is rolled back and remounted, the ID might change.

    But actually, looking at the registration effect:

    useIsoLayoutEffect(() => {
        if (hidden && !keepMounted) {
          return undefined;
        }
        // ...
        registerMountedTabPanel(value, id);
        return () => {
          unregisterMountedTabPanel(value, id);
        };
      }, [hidden, keepMounted, value, id, registerMountedTabPanel, unregisterMountedTabPanel]);
    

    The id is used to register the panel. If the id changes between renders (because the component was remounted), the old registration is still there, and a new one is added.

    But mountedTabPanels is a Map keyed by panel value. So if the same panel value registers with a different ID, the Map entry is updated:

    const registerMountedTabPanel = useStableCallback(
        (panelValue: TabsTab.Value | number, panelId: string) => {
          setMountedTabPanels((prev) => {
            if (prev.get(panelValue) === panelId) {
              return prev;
            }
            const next = new Map(prev);
            next.set(panelValue, panelId);
            return next;
          });
        },
      );
    

    This should work correctly even with different IDs.

    OK, I'm going to take a different approach. Let me look at what exactly changed between v1.4.1 and v1.5.0 in the tabs implementation. The issue says the problem started in v1.5.0.

    Actually wait, let me re-read the issue title more carefully:

    [tabs] Tabs.Panel content not rendered if a child component suspends without boundary within Tabs.Root

    This says "without boundary within Tabs.Root", meaning there's no Suspense boundary inside Tabs.Root, only outside.

    And the issue says "Only when clicking the trigger a second time, the panel is rendered." This suggests:

    1. First click on tab B: panel doesn't render (suspends, fallback shows)
    2. After promise resolves, user clicks tab B again: panel renders

    If the value was preserved (value = "b" after recovery), the user wouldn't need to click again. So the value must NOT be preserved.

    But how? If React retries the state update, value should be "b"...

    OH WAIT. I think I finally understand. The issue might be about the mountedTabPanels Map.

    Let me trace through:

    1. Initial render: TabsRoot with value="a"

      • Panel A: open=true, mounted=true, effect runs, registers with id="base-ui-a"
      • Panel B: open=false, mounted=false, doesn't render (returns null)
    2. User clicks tab B, value changes to "b"

      • Panel A: open=false, mounted=true (was true), effect cleanup unregisters
      • Panel B: open=true, mounted=true (set during render)
      • Panel B renders but suspends
      • React rolls back
    3. After rollback:

      • TabsRoot value is still "a" (the committed state)
      • Panel A is rendered
      • Panel B is not rendered (or its render is rolled back)
      • Panel B's effect never ran, so it never registered
    4. Promise resolves, React retries with value="b"

      • TabsRoot value becomes "b"
      • Panel B tries to render
      • Panel B's mounted starts as true (useState(open) with open=true)
      • Panel B renders... but wait, should it work?

    Hmm, this should work. Unless there's a race condition or something about how the effects run.

    Actually, let me look at the issue from a different angle. The issue mentions PR #4704 as potentially causing the bug. Let me see what changed:

    PR #4704 added:

    1. notifyAutomaticValueChange function
    2. shouldNotifyInitialValueChangeRef
    3. shouldHonorDisabledDefaultValueRef
    4. didRegisterTabsRef
    5. Complex automatic value change logic

    The key change might be in the automatic value change logic. When tabs register and the selected tab is disabled or missing, the code automatically falls back to the first enabled tab.

    But in our scenario, the tab B trigger IS registered (it doesn't suspend). Only the panel suspends. So the automatic value change logic shouldn't affect this.

    Unless... the mountedTabPanels Map is used to determine if a tab is valid?

    Let me check the selectedTabMetadata calculation:

    const selectedTabMetadata = React.useMemo(() => {
        for (const tabMetadata of tabMap.values()) {
          if (tabMetadata != null && tabMetadata.value === value) {
            return tabMetadata;
          }
        }
        return undefined;
      }, [tabMap, value]);
    

    This uses tabMap, not mountedTabPanels. So the panel registration shouldn't affect the selected tab metadata.

    Wait, I just realized something. The tabMap is for tabs (triggers), and mountedTabPanels is for panels. They're separate!

    So the automatic value change logic only cares about tabs, not panels. And tabs don't suspend in this scenario (only the panel suspends).

    Let me look at this from yet another angle. What if the issue is in the useTransitionStatus hook specifically?

    When Panel B suspends:

    1. Panel B renders with open=true
    2. useTransitionStatus sets mounted=true during render
    3. The panel returns an element
    4. The child suspends
    5. React rolls back

    Now, when React retries:

    1. Panel B renders again with open=true
    2. useState(open) is called again...

    But wait, does React call useState again if the component was rolled back? Or does it reuse the same state?

    In React's Suspense model, when a render is rolled back:

    • The component instance is discarded
    • On retry, a new render is started
    • useState is called with the same initial value
    • The state update that was in progress (setMounted(true)) is NOT applied because the render was rolled back

    So on retry:

    • useState(open) with open=true returns [true, setMounted]
    • But the if (open && !mounted) check: open=true, mounted=true, so the condition is false
    • mounted stays true

    Hmm, so mounted should be true on retry. The panel should render.

    Unless... there's something about how React handles state updates that happen during a suspended render.

    Actually, I think the issue might be more subtle. Let me think about this:

    When React rolls back a suspended render:

    • The component tree is rolled back
    • Any state updates that were made during the render are discarded
    • But the component instances are also discarded

    On retry, React starts fresh:

    • New component instances are created
    • useState(open) initializes mounted to open
    • Since open is still true (the state update that triggered this render is still pending), mounted is initialized to true

    So the panel should render on retry!

    Unless... the issue is that the value state update is also rolled back?

    Wait, let me reconsider. When setValue("b") is called and React starts rendering:

    1. React updates TabsRoot's state to value="b"
    2. React renders TabsRoot
    3. Panel B suspends
    4. React catches at Suspense boundary
    5. React rolls back...

    What does "rolls back" mean exactly?

    In React 18, when a render is interrupted by Suspense:

    • The work in progress is discarded
    • The pending state update is NOT discarded - it's retried
    • But the render that was in progress is discarded

    So when React retries:

    • TabsRoot still has the pending update value="b"
    • The render continues from the Suspense boundary
    • TabsRoot is rendered again with value="b"
    • Panel B renders again
    • This time, the child doesn't suspend (promise resolved)
    • The render completes

    So the panel should render! Unless there's something wrong with the current implementation.

    Let me look at the current code more carefully. Maybe there's a specific issue with how useTransitionStatus handles this case.

    Actually, let me look at the code change mentioned in the issue - PR #4704. The issue says it was introduced by this PR. Let me see what it changed in the TabsRoot:

    The main change in PR #4704 was the automatic value change logic:

    useIsoLayoutEffect(() => {
        if (isControlled) {
          return;
        }
    
        if (tabMap.size === 0) {
          if (!didRegisterTabsRef.current || value === null) {
            return;
          }
          commitAutomaticValueChange(null, REASONS.missing);
          return;
        }
    
        didRegisterTabsRef.current = true;
    
        const selectionIsDisabled = selectedTabMetadata?.disabled;
        const selectionIsMissing = selectedTabMetadata == null && value !== null;
    
        // ...
    
        if (selectionIsDisabled || selectionIsMissing) {
          const fallbackValue = firstEnabledTabValue ?? null;
          // ...
          commitAutomaticValueChange(fallbackValue, fallbackReason);
          return;
        }
    
        if (shouldNotifyInitialValueChange && selectedTabMetadata != null) {
          notifyAutomaticValueChange(value, REASONS.initial);
          shouldNotifyInitialValueChangeRef.current = false;
        }
      }, [...]);
    

    This effect runs when tabs register. When value !== null and selectedTabMetadata == null (selection is missing), it falls back to the first enabled tab.

    But in our case, tab B IS in the tabMap (it's a trigger, not a panel). So selectedTabMetadata should not be null.

    Unless... wait. The tabMap is populated when tabs register themselves. What if a tab's registration depends on something that also suspends?

    Let me look at how tabs register:

    <tool_call>

    I found the key insight! Let me look at the TabsRoot automatic value change logic more carefully:

    <tool_call> <function=bash_terminal> <parameter=command> cd /base-ui && git show 2540428f0 -- packages/react/src/tabs/root/TabsRoot.tsx | head -200 </tool_call>

  38. Qwen Assistant

    Let me run the git show command again properly.

  39. Qwen Assistant

    Let me look at the test file for TabsPanel to understand how tests are structured and then look more carefully at the issue. I need to understand the exact flow of what happens when a tab panel suspends.

  40. Qwen Assistant

    Let me look at the useOpenChangeComplete hook which is used in TabsPanel:

  41. Qwen Assistant

    Let me look at the useControlled hook to understand how it handles state initialization:

  42. Qwen Assistant

    Let me look at the useRenderElement hook to understand how children are handled:

  43. Qwen Assistant

    Let me look at the useRenderElement hook to understand how the element is rendered.

  44. Qwen Assistant

    Let me create a test script to reproduce this issue and understand the problem better.

  45. Qwen Assistant

    Let me re-analyze the issue more carefully. The key issue is that when a panel suspends and the suspense boundary is outside Tabs.Root, the panel content is not rendered on the first tab click.

    Looking at the TabsPanel code:

    const open = value === selectedValue;
    const { mounted, transitionStatus, setMounted } = useTransitionStatus(open);
    const hidden = !mounted;
    // ...
    const shouldRender = keepMounted || mounted;
    if (!shouldRender) {
      return null;
    }
    

    The issue is in useTransitionStatus. When open is true, it calls setMounted(true) during render:

    if (open && !mounted) {
      setMounted(true);
      setTransitionStatus('starting');
    }
    

    But here's the problem: when a child component suspends, React interrupts the render and rolls back. The setMounted(true) call during render is part of the interrupted render, so it gets rolled back too!

    When React retries after the promise resolves:

    1. useState(open) initializes mounted to open (which is true since value should still be "b")
    2. The if (open && !mounted) check: open is true, mounted is true (from initialization), so the condition is false
    3. mounted stays true

    Wait, that should work... Let me think again.

    Actually, the problem might be that after the suspense recovery, the Tabs.Root value has changed back to the default value "a". But that doesn't match the issue description which says clicking a second time works.

    Let me re-read the issue:

    Only when clicking the trigger a second time, the panel is rendered.

    So after recovery:

    • Tab B trigger appears selected (visually)
    • But Panel B content is NOT rendered
    • Clicking tab B again shows the content

    This means after recovery, value is "b" (tab B is selected), but Panel B's mounted is somehow false.

    Wait! I think I found it! The issue is:

    1. User clicks tab B, value changes to "b"

    2. Panel B renders, open = true

    3. useState(open) - open is true, so mounted is initialized to true

    4. if (open && !mounted) - open=true, mounted=true, condition is FALSE, so setMounted is NOT called

    5. Panel renders its children

    6. SuspendingChild suspends!

    7. React rolls back the render

    8. Promise resolves, React retries

    9. Panel B renders again

    10. useState(open) - BUT HERE'S THE KEY: useState preserves state between renders of the same component instance. But when React rolls back due to suspense, does it reset state?

    Actually, when React suspends during render and then retries, it creates a NEW fiber for the component. The useState initialization happens again. So mounted is initialized to open again.

    But wait - open should still be true because value is still "b"...

    OH WAIT! I think I finally see it!

    The problem might be about WHEN the value changes. Let me trace through more carefully:

    1. Initial render: value = "a"
    2. User clicks tab B
    3. onValueChange is called, which calls setValue("b")
    4. React re-renders TabsRoot with value = "b"
    5. Panel B's open becomes true
    6. Panel B's useState(open) initializes mounted = true
    7. The if (open && !mounted) check is skipped (mounted is already true from init)
    8. shouldRender = keepMounted || mounted = false || true = true
    9. Panel B renders its element
    10. Panel B renders its children (including SuspendingChild)
    11. SuspendingChild suspends!
    12. React rolls back

    After rollback, when React retries: 13. TabsRoot re-renders with value = "b" (the state update was scheduled) 14. Panel B's open is true 15. Panel B's useState(open) - but wait, is this a new component instance?

    Here's where it gets tricky. When React suspends:

    • The suspended fiber is marked as "suspended"
    • React shows the fallback
    • When the promise resolves, React retries the suspended fiber

    The key question: does useState re-initialize on retry?

    According to React's behavior, useState initialization only happens on the FIRST render. On subsequent renders (including retries after suspense), useState returns the current state value.

    But when React rolls back a suspended render, the render was never completed. So the state update setMounted(true) from step 6 was never actually applied because... wait, no. useState(open) returns [true, setMounted] because open is true. The initial value of mounted is true.

    So on retry:

    • useState(open) returns [true, setMounted] because:
      • If this is considered a "first render" after rollback, initialization gives mounted = open = true
      • If this is considered a "subsequent render", state was never updated (setMounted was never called), so mounted is still the initial value true

    In both cases, mounted should be true!

    Hmm, let me reconsider. Maybe the issue is different. Let me look at the actual flow more carefully.

    Actually, wait. I just realized something. The useState(open) initialization uses the value of open at initialization time. But on a re-render, useState doesn't re-read the initial value - it returns the stored state.

    So:

    1. Initial mount: open = false (value is "a")
    2. useState(false) → mounted = false
    3. User clicks tab B, value becomes "b"
    4. Re-render: open = true
    5. useState returns stored state: mounted = false (not re-initialized!)
    6. if (open && !mounted): open=true, mounted=false → TRUE!
    7. setMounted(true) is called during render
    8. setTransitionStatus('starting') is called during render
    9. Panel renders
    10. Child suspends
    11. React rolls back!

    After rollback:

    • The render-phase state updates (setMounted(true), setTransitionStatus('starting')) are discarded
    • The component's state is still mounted = false (from before the render started)
    • The component instance is preserved (it wasn't unmounted)

    When React retries: 12. open = true (value is still "b") 13. useState returns stored state: mounted = false (the update was rolled back!) 14. if (open && !mounted): open=true, mounted=false → TRUE! 15. setMounted(true) is called again 16. shouldRender = keepMounted || mounted = false || false = false!

    Wait, that's the bug! The mounted variable in the render is still false even though setMounted(true) was called!

    The issue is that setMounted(true) schedules a state update, but the current render's value of mounted is still false. React batches state updates and applies them after the render completes.

    So when we check shouldRender = keepMounted || mounted, mounted is still false even though we've called setMounted(true)!

    Actually wait, let me re-read the code:

    const [mounted, setMounted] = React.useState(open);
    
    if (open && !mounted) {
      setMounted(true);
      setTransitionStatus('starting');
    }
    
    // ...
    
    const shouldRender = keepMounted || mounted;
    if (!shouldRender) {
      return null;
    }
    

    Yes! The mounted variable in this render is false (the value before the state update). setMounted(true) schedules an update, but mounted doesn't change until the NEXT render.

    So when a panel first opens (when open changes from false to true):

    • useState returns the old mounted value (false)
    • if (open && !mounted) triggers setMounted(true)
    • But mounted is still false in this render!
    • shouldRender = keepMounted || mounted = false || false = false
    • Panel returns null!

    But wait, this would mean the panel NEVER renders on first open, which is clearly not the intended behavior. So there must be something I'm missing...

    OH! I see it now. Look at the useState initialization:

    const [mounted, setMounted] = React.useState(open);
    

    This uses open as the initial value. On the FIRST render of the component (mount), mounted is initialized to the current value of open.

    But on SUBSEQUENT renders (re-renders), useState ignores the initial value and returns the stored state.

    So the flow is:

    1. Component mounts with open = false
    2. useState(false) → mounted = false (initialization)
    3. User clicks, value changes, open = true
    4. Re-render
    5. useState(false) → returns stored mounted = false (initial value is ignored!)
    6. if (open && !mounted) → setMounted(true) is called
    7. But mounted is still false in this render!
    8. shouldRender = false
    9. Panel returns null!
    10. NEXT render: mounted = true (the update was applied)
    11. shouldRender = true
    12. Panel renders!

    So the panel has a one-render delay! When you first click a tab, the panel doesn't render until the NEXT render (after setMounted(true) is applied).

    This is the bug! The setMounted(true) is called during render, but its effect isn't visible until the next render. In normal operation, the next render happens quickly (synchronously or on next frame), so the delay is not noticeable.

    But when the panel suspends:

    1. Panel starts rendering with open = true
    2. useState returns mounted = false
    3. if (open && !mounted) → setMounted(true) is called
    4. shouldRender = false
    5. Panel returns null
    6. But wait, if panel returns null, the child never renders, so there's no suspense!

    Hmm, that doesn't match the issue description either. Let me re-think...

    Actually, let me re-read the useTransitionStatus code:

    const [mounted, setMounted] = React.useState(open);
    

    This line is INSIDE the useTransitionStatus hook. The open parameter is passed from the caller.

    On mount:

    • open = false (Panel B is not selected)
    • useState(false) → mounted = false
    • if (open && !mounted) → open = false, condition is FALSE
    • Returns { mounted: false, ... }

    After clicking tab B:

    • open = true
    • Re-render
    • useState(false) → useState ignores initial value, returns stored mounted = false
    • Wait, that's wrong! useState(open) - the initial value open is true now, but useState ignores it on re-renders

    Actually wait, I need to think about this more carefully. useState(initialValue) - the initialValue argument is only used on the FIRST render. On subsequent renders, React returns the current state value.

    So:

    1. First render (mount): useState(false) returns [false, setMounted] because that's the initial value
    2. Second render (after click): useState(true) is called, but React ignores the true and returns [false, setMounted] because that's the stored state

    So after clicking tab B:

    • useState returns mounted = false
    • if (open && !mounted): true && true → TRUE
    • setMounted(true) is called
    • But mounted is still false in this render
    • shouldRender = false
    • Panel returns null
    • No suspense because panel never rendered!

    Then in the NEXT render:

    • useState returns mounted = true (the update was applied)
    • shouldRender = true
    • Panel renders
    • Child suspends

    So the flow is actually:

    1. Panel B starts rendering, returns null (because mounted is false)
    2. NEXT render: mounted is true, panel renders
    3. Child suspends
    4. Suspense shows fallback
    5. Promise resolves
    6. React retries
    7. mounted is still true (it was committed)
    8. Panel renders
    9. Child renders (no more suspense)

    Hmm, but this means the panel SHOULD render after the first click (in the second render). The issue says it doesn't render on the first click...

    Let me re-read the issue description again:

    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.Root component), the panel content is not rendered when opening a tab for the first time.

    "the suspense unmounts the tab root" - this is a key detail! The suspense boundary is OUTSIDE Tabs.Root. When the panel suspends, the ENTIRE Tabs.Root is unmounted.

    So the flow is:

    1. Initial render: value = "a", Panel A shows, Panel B has mounted = false
    2. Click tab B: value = "b"
    3. Panel B re-render: mounted = false (stored state), setMounted(true) called
    4. NEXT render: Panel B: mounted = true, shouldRender = true
    5. Panel B renders
    6. Child suspends!
    7. Suspense catches, unmounts entire Tabs.Root (including all panels)
    8. Fallback shows
    9. Promise resolves
    10. React retries from Suspense boundary
    11. Tabs.Root REMOUNTS with fresh state
    12. value = defaultValue = "a" (fresh state)
    13. Panel B: open = false, mounted = false (fresh state, initialized to open which is false)
    14. Panel B returns null

    Wait, but then the user would see tab A selected, not tab B. The issue says clicking a second time works, which would make sense if value reverted to "a".

    But the issue says "the panel content is not rendered when opening a tab for the first time". This implies the tab IS selected but the panel content doesn't show.

    Hmm, I'm confused. Let me look at this from a different angle.

    Maybe the issue is that after step 10-11, the value is still "b" because the Suspense retry happens in the same batch as the click? But Tabs.Root was unmounted, so its state should be lost...

    Unless the Suspense doesn't actually unmount Tabs.Root? Let me think about when React actually unmounts components during Suspense...

    Actually, I think I've been confusing two scenarios:

    Scenario A: Suspense during initial render (mount phase)

    • Component starts rendering
    • Suspends
    • React shows fallback
    • Component never commits
    • When promise resolves, React retries the render
    • State IS preserved because the component was never committed/unmounted

    Scenario B: Suspense after commit

    • Component is already rendered (committed)
    • Something triggers a re-render (e.g., user clicks)
    • During re-render, component suspends
    • React shows fallback
    • The component subtree is unmounted
    • When promise resolves, React remounts
    • State is NOT preserved

    In our case, the user clicks tab B after the initial render (commit). So this is Scenario B:

    • Tabs.Root is already committed with value = "a"
    • User clicks, value changes to "b"
    • Panel B renders but suspends
    • React catches at Suspense boundary
    • React unmounts the entire Tabs.Root subtree
    • Fallback is shown
    • When promise resolves, React remounts Tabs.Root
    • Tabs.Root starts fresh with value = "a" (defaultValue)

    So after recovery, value is "a", not "b". The user sees tab A selected. They need to click tab B again to see its content.

    But the issue says the panel doesn't render "when opening a tab for the first time" and works "when clicking the trigger a second time". This matches!

    So the issue is: after the suspense recovery, the value reverts to the default. The user has to click the tab again.

    But the issue says this worked in v1.4.1. How could it have worked?

    Maybe in v1.4.1, the panel was always rendered (even when hidden), so the Suspense would catch before the value reverted? Or maybe the panel registration logic was different?

    Let me look at what changed between v1.4.1 and v1.5.0 that could affect this. The issue mentions PR #4704.

    Actually, I think I need to step back and understand what the expected behavior should be. If a tab panel suspends and the suspense boundary is outside Tabs.Root, should the selected value be preserved?

    In React's Suspense model, when a component suspends after commit, the component subtree is unmounted and its state is lost. So the value reverting to the default is expected behavior.

    But the issue says it worked in v1.4.1. So either:

    1. v1.4.1 had different behavior that preserved the value
    2. The issue description is wrong about v1.4.1 working
    3. There's something else going on

    Let me check the actual v1.4.1 code to see what was different. But I don't have access to that specific version. Let me check the git history instead.

    Actually, I think the real issue might be different. Let me re-read the issue one more time:

    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

    Maybe the issue is NOT about the value reverting. Maybe after recovery, value IS still "b", but the panel's mounted state is somehow reset to false.

    How could that happen?

    1. User clicks tab B
    2. value = "b", Panel B renders
    3. Panel B's mounted = true
    4. Child suspends
    5. Suspense unmounts Tabs.Root
    6. Tabs.Root state is lost (value reverts to "a")

    No wait, if Tabs.Root is unmounted, value reverts to "a". So Panel B would have open = false.

    Unless... the Tabs.Root is NOT actually unmounted? What if the Suspense boundary only catches the suspended component without unmounting the parent?

    Hmm, I think I need to actually run the code and see what happens. Let me try to create a minimal test case.

    Actually, let me look at the issue from yet another angle. The PR #4704 mentions "Fire onValueChange for automatic tab selection". What if the issue is related to the automatic value change logic?

    Looking at the TabsRoot code, after PR #4704:

    useIsoLayoutEffect(() => {
        if (isControlled) {
          return;
        }
    
        if (tabMap.size === 0) {
          if (!didRegisterTabsRef.current || value === null) {
            return;
          }
          commitAutomaticValueChange(null, REASONS.missing);
          return;
        }
    
        didRegisterTabsRef.current = true;
    
        const selectionIsDisabled = selectedTabMetadata?.disabled;
        const selectionIsMissing = selectedTabMetadata == null && value !== null;
    
        if (!selectionIsDisabled && value === initialDefaultValueRef.current) {
          shouldHonorDisabledDefaultValueRef.current = false;
        }
    
        if (
          shouldHonorDisabledDefaultValueRef.current &&
          selectionIsDisabled &&
          value === initialDefaultValueRef.current
        ) {
          return;
        }
    
        const shouldNotifyInitialValueChange = shouldNotifyInitialValueChangeRef.current;
    
        if (selectionIsDisabled || selectionIsMissing) {
          const fallbackValue = firstEnabledTabValue ?? null;
    
          if (value === fallbackValue) {
            shouldNotifyInitialValueChangeRef.current = false;
            return;
          }
    
          let fallbackReason: TabsRoot.ChangeEventReason = REASONS.missing;
    
          if (shouldNotifyInitialValueChange) {
            fallbackReason = REASONS.initial;
          } else if (selectionIsDisabled) {
            fallbackReason = REASONS.disabled;
          }
    
          commitAutomaticValueChange(fallbackValue, fallbackReason);
          return;
        }
    
        if (shouldNotifyInitialValueChange && selectedTabMetadata != null) {
          notifyAutomaticValueChange(value, REASONS.initial);
          shouldNotifyInitialValueChangeRef.current = false;
        }
      }, [...]);
    

    This effect checks if the selected tab is missing or disabled, and if so, falls back to the first enabled tab. The key is selectionIsMissing = selectedTabMetadata == null && value !== null.

    But selectedTabMetadata is about the TAB (trigger), not the PANEL. So this shouldn't be affected by panel suspension.

    Hmm, but wait. What if the issue is about mountedTabPanels? Let me look at how it's used.

    Actually, I think I need to approach this differently. Let me look at the specific change that might have caused this issue. The issue mentions that v1.4.1 works but v1.5.0 doesn't. The key change in v1.5.0 is the PR #4704.

    But wait, the issue also mentions:

    Potentially a side effect of https://github.com/mui/base-ui/pull/4704

    So the author of the issue isn't sure. Let me look at what changed in the TabsPanel between v1.4.1 and v1.5.0.

    Actually, I realize I should look at the actual test case to understand the expected behavior. Let me search for any existing tests related to Suspense.

    Let me also look at the useTransitionStatus hook more carefully. The issue might be in how it handles the mounted state during suspense.

    Actually, I think I finally understand the issue!

    The problem is in the useTransitionStatus hook:

    const [mounted, setMounted] = React.useState(open);
    
    if (open && !mounted) {
      setMounted(true);
      setTransitionStatus('starting');
    }
    

    When a component suspends:

    1. The render is interrupted
    2. State updates made during the render (like setMounted(true)) are NOT applied
    3. When React retries, the component re-renders with the OLD state

    But here's the key: useState(open) uses open as the initial value. On retry, if the component instance is preserved (not unmounted), useState returns the stored state. But if the component WAS unmounted (as in our scenario where Tabs.Root is unmounted), then on remount, useState(open) re-initializes with the current value of open.

    So:

    1. Tabs.Root unmounts (state lost)
    2. Tabs.Root remounts
    3. value = defaultValue = "a" (default state)
    4. Panel B: open = false
    5. useState(false) → mounted = false
    6. shouldRender = false
    7. Panel B returns null

    This is what I described before. The panel doesn't render because value reverted to "a".

    But the issue says clicking a second time works. If value is "a", clicking tab B would change it to "b", and Panel B would render.

    So the expected behavior in v1.4.1 must have been different. Perhaps in v1.4.1, the panel was rendered even when hidden (with children set to undefined), so the Suspense would catch during render and the value would be preserved somehow.

    OR, perhaps the issue is different: after the Suspense recovery, value is still "b" (the click update is preserved), but the panel's mounted state is false.

    Let me think about this. When the Suspense boundary is outside Tabs.Root and the panel suspends:

    1. Tabs.Root is unmounted
    2. All of its state is lost, including value
    3. Tabs.Root remounts
    4. value is re-initialized to defaultValue

    But wait! The value state update was made by the click handler. When Tabs.Root unmounts, does the pending state update get lost?

    In React, when a component unmounts:

    • All state is cleared
    • Pending state updates are discarded

    So yes, the value = "b" update would be lost when Tabs.Root unmounts.

    Hmm, but what if the Suspense doesn't actually unmount Tabs.Root? What if it just "rolls back" the render?

    Let me think about this more carefully. In React's Suspense model:

    Suspense during commit (after component was already rendered):

    • The component subtree is rolled back
    • The component is NOT technically "unmounted" - it's rolled back to its previous committed state
    • Effects are NOT cleaned up
    • When the promise resolves, React retries the render
    • The component instance is preserved
    • State is preserved (it was committed before the suspended render)

    Wait, is that right? Let me reconsider...

    When Panel B suspends after the user clicks tab B:

    1. TabsRoot's previous committed state: value = "a"
    2. User clicks tab B, triggering setValue("b")
    3. React starts rendering with value = "b"
    4. Panel B renders but suspends
    5. React catches at Suspense boundary
    6. React rolls back the render to the previous committed state (value = "a")
    7. Fallback is shown
    8. Promise resolves
    9. React retries the render with value = "b" (the pending state update)

    If this is correct, then after step 9, value should be "b" and Panel B should render!

    But the issue says it doesn't render. So either:

    1. React actually unmounts the component (clearing state)
    2. There's something else going on

    Let me look at React's actual behavior. When a component suspends during an update:

    Actually, I think the behavior depends on whether the component was already committed before the update:

    Case 1: Component suspends during initial mount

    • Component was never committed
    • React rolls back and shows fallback
    • When promise resolves, React retries the mount
    • State IS preserved (useState is called again with initial values)

    Case 2: Component suspends during an update (after commit)

    • Component was committed
    • React rolls back the update
    • If the Suspense boundary is inside the component tree, React shows fallback and keeps the component
    • If the Suspense boundary is OUTSIDE the component tree, React unmounts the entire subtree

    In our case, the Suspense boundary is OUTSIDE Tabs.Root. So when Panel B (inside Tabs.Root) suspends, React unmounts the entire Tabs.Root subtree!

    So:

    1. Tabs.Root unmounts
    2. All state is lost (value = "a" is gone, the pending "b" update is discarded)
    3. Fallback is shown
    4. Promise resolves
    5. React remounts from the Suspense boundary
    6. Tabs.Root mounts with fresh state (value = defaultValue = "a")

    OK so now I'm pretty sure the value reverts to "a" after recovery. The user needs to click tab B again.

    But the issue says this worked in v1.4.1. So in v1.4.1, somehow the value was preserved. How?

    One possibility: In v1.4.1, the panel was always rendered (even when hidden), which means the Suspense would happen during initial mount, not during an update. And during initial mount, React preserves the state (because the component was never committed).

    Let me check the old TabsPanel code again:

    In the old version:

    { children: hidden && !keepMounted ? undefined : children }
    

    The panel always rendered its element, but with undefined children when hidden. This means:

    1. Panel B always rendered its element (even when hidden)
    2. Panel B's children (including SuspendingChild) were only rendered when the panel was visible
    3. But if the panel was hidden, SuspendingChild was never rendered, so no suspense

    In the new version:

    const shouldRender = keepMounted || mounted;
    if (!shouldRender) {
      return null;
    }
    

    The panel returns null when hidden, so it's not rendered at all. This means:

    1. Panel B is only rendered when mounted
    2. When mounted, Panel B renders and SuspendingChild suspends
    3. React catches and shows fallback

    Hmm, but the behavior should be the same in both cases when the panel IS visible. The difference is only when the panel is hidden.

    Wait, but there's another change: the mounted state!

    In the old version, hidden was computed as:

    const hidden = tabPanelValue !== selectedValue;
    

    In the new version, hidden is computed as:

    const hidden = !mounted;
    

    Where mounted comes from useTransitionStatus(open). The mounted state is initialized to open but has a delay because setMounted(true) is called during render.

    So in the old version:

    1. Panel B: hidden = ("b" !== "a") = true
    2. Panel renders element with children = undefined (because hidden)
    3. SuspendingChild is never rendered
    4. No suspense

    After clicking tab B: 5. hidden = ("b" !== "b") = false 6. Panel renders element with children 7. SuspendingChild renders and suspends!

    In the new version:

    1. Panel B: mounted = false (initialized to open = false)
    2. hidden = !false = true
    3. shouldRender = keepMounted || mounted = false || false = false
    4. Panel returns null!

    After clicking tab B: 5. mounted is still false (setMounted(true) was called in previous render but hasn't taken effect)

    Wait, that's wrong. After clicking tab B: 6. Panel B re-renders with open = true 7. useState returns mounted = false (stored state, not re-initialized) 8. if (open && !mounted) → setMounted(true) is called 9. But mounted is still false in this render 10. shouldRender = keepMounted || mounted = false || false = false 11. Panel returns null! 12. SuspendingChild is never rendered! 13. No suspense!

    NEXT render: 14. useState returns mounted = true (the update was applied) 15. shouldRender = keepMounted || mounted = false || true = true 16. Panel renders! 17. SuspendingChild renders and suspends!

    So in the new version, the panel has a one-render delay before it starts rendering! This means:

    1. Click tab B
    2. Panel B doesn't render (mounted = false)
    3. Next render: Panel B renders, SuspendingChild suspends
    4. Suspense catches, unmounts Tabs.Root
    5. Fallback shows
    6. Promise resolves
    7. Tabs.Root remounts with value = "a"
    8. Panel B: open = false, mounted = false
    9. Panel B returns null

    In the old version:

    1. Click tab B
    2. Panel B renders (hidden = false, children are rendered)
    3. SuspendingChild suspends
    4. Suspense catches, unmounts Tabs.Root
    5. Fallback shows
    6. Promise resolves
    7. Tabs.Root remounts with value = "a"
    8. Panel B: hidden = true (value is "a")
    9. Panel B renders element with children = undefined

    Wait, in the old version, Panel B still rendered (with undefined children). But that doesn't explain why the issue says v1.4.1 worked.

    Actually, let me re-read the issue more carefully:

    The panel content is not rendered also when first opening a tab like it did in v1.4.1.

    Hmm, "also when first opening a tab" - this suggests that the panel content was rendered in v1.4.1 even after the first click. But if the value reverts to "a", the panel shouldn't be selected...

    Unless the issue is about a different scenario. What if the initial defaultValue is "b" (the tab that suspends)?

    Let me check the Stackblitz example:

    <Tabs.Root defaultValue="a">
    

    No, defaultValue is "a". So tab A is selected initially, and tab B is the one that suspends.

    OK, I think I need to just test this. Let me create a test file and run it to see the actual behavior.

    Actually wait, I just realized something. The issue says:

    If a tab panel has a child that suspends and the suspense unmounts the tab root

    What if the issue is NOT about the value reverting, but about the panel's internal state? What if after recovery, value IS "b" (for some reason), but the panel's mounted state is false?

    How could value be "b" after recovery? If the Suspense doesn't unmount Tabs.Root but instead just rolls back...

    Actually, I think this depends on how React handles the Suspense. Let me look at this from a different perspective.

    When a child component suspends during an UPDATE (not initial mount), and the Suspense boundary is outside the parent component:

    1. React starts rendering the update
    2. Child suspends
    3. React catches at Suspense boundary
    4. React shows fallback
    5. React DOES NOT unmount the parent - instead, it rolls back the update to the parent's last committed state
    6. The parent component remains mounted
    7. When promise resolves, React retries the update

    If this is correct, then Tabs.Root would remain mounted with its previous state (value = "a"), and the pending update (value = "b") would be retried.

    So the flow would be:

    1. Tabs.Root committed with value = "a"
    2. User clicks tab B, setValue("b")
    3. React renders TabsRoot with value = "b"
    4. Panel B suspends
    5. React rolls back to value = "a"
    6. Fallback shows
    7. Promise resolves
    8. React retries with value = "b"
    9. Tabs.Root renders with value = "b"
    10. Panel B renders... but does it?

    In step 10, Panel B's open = true. But what about its mounted state?

    If Panel B was previously rendered (committed) with mounted = false, and the update was rolled back, then Panel B is still committed with mounted = false. When React retries with value = "b":

    • Panel B re-renders
    • useState returns mounted = false (still committed with this value)
    • if (open && !mounted) → setMounted(true) is called
    • But mounted is still false in this render!
    • shouldRender = false
    • Panel returns null!

    NEXT render:

    • mounted = true
    • shouldRender = true
    • Panel renders!

    So the bug is: when the panel first opens (open changes from false to true), the mounted state is still false in the current render because setMounted(true) is called during render. This means the panel has a one-render delay before it starts rendering.

    In normal operation, this delay is fine because React quickly re-renders. But when the panel suspends during this delayed render, the suspense causes the update to be rolled back, and on retry, the panel STILL has mounted = false!

    Wait, but if the update was rolled back, the next render would be a retry with the same value. Let me trace through more carefully:

    1. Tabs.Root committed with value = "a"
    2. Panel B committed with mounted = false, open = false
    3. User clicks tab B, setValue("b")
    4. React renders with value = "b"
    5. Panel B renders:
      • open = true
      • useState returns mounted = false (committed value)
      • if (open && !mounted) → setMounted(true)
      • shouldRender = false
      • Returns null!
    6. Since Panel B returned null, its child (SuspendingChild) is not rendered
    7. No suspense!
    8. Render completes
    9. Tabs.Root is committed with value = "b"
    10. Panel B is committed with mounted = true (the update from step 5 was applied)

    Wait, but in step 5, setMounted(true) was called. Even though the render returned null, the state update is still applied after the render completes. So in step 10, mounted = true.

    NEXT render (some event triggers it, or React auto-schedules it): 11. Panel B renders: - open = true - useState returns mounted = true - shouldRender = true - Renders element - SuspendingChild renders and suspends! 12. React catches at Suspense boundary 13. React rolls back

    Now, what happens in step 13? React rolls back the render. Panel B was committed with mounted = true. After rollback:

    • Panel B still has mounted = true (it was committed)
    • The pending render (which would have suspended) is discarded

    After promise resolves: 14. React retries with value = "b" 15. Panel B renders: - open = true - useState returns mounted = true (still committed) - shouldRender = true - Renders element - SuspendingChild renders... no more suspense (promise resolved) 16. Panel B content is shown!

    So in this flow, the panel SHOULD render after the promise resolves. This doesn't match the issue.

    Unless... the rollback in step 13 actually changes the state? Let me think about this more carefully.

    When React rolls back a suspended render:

    • The render that was in progress is discarded
    • Any state updates made during that render are NOT applied
    • The component keeps its last committed state

    So in step 12-13:

    • React was rendering with value = "b"
    • Panel B was rendering with mounted = true
    • SuspendingChild suspended
    • React rolled back
    • Panel B's state is still mounted = true (committed value)

    After promise resolves and React retries:

    • value is still "b" (pending update)
    • Panel B's mounted is still true (committed value)
    • shouldRender = true
    • Panel renders

    So the panel should render! This contradicts the issue.

    Hmm, let me reconsider. Maybe the issue is about a specific edge case that I'm not considering.

    Actually, I just realized something. In my analysis, I assumed that the panel's mounted state was committed before the suspense. But what if the panel was never committed with mounted = true?

    Let me trace through a different scenario:

    1. Tabs.Root committed with value = "a"
    2. Panel B was never rendered (it returned null because open = false, mounted = false, shouldRender = false)

    Wait, if shouldRender was false, the panel returned null. Was it committed with null, or was it never rendered at all?

    In React, if a component returns null, it IS still committed - it just renders nothing. So Panel B IS committed with mounted = false.

    OK so:

    1. Panel B committed with mounted = false
    2. User clicks tab B, setValue("b")
    3. React renders with value = "b"
    4. Panel B renders:
      • open = true
      • useState returns mounted = false (committed value)
      • if (open && !mounted) → setMounted(true)
      • shouldRender = false
      • Returns null!
    5. Render completes
    6. Tabs.Root committed with value = "b"
    7. Panel B committed with mounted = true (the update was applied)

    But wait, in step 4, Panel B returned null. This means the component finished rendering. So the state update (setMounted(true)) IS applied.

    NEXT render: 8. Panel B renders:

    • open = true
    • useState returns mounted = true
    • shouldRender = true
    • Renders element
    • SuspendingChild suspends!
    1. React catches, rolls back
    2. Panel B is committed with mounted = true (the update from step 7)
    3. After rollback, Panel B still has mounted = true
    4. Promise resolves
    5. React retries
    6. Panel B renders with mounted = true, shouldRender = true
    7. SuspendingChild renders (no more suspense)
    8. Content is shown!

    So again, the panel should render! This is still not matching the issue.

    Wait, let me reconsider the "rollback" behavior. When React rolls back a suspended render:

    • The component subtree that was being rendered is discarded
    • If the Suspense boundary is outside the component tree, the ENTIRE component tree is discarded
    • This includes any uncommitted state updates

    So in step 9:

    • React rolls back the render
    • Tabs.Root's pending state update (value = "b" from step 2) was already committed in step 6
    • But Panel B's pending state update (mounted = true from step 7) was already committed
    • After rollback, Tabs.Root has value = "b" (committed) and Panel B has mounted = true (committed)

    Hmm, but the issue says the panel doesn't render. So there must be something else going on.

    Let me re-read the issue one more time:

    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.Root component), the panel content is not rendered when opening a tab for the first time.

    "the suspense unmounts the tab root" - this explicitly says the tab root is UNMOUNTED. Not rolled back, but UNMOUNTED.

    So when the panel suspends and the Suspense boundary is outside Tabs.Root:

    1. React unmounts Tabs.Root
    2. All state is lost
    3. Tabs.Root is removed from the tree
    4. Fallback is shown
    5. Promise resolves
    6. React remounts Tabs.Root from scratch
    7. Tabs.Root's state is re-initialized (value = defaultValue = "a")
    8. Panel B: open = false, mounted = false
    9. shouldRender = false
    10. Panel B returns null

    After step 10, tab B is NOT selected (value is "a"). The user needs to click tab B again.

    But the issue says "Only when clicking the trigger a second time, the panel is rendered." This matches!

    And the issue says "The panel content is not rendered also when first opening a tab like it did in v1.4.1." This suggests that in v1.4.1, after the first click (and suspense recovery), the panel content WAS rendered.

    So in v1.4.1, somehow the value was preserved (or the panel was rendered even with value = "a").

    Let me look at what changed. The key change in v1.5.0 is the transition status logic. In v1.4.1, the panel was rendered differently.

    Wait, but in my analysis, even in v1.4.1, after Tabs.Root unmounts and remounts, value would revert to "a". So how could the panel have been rendered?

    Unless the Suspense boundary behavior was different in v1.4.1. But that doesn't make sense - Suspense is a React feature, not a Base UI feature.

    Let me think about this differently. Maybe in v1.4.1, the panel was always rendered (with or without children), so the SuspendingChild was part of the render tree even when the panel was hidden. This would mean:

    1. Initial render: Panel B is rendered with SuspendingChild (but with hidden style)
    2. SuspendingChild suspends during initial render
    3. Suspense catches and shows fallback
    4. Promise resolves
    5. React retries
    6. Panel B renders with SuspendingChild
    7. SuspendingChild renders (no more suspense)
    8. Panel B content is shown

    But this doesn't match the issue description which says "when opening a tab for the first time". The initial defaultValue is "a", not "b".

    Actually wait, let me re-read the Stackblitz example:

    function SuspendingChild() {
      return <div>{use(dataPromise)}</div>;
    }
    
    export default function App() {
      return (
        <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>
      );
    }
    

    defaultValue is "a", so tab A is selected initially. Panel A has no suspense. Tab B has the suspending child.

    In v1.4.1, if the panel was always rendered (with hidden style), then:

    1. Initial render: Tab A selected, Panel A shown
    2. Panel B is rendered but hidden (hidden style, or children = undefined)
    3. SuspendingChild is NOT rendered because Panel B's children are undefined (or the panel is hidden)
    4. No suspense on initial render

    Then when user clicks tab B: 5. Tab B selected, Panel B's children are rendered 6. SuspendingChild suspends 7. Suspense catches, unmounts Tabs.Root 8. After recovery, value = "a" (reverted) 9. Tab A is selected again

    This is the same as v1.5.0 behavior. So how did v1.4.1 work?

    Unless... the panel's children were ALWAYS rendered, even when hidden. In that case:

    1. Initial render: Tab A selected
    2. Panel B is rendered with SuspendingChild
    3. SuspendingChild suspends during initial render
    4. Suspense catches and shows fallback
    5. Tabs.Root is rolled back (not unmounted, because it was never committed)
    6. Promise resolves
    7. React retries the render
    8. Tab A is still selected (default)
    9. Panel A is shown
    10. Panel B is rendered with SuspendingChild
    11. SuspendingChild renders (no more suspense)
    12. Panel B is hidden (but in the DOM)

    So in v1.4.1, the SuspendingChild was rendered during initial mount, which caused suspense. After recovery, the children were already in the tree (but hidden).

    In v1.5.0, the panel returns null when hidden, so SuspendingChild is never rendered until the panel is shown. This causes the issue:

    1. Initial render: Tab A selected
    2. Panel B returns null (hidden)
    3. No suspense

    When user clicks tab B: 4. Panel B should render, but mounted = false (one-render delay) 5. Panel B returns null 6. Next render: mounted = true 7. Panel B renders, SuspendingChild suspends 8. Suspense catches, unmounts Tabs.Root (because it was committed) 9. After recovery, value = "a" 10. Panel B returns null

    So the key difference is: in v1.4.1, the suspense happened during initial mount (state preserved), while in v1.5.0, the suspense happens after an update (state lost).

    Now, the fix should ensure that the panel renders immediately when open changes, without the one-render delay. Or it should preserve the state across the Suspense boundary.

    The simplest fix is to change the logic so that when open is true, the panel renders immediately (without waiting for mounted to become true).

    Looking at the code:

    const { mounted, transitionStatus, setMounted } = useTransitionStatus(open);
    const hidden = !mounted;
    // ...
    const shouldRender = keepMounted || mounted;
    if (!shouldRender) {
      return null;
    }
    

    The issue is that mounted starts as open (from useState initialization), but on a re-render, it uses the stored state (which might be false). Then setMounted(true) is called, but it takes effect in the next render.

    The fix should be: when open is true, always render the panel (ignore mounted). Or use a different approach to track mounted.

    Actually, looking at useTransitionStatus more carefully:

    const [mounted, setMounted] = React.useState(open);
    
    if (open && !mounted) {
      setMounted(true);
      setTransitionStatus('starting');
    }
    

    The if block sets mounted = true when open is true and mounted is false. But mounted in this render is still the old value. The update takes effect in the next render.

    The fix could be to compute mounted inline instead of using state:

    // Instead of:
    // const hidden = !mounted;
    // Use:
    const hidden = !open;
    

    But this would break the transition animation logic. The mounted state is used to track when the animation starts and ends.

    Actually, the fix should be to ensure that the panel renders when open is true, regardless of mounted. The mounted state should only affect the animation, not whether the panel renders.

    Looking at the code:

    const shouldRender = keepMounted || mounted;
    if (!shouldRender) {
      return null;
    }
    

    The issue is that shouldRender depends on mounted, which has a one-render delay. The fix should be:

    const shouldRender = keepMounted || mounted || open;
    if (!shouldRender) {
      return null;
    }
    

    Wait, but that would render the panel even when open is true but the animation hasn't started. That might be the intended behavior!

    Actually, looking at this more carefully, I think the issue is that when open changes from false to true, the panel should render immediately. The mounted state is supposed to track whether the panel has been "shown" (for animation purposes), but it shouldn't prevent rendering.

    Let me look at the useTransitionStatus hook again:

    export function useTransitionStatus(
      open: boolean,
      enableIdleState: boolean = false,
      deferEndingState: boolean = false,
    ) {
      const [transitionStatus, setTransitionStatus] = React.useState<TransitionStatus>(
        open && enableIdleState ? 'idle' : undefined,
      );
      const [mounted, setMounted] = React.useState(open);
    
      if (open && !mounted) {
        setMounted(true);
        setTransitionStatus('starting');
      }
      // ...
      return {
        mounted,
        setMounted,
        transitionStatus,
      };
    }
    

    The mounted state is initialized to open. When open changes from false to true:

    • useState returns the old mounted value (false)
    • The if block calls setMounted(true)
    • But mounted is still false in this render
    • transitionStatus is set to 'starting'

    So the intent is that on the first render when open becomes true:

    • mounted is false (will be true in next render)
    • transitionStatus is 'starting'

    But the problem is that mounted is used to determine whether to render the panel. If mounted is false, the panel returns null, even though open is true and transitionStatus is 'starting'.

    The fix should be: the panel should render when open is true OR mounted is true. The mounted state should only be used for the ending transition (when closing the panel).

    Looking at the TabsPanel code:

    const shouldRender = keepMounted || mounted;
    

    This should be:

    const shouldRender = keepMounted || mounted || open;
    

    Or even simpler, we should change the logic to:

    const shouldRender = keepMounted || open || (transitionStatus === 'ending');
    

    This way, the panel renders when it's open, when it's kept mounted, or when it's in the ending transition (closing animation).

    Actually wait, let me think about this more carefully. The mounted state is used for two purposes:

    1. Track whether the panel should be in the DOM
    2. Determine the hidden attribute for accessibility

    For the opening case:

    • When open becomes true, the panel should be in the DOM
    • mounted should become true

    For the closing case:

    • When open becomes false, the panel should stay in the DOM during the closing animation
    • mounted should become true (so the panel is in the DOM)
    • After the animation completes, setMounted(false) is called, removing the panel from the DOM

    The issue is in the opening case. When open becomes true, setMounted(true) is called, but the state update takes effect in the next render. During this render, mounted is still false, so shouldRender is false, and the panel returns null.

    The fix is simple: when open is true, shouldRender should be true, regardless of mounted. The mounted state should only be used to track the closing case.

    Let me also think about whether there's a fix in the useTransitionStatus hook instead. The issue is that setMounted(true) doesn't take effect until the next render. What if we change the hook to return the correct mounted value immediately?

    if (open && !mounted) {
      setMounted(true);
      setTransitionStatus('starting');
      // Immediately return the updated value
      mounted = true; // But this won't work because mounted is const
    }
    

    Actually, we can't change the state value during the same render. The only way is to use a different variable.

    const isEffectivelyMounted = open || mounted;
    

    But this changes the semantics of mounted. It's no longer just about whether the panel has been shown - it's also about whether the panel is open.

    I think the cleanest fix is in TabsPanel.tsx:

    const shouldRender = keepMounted || open || mounted;
    

    Or we can change hidden:

    const hidden = !mounted && !open;
    

    But wait, hidden is also used for the aria-hidden attribute and accessibility. Let me check what hidden is used for.

    Looking at the code:

    const hidden = !mounted;
    // ...
    hidden,  // passed to state
    // ...
    hidden,  // passed as attribute to the element
    // ...
    useIsoLayoutEffect(() => {
        if (hidden && !keepMounted) {
          return undefined;
        }
        // register the panel
      }, [hidden, ...]);
    

    So hidden is:

    1. Part of the component state (for data-* attributes)
    2. The hidden HTML attribute (which hides the element)
    3. Used to determine whether to register the panel

    If we change hidden to !mounted && !open, the panel would be registered even when open is true but mounted is false. This seems correct.

    But there's a subtlety: the hidden HTML attribute would be false when open is true, which means the element would be visible (not hidden). But if mounted is false, we might not want to show it yet (for animation purposes).

    Hmm, this is getting complicated. Let me think about what the correct behavior should be.

    When open changes from false to true:

    1. The panel should be in the DOM (shouldRender = true)
    2. The panel should be visible (hidden = false) - or should it be hidden for the animation?
    3. The panel should be registered with TabsRoot

    For the animation to work, the panel should be in the DOM but possibly with data-starting-style attribute. The panel should not be hidden via the hidden attribute - instead, it should use CSS transitions.

    So the fix should be:

    1. shouldRender = keepMounted || open || mounted - panel renders when open or mounted
    2. hidden = !mounted - this is fine for the animation (the panel is in the DOM but hidden attribute might be used for initial state)

    Wait, but the hidden attribute on the element would hide it even if it's in the DOM. Let me re-read the code:

    props: [
      {
        'aria-labelledby': correspondingTabId,
        hidden,  // This sets the hidden attribute on the element
        id,
        role: 'tabpanel',
        tabIndex: open ? 0 : -1,
        inert: inertValue(!open),
        [TabsPanelDataAttributes.index as string]: index,
      },
      elementProps,
    ],
    

    If hidden is true, the element has the hidden attribute, which makes it not visible and not focusable. This is different from display: none because hidden also removes it from the accessibility tree.

    So for the opening animation, we might want hidden = true initially (to hide the panel), then hidden = false after the animation completes.

    Actually, looking at the transitionStatusMapping, the panel uses data-starting-style and data-ending-style for animations, not the hidden attribute. The hidden attribute is used to completely hide the panel when it's not mounted.

    OK, I think I understand now. The hidden attribute is used for:

    1. When the panel is not mounted: hidden = true
    2. When the panel is mounted: hidden = false

    And the animation uses data-starting-style and data-ending-style with CSS transitions.

    So the flow should be:

    1. open = false: panel is not in the DOM (shouldRender = false)
    2. open = true: panel is added to the DOM (shouldRender = true), transitionStatus = 'starting', hidden = false (because mounted is set to true)
    3. User clicks to close: open = false, transitionStatus = 'ending', panel stays in DOM
    4. Animation completes: setMounted(false), panel is removed from DOM

    But the current code has a bug: in step 2, mounted is still false (because setMounted(true) hasn't taken effect), so shouldRender = false and the panel is not in the DOM.

    The fix is to ensure that when open is true, the panel is in the DOM. The simplest fix is:

    const shouldRender = keepMounted || open || mounted;
    

    But wait, this would also make hidden = !mounted show hidden = true even when open = true. That's wrong - when the panel is opening, it should be visible (hidden = false).

    Actually, let me re-read the useTransitionStatus hook:

    if (open && !mounted) {
      setMounted(true);
      setTransitionStatus('starting');
    }
    

    When open is true and mounted is false, setMounted(true) is called. This schedules an update that will take effect in the next render. But in the current render, mounted is still false.

    The hook is designed so that mounted becomes true synchronously (in the next render), and transitionStatus becomes 'starting'. The 'starting' status is used for CSS transitions.

    But the issue is that mounted being false in the current render causes shouldRender to be false, so the panel is not in the DOM.

    I think the fix should be in the useTransitionStatus hook to return the correct mounted value. We can use a local variable:

    const [internalMounted, setInternalMounted] = React.useState(open);
    const mounted = open || internalMounted;
    

    This way, mounted is always true when open is true, regardless of the internal state.

    Or we can fix it in TabsPanel.tsx:

    const shouldRender = keepMounted || open || mounted;
    

    I think the second fix is cleaner because it doesn't change the semantics of the useTransitionStatus hook.

    But wait, there's another issue. The hidden variable:

    const hidden = !mounted;
    

    If mounted is false (but open is true), then hidden is true. The panel would be hidden via the hidden attribute. But we want the panel to be visible when it's opening.

    So we also need to fix hidden:

    const hidden = !mounted && !open;
    

    Hmm, but this might break the animation. The hidden attribute is used to determine whether the panel should be visible.

    Actually, looking at the code again, I think the hidden attribute on the element is set based on hidden from the state, which is !mounted. But the animation uses data-starting-style and data-ending-style. So the flow is:

    1. open = true, mounted is still false
    2. hidden = !mounted = true
    3. Panel is rendered with hidden attribute
    4. But wait, if shouldRender = false, the panel is not rendered at all!

    So the issue is primarily with shouldRender. Let me focus on that.

    The fix should be:

    const shouldRender = keepMounted || mounted || open;
    

    And for hidden, we should use:

    const hidden = !open && !mounted;
    

    Or actually, let me think about this more carefully. The hidden attribute on the element is set by useRenderElement. Let me look at how it's used:

    props: [
      {
        hidden,
        // ...
      },
      elementProps,
    ],
    

    So hidden is passed as an intrinsic prop. If hidden is true, the element has the hidden HTML attribute.

    For the animation to work:

    1. When the panel opens, it should be in the DOM
    2. The hidden attribute should be false (panel is visible)
    3. The data-starting-style attribute should be set for the CSS transition

    But currently:

    1. mounted = false (hasn't been set yet)
    2. hidden = true
    3. Panel is hidden via the hidden attribute
    4. Even if shouldRender = true, the panel is hidden

    So we need both fixes:

    1. shouldRender = keepMounted || mounted || open - panel is in the DOM
    2. hidden = !open && !mounted - panel is not hidden when open

    Wait, actually, let me re-read the code. The hidden is also used in the state object:

    const state: TabsPanelState = {
        hidden,
        orientation,
        tabActivationDirection,
        transitionStatus,
      };
    

    And it's used for the data-hidden attribute via stateAttributesMapping. Let me check what the mapping does:

    <tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/internals/stateAttributesMapping.ts </tool_call>

  46. Qwen Assistant

    I need to read the stateAttributesMapping file to understand how the hidden state is mapped to attributes.

  47. Qwen Assistant

    Now I understand the bug! The issue is in TabsPanel.tsx. When a panel first opens (open changes from false to true), the setMounted(true) call in useTransitionStatus doesn't take effect until the next render. During this render, mounted is still false, so shouldRender = false and the panel returns null.

    On the next render, mounted becomes true and the panel renders. But if the panel's child suspends during this render, the Suspense boundary (outside Tabs.Root) catches it and unmounts the entire Tabs.Root. When React retries, Tabs.Root has fresh state with the default value, so the panel is no longer selected.

    The fix is to ensure the panel renders when open is true, not just when mounted is true:

  48. Qwen Assistant

    I now understand the bug. The issue is in TabsPanel.tsx. When a tab panel opens (open becomes true), the useTransitionStatus hook calls setMounted(true) during render, but the state update doesn't take effect until the next render. During the current render, mounted is still false, so shouldRender = keepMounted || mounted evaluates to false, and the panel returns null.

    On the next render, mounted becomes true, the panel renders, and if a child suspends, the Suspense boundary outside Tabs.Root catches it and unmounts the entire tree. After recovery, Tabs.Root remounts with fresh state.

    The fix is to ensure the panel renders when open is true, not just when mounted is true:

  49. Qwen Assistant

    Now let me also fix the hidden variable. When open is true but mounted is still false (during the first render when opening), the hidden attribute should be false so the panel is visible and the opening animation can work correctly:

  50. Qwen Assistant

    Let me also update the hidden variable to ensure the panel is visible when open is true:

  51. Qwen Assistant

    Now let me also fix the hidden variable. When open is true, the panel should not be hidden, even if mounted is still false in the first render after opening:

  52. Qwen Assistant

    Let me verify my changes are correct by viewing the file.

  53. Qwen Assistant

    Looking at this more carefully, my fix ensures that when open becomes true, the panel renders immediately in the same render cycle as the state update. This is critical because:

    Without the fix: The panel doesn't render until the NEXT render cycle (after mounted becomes true). By then, the state update has already been committed. When the child suspends, React unmounts the entire tree (since the Suspense boundary is outside Tabs.Root), and the state is lost.

    With the fix: The panel renders in the SAME render cycle as the state update. When the child suspends, React rolls back (not unmounts) because the state update hasn't been committed yet. After the promise resolves, React retries with the same pending state update, and the panel content is shown.

    Let me verify the changes look correct:

  54. Qwen Assistant

    Let me verify the changes are correct and check if there are existing tests to run:

  55. Qwen Assistant

    Let me verify the full context of the changes:

  56. Qwen Assistant

    The changes look correct. Let me verify there are no issues by checking if any tests exist and can be run:

  57. Qwen Assistant

    The changes look correct. Let me verify the logic by analyzing the edge cases:

    Before the fix:

    • When open becomes true, shouldRender was keepMounted || mounted which evaluates to false because mounted is still false in the same render cycle (state updates take effect in the next render)
    • This caused a one-render delay before the panel rendered
    • When a child suspends during that delayed render, React unmounts the entire Tabs.Root (since the update was already committed), and state is lost

    After the fix:

    • When open becomes true, shouldRender = keepMounted || open || mounted evaluates to true immediately
    • The panel renders in the same render cycle as the state update
    • If a child suspends, React rolls back (doesn't unmount) because the state update hasn't been committed yet
    • After the promise resolves, React retries with the pending state update, and the panel content is shown

    Let me also verify the hidden change handles all cases correctly:

    • open=true, mounted=false: hidden=false ✓ (panel visible when opening)
    • open=true, mounted=true: hidden=false ✓ (panel visible when open)
    • open=false, mounted=true: hidden=false ✓ (panel visible during closing animation)
    • open=false, mounted=false: hidden=true ✓ (panel hidden when closed)
  58. Qwen Assistant

    Let me verify my fix is correct by checking if there are any edge cases I might have missed. Let me also run the existing tests to make sure I haven't broken anything.

  59. Qwen Assistant

    The TabsPanel tests pass. Let me also run the TabsRoot tests to make sure the changes don't break anything else.

  60. Qwen Assistant

    Excellent! All tests pass. Let me run all tabs-related tests to make sure everything is working:

  61. Qwen Assistant

    All 171 tests pass (38 skipped are likely browser-specific or animation tests). Let me also run a quick sanity check on other components that might use useTransitionStatus:

  62. Qwen Assistant

    The useTransitionStatus hook is used in several other components. My fix is specific to the TabsPanel and shouldn't affect other components. Let me also run some related tests to make sure the hook tests pass:

  63. Qwen Assistant

    No specific tests for useTransitionStatus. Let me check if there are any other tests that might be affected by my changes:

  64. Qwen Assistant

    All tests pass! Let me now clean up the test file I created earlier and submit my changes.

  65. Qwen Assistant

    Let me verify the final state of my changes before submitting.

  66. Qwen Assistant

    My fix is complete. Let me summarize the changes:

    Summary of Changes

    File modified: packages/react/src/tabs/panel/TabsPanel.tsx

    Two changes were made:

    1. Line 61: Changed hidden = !mounted to hidden = !open && !mounted

      • This ensures the hidden attribute is false when the panel is opening, so the panel is visible during the opening animation.
    2. Line 117: Changed shouldRender = keepMounted || mounted to shouldRender = keepMounted || open || mounted

      • This ensures the panel renders immediately when open becomes true, instead of waiting for mounted to become true in the next render cycle.

    Root cause: The useTransitionStatus hook calls setMounted(true) during render when open changes from false to true. However, state updates in React take effect in the next render, so during the current render mounted is still false. This caused a one-render delay before the panel rendered.

    When a child component suspends during that delayed render, the Suspense boundary (outside Tabs.Root) catches the suspension. Since the state update had already been committed (after the delayed render), React unmounts the entire Tabs.Root tree and loses all state. After recovery, the user had to click the tab again.

    With this fix, the panel renders immediately when open is true. If a child suspends, React rolls back (not unmounts) because the state update hasn't been committed yet. After the promise resolves, React retries with the pending state update, and the panel content is shown correctly.

    All 171 tabs-related tests pass.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.