ISSUE DESCRIPTION [tabs] Tabs.Panel content not rendered if a child component suspends…
- User
ISSUE DESCRIPTION
[tabs] Tabs.Panel content not rendered if a child component suspends without boundary within Tabs.Root
Bug report
Current behavior
If a tab panel has a child that suspends and the suspense unmounts the tab root (i.e., the next boundary is outside the
Tabs.Rootcomponent), the panel content is not rendered when opening a tab for the first time.Only when clicking the trigger a second time, the panel is rendered.
Expected behavior
The panel content is rendered also when first opening a tab like it did in v1.4.1.
Reproducible example
Click on tab B in this Stackblitz
Alternatively, run this code snippet locally:
import { Tabs } from '@base-ui/react/tabs'; import { Suspense, use } from 'react'; // Promise used to suspend. const dataPromise = new Promise<string>((resolve) => setTimeout(() => resolve('Panel B is rendered'), 500) ); function SuspendingChild() { return <div>{use(dataPromise)}</div>; } export default function App() { return ( // The Suspense boundary is outside the <Tabs.Root> and the panels/panel content don't use a separate suspense boundary. <Suspense fallback={<div>Loading…</div>}> <Tabs.Root defaultValue="a"> <Tabs.List> <Tabs.Tab value="a">Tab A</Tabs.Tab> <Tabs.Tab value="b">Tab B</Tabs.Tab> </Tabs.List> <Tabs.Panel value="a">Panel A (no suspense)</Tabs.Panel> <Tabs.Panel value="b"> <SuspendingChild /> </Tabs.Panel> </Tabs.Root> </Suspense> ); }Base UI version
The only affected version is v1.5.0
v1.4.1 is not affected
Which browser are you using?
Reproducible in Chrome/Safari/Firefox
Additional context
Potentially a side effect of https://github.com/mui/base-ui/pull/4704
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto 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-$
- Assistant
I'll start by exploring the repository structure to understand the codebase. Let's first check what kind of project this is.
- Assistant
This looks like a monorepo with lerna/pnpm. Let's look at the root package.json to understand the project better.
- Assistant
Let me look at the packages directory to find the tabs component.
- Assistant
Let me explore the structure more.
- Assistant
Let's look at the tabs directory.
- Assistant
Let me explore the tabs component structure more deeply.
- Assistant
Let me examine the issue. The bug was introduced in v1.5.0, and it's related to tabs panel content not rendering when a child component suspends without a boundary within Tabs.Root. The issue mentions PR #4704 as a potential cause. Let me look at the tab panel implementation and the tab root implementation.
- Assistant
Now let me look at the root component to understand the structure better.---
- Assistant
Let me look at one file at a time.
- Assistant
Now let me look at the
useTransitionStatushook and the referenced PR #4704. - Assistant
Let me analyze the issue. The problem is that when a child component of
Tabs.Panelsuspends (throws a Promise) and theSuspenseboundary is outside ofTabs.Root, the panel content is not rendered on first click.The issue mentions PR #4704 as a potential cause. Let me look at the git history to understand what changed.
The key issue is in
useTransitionStatus. Whenopenistrue(a tab panel is selected), but a child suspends and causes the wholeTabs.Rootto unmount and remount (because the Suspense boundary is above), theuseTransitionStatushook might not correctly handle this scenario.Wait, actually let me re-read the issue more carefully. The issue is:
- The
Suspenseboundary is outsideTabs.Root - A tab panel has a child that suspends
- When clicking the tab for the first time, the panel content is not rendered
- Only when clicking the trigger a second time, the panel is rendered
This means the
Tabs.Rootdoesn't unmount per se. The Suspense boundary catches the thrown Promise from the child component and shows the fallback. But the Tabs.Root itself stays mounted. When the Promise resolves, the Suspense boundary re-renders its children, and the tab panel should now render properly.Wait, but if the Suspense boundary is OUTSIDE Tabs.Root, then when the child suspends, the entire Tabs.Root would be replaced by the Suspense fallback. Then when the promise resolves, the entire Tabs.Root is re-created, which means the state (including which tab is selected) would be reset.
But the issue says this worked in v1.4.1, so something must have changed.
Let me think about this differently. With the Suspense boundary outside Tabs.Root:
- Initially, tab "a" is selected (defaultValue="a"), panel A renders fine
- User clicks tab "b", the value changes to "b"
- Panel B tries to render, its child (
SuspendingChild) throws a Promise - The Suspense boundary catches it, replaces everything with "Loading..."
- After 500ms, the Promise resolves, the Suspense boundary re-renders its children
- Tabs.Root is recreated with defaultValue="a", so tab "a" is selected again... wait, that's not right either.
Actually wait. If the entire Tabs.Root is unmounted and remounted by Suspense, the defaultValue would be used again. So when the promise resolves, the tabs would show tab A again, not tab B. But the user was clicking tab B...
Hmm, but the issue says "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 when the Suspense boundary resolves, the tab B trigger is still in the "selected" visual state, but the panel doesn't render.
Actually, let me re-think. In React Suspense, when a component suspends:
- The nearest Suspense boundary catches it and shows the fallback
- When the promise resolves, React re-renders from the Suspense boundary
- The component tree is recreated from scratch (new instances)
But wait, I need to consider that in React 18/19, Suspense doesn't cause the component to unmount and remount - it's more nuanced. When a child suspends, the Suspense boundary replaces its children with the fallback. But when the promise resolves, React re-renders the original children. The key question is whether React maintains the state of components above the suspended child.
Actually, the way Suspense works:
- The component that suspends throws a Promise
- React bubbles up to the nearest Suspense boundary
- The Suspense boundary's children are replaced with the fallback
- When the Promise resolves, React re-renders from the Suspense boundary
- The component tree under the Suspense boundary is re-rendered (not necessarily remounted)
But in this case, the Suspense boundary is ABOVE Tabs.Root. So when the child of panel B suspends:
- The Promise propagates up to the Suspense boundary
- The entire Tabs.Root (which is inside the Suspense boundary) is replaced with the fallback
- This means ALL state in Tabs.Root (and its children) is lost
- When the promise resolves, the Suspense boundary re-renders, and Tabs.Root is created from scratch
- Tabs.Root uses defaultValue="a", so tab A is selected
- Panel A renders, panel B does not (because it's not selected)
So the user would need to click tab B again, and this time the SuspendingChild would not throw (since the promise already resolved). So it would work the second time.
Wait, but the
dataPromiseis defined outside the component as a module-level constant. So it's the same Promise every time. Theuse()hook with a resolved promise should just return the resolved value immediately.Actually, in React 19,
use()on a resolved promise returns the value immediately. But in the first render after Suspense resolves, the Promise is already resolved, souse()should work fine.Hmm, let me reconsider. The issue might be more subtle. Let me look at
useTransitionStatusmore carefully.When the Tabs.Root is re-created after Suspense resolves:
TabsPanelfor value "b" is created withopen = false(becauseselectedValueis "a" from defaultValue)- In
useTransitionStatus(open=false),mountedstarts asfalse,transitionStatusstarts asundefined - Panel B doesn't render (shouldRender = keepMounted || mounted = false || false = false)
Then when user clicks tab B:
valuechanges to "b"- Panel B has
open = true - In
useTransitionStatus,open && !mounted->setMounted(true); setTransitionStatus('starting') shouldRender = true- But now the child suspends again? No, the promise is already resolved...
Wait, actually the issue might be that when the Suspense boundary resolves and re-renders Tabs.Root, React might throw again because the promise might not be fully resolved yet, or there's some timing issue.
Actually, I think the real issue might be different. Let me re-read the issue more carefully.
"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."
OK so the scenario is:
- User clicks tab B
- Tab B's panel tries to render, child suspends
- Suspense boundary catches it, Tabs.Root is unmounted, fallback shown
- Promise resolves, Suspense re-renders
- Tabs.Root re-creates with defaultValue="a", but... wait, if the value was controlled or something?
Actually, let me re-read the repro code:
<Tabs.Root defaultValue="a">So this is uncontrolled. When the component re-mounts after Suspense, defaultValue is "a". Tab A would be selected.
But the user was clicking tab B! So from the user's perspective, they click tab B, see "Loading...", then when it resolves they see tab A again. That's weird but might be "correct" behavior since it's uncontrolled.
But the issue says "the panel content is not rendered when opening a tab for the first time". I think the scenario is:
- Click tab B -> panel content is not rendered (Suspense catches)
- Suspense resolves, tabs are re-created, tab A is selected
- Click tab B again -> now the promise is resolved, so no suspense, panel B renders
So the "first time" means the first time after the component mounts. If the user clicks tab B again, it works because the promise is already resolved.
Hmm, but the issue says "Only when clicking the trigger a second time, the panel is rendered." This seems to suggest that after the Suspense resolves, clicking the trigger again works. That matches what I described.
But is this a bug in the Tabs component or just expected behavior with Suspense? The issue says it worked in v1.4.1 but not in v1.5.0.
Let me check what changed in PR #4704. Let me look at the git log.
- The
- Assistant
Let me look at PR #4704 and the recent tabs fix commit.
- Assistant
Let me look at the tabs fix commit that's already in the repo.
- Assistant
Let me see what changes were made in the recent tabs fix.
- Assistant
Let me look at the PR #4704 changes and the
useTransitionStatushook. - Assistant
Let me look at the
useTransitionStatushook and think about the issue. The problem is when a child suspends and the Suspense boundary is outside Tabs.Root. - Assistant
Let me look at the
useTransitionStatushook and understand the issue better. - Assistant
Now let me understand the issue. Let me trace through the flow when a child component suspends inside a Tabs.Panel. First, let me look at the
useOpenChangeCompletehook used in TabsPanel. - Assistant
Let me find the file.
- Assistant
Let me look at the
useOpenChangeCompletehook and understand the flow when a child suspends inside a panel. - Assistant
Let me look at the PR #4704 changes more carefully and check what version tags are available.
- Assistant
Let me understand the flow better. Let me look at how tabs register and what happens with Suspense. Let me look at the
useCompositeListItemhook. - Assistant
Let me look at the actual issue. The problem is:
-
Tabs.Panel uses
useTransitionStatus(open)whereopenistruewhen the panel is selected -
useTransitionStatushas render-time state updates that setmounted = truewhenopenbecomestrue -
When a child of the panel suspends, React needs to handle thisLet me trace through the exact sequence of events:
-
User clicks Tab B →
valuechanges to "b" -
Panel B starts rendering with
open = true -
In
useTransitionStatus(true):mountedisfalse(initial state)- The render-time check:
if (open && !mounted)→setMounted(true),setTransitionStatus('starting') - React re-renders with
mounted = true
-
Now
shouldRender = true, so the panel renders its children -
SuspendingChildcallsuse(dataPromise)which throws the promise -
React catches the promise and goes up to the Suspense boundary (outside Tabs.Root)
-
The Suspense boundary renders its fallback
Now here's the key question: what state does React preserve for the Tabs components?
In React, when Suspense catches a thrown promise during a render:
- If this is the initial render, the component is not mounted yet
- If this is a re-render (update), the existing committed state is preserved
But wait - in step3, we had a render-time state update (
setMounted(true)). This is a "discrete" update during render. React processes it synchronously.Actually, let me reconsider. The issue might be more subtle. Let me look at the
useTransitionStatushook more carefully.The render-time state updates in
useTransitionStatusare:if (open && !mounted) { setMounted(true); setTransitionStatus('starting'); }This is called during render. In React, calling
setStateduring render is a "state reducer" pattern - React will immediately re-render the component with the new state before continuing.So when Panel B's
openbecomestrue:- First render:
mounted = false,open = true→setMounted(true),setTransitionStatus('starting') - React immediately re-renders with
mounted = true,transitionStatus = 'starting' shouldRender = true, so children are renderedSuspendingChildsuspends- React catches the promise at the Suspense boundary
Now, here's the crucial part: when the Suspense boundary catches this and renders its fallback, what happens to the Tabs component tree?
When the Suspense boundary replaces its children with the fallback, the children are effectively unmounted. All their state is lost. When the promise resolves, React re-renders the Suspense boundary's children, which creates fresh component instances.
So when the promise resolves:
Tabs.Rootre-mounts fresh withdefaultValue = "a"- Tab A is selected
- Panel B has
open = false,mounted = false - User needs to click Tab B again
But wait, the issue says clicking Tab B the second time also doesn't work initially. Let me re-read:
"Only when clicking the trigger a second time, the panel is rendered."
Hmm, so:
- First click on Tab B → child suspends → Suspense catches → "Loading..." → promise resolves → Tabs remount with Tab A
- Click Tab B again → should work now because promise is already resolved
But the issue says the panel content is NOT rendered when opening a tab for the first time, and only renders on the second click.
Wait, maybe I'm misunderstanding. Let me re-read the issue more carefully.
"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."
I think what's happening is:
- The Suspense boundary catches the promise
- When the promise resolves, React re-renders
- But something goes wrong with the Tabs state/rendering
- The panel doesn't show content
- Clicking the trigger again makes it work
Let me think about what could cause this...
Actually, looking at the code more carefully, I see that
useTransitionStatususes render-time state updates:if (open && !mounted) { setMounted(true); setTransitionStatus('starting'); }And also:
if (!open && mounted && transitionStatus !== 'ending' && !deferEndingState) { setTransitionStatus('ending'); }These are render-time state updates. In React, when a component suspends (throws a promise), React will NOT commit the render. So the state updates from this render are lost.
But wait,
setMounted(true)was already called during render as a state reducer. In React 19 (which usesuse()), state reducers during render are handled differently than regular setState calls.Actually, I think the issue is more specific. Let me look at the interaction between
useTransitionStatusand the Suspense boundary.When the Suspense boundary catches the promise and then resolves, React re-renders from the Suspense boundary. The Tabs component tree is recreated. But here's the thing:
useTransitionStatushas this code:const [mounted, setMounted] = React.useState(open);When
openistrueon the first render after remount:mountedstarts astrue(fromuseState(open))- But wait, the panel's
openmight befalseinitially (Tab A is selected) - Then when Tab B is clicked,
openbecomestrue mountedisfalse(fromuseState(false))if (open && !mounted)→setMounted(true),setTransitionStatus('starting')- React re-renders, children render, child suspends again? No, the promise is already resolved...
Wait, the promise is a module-level constant, so it's the same promise every time. After it resolves,
use(dataPromise)should return the resolved value immediately.So when the user clicks Tab B the second time (after the Suspense resolved and remounted):
openbecomestrueuseTransitionStatus:mounted = false,open = true→setMounted(true),setTransitionStatus('starting')- React re-renders with
mounted = true shouldRender = true- Children render,
use(dataPromise)returns the resolved value - Panel B content should render
This should work! So why doesn't it?
Let me look at the
useOpenChangeCompletehook more carefully:useOpenChangeComplete({ open, ref: panelRef, onComplete() { if (!open) { setMounted(false); } }, });When
openchanges totrue,useOpenChangeCompletewaits for animations to complete and then callsonComplete. ButonCompleteonly setsmounted = falsewhenopenisfalse. So whenopenistrue, this is a no-op.But wait, the
useOpenChangeCompletehook uses auseEffectwithopenas a dependency:React.useEffect(() => { if (!enabled) { return undefined; } const abortController = new AbortController(); runOnceAnimationsFinish(onComplete, abortController.signal); return () => { abortController.abort(); }; }, [enabled, open, onComplete, runOnceAnimationsFinish]);When the component unmounts (due to Suspense), the effect cleanup runs and aborts. When it remounts and
openistrue, the effect runs again and waits for animations. This seems fine.Hmm, let me think about this differently. Maybe the issue is related to how React handles the
setMounted(true)call during render when there's a Suspense boundary above.Actually, I think I might have been overthinking this. Let me look at what happens more carefully with React Suspense.
When a component throws a promise during render:
- React walks up the fiber tree to find the nearest Suspense boundary
- React renders the fallback
- The suspended subtree is NOT committed
- When the promise resolves, React re-renders the suspended component
But the key question is: are the render-time state updates (
setMounted(true)) committed or not?In React 19 with
use():- State updates during render (like
setMounted(true)in theif (open && !mounted)check) are processed as "state reducer" calls - These are handled synchronously during render
- If a child suspends AFTER these state updates, the parent's state should be updated- But the Suspense boundary will catch the promise and show the fallback
- When the promise resolves, React re-renders from the Suspense boundary
Wait, I think the issue might be that when the Suspense boundary catches the promise, the component tree below it is replaced with the fallback. This means the Tabs components are unmounted. When the promise resolves, they're re-created fresh.
If they're re-created fresh:
Tabs.Rootstarts withdefaultValue = "a"→value = "a"- Panel B has
open = false,mounted = false - User clicks Tab B again →
open = true,mounted = false setMounted(true)→ React re-renders →mounted = true- Children render, promise already resolved → content showsThis should work! Unless there's something else going on.
Let me look at the PR #4704 changes one more time. Actually, let me check if there's something about the
commitAutomaticValueChangethat might interfere.In
TabsRoot, there's this effect:useIsoLayoutEffect(() => { if (isControlled) { return; } // ... if (tabMap.size === 0) { if (!didRegisterTabsRef.current || value === null) { return; } commitAutomaticValueChange(null, REASONS.missing); return; } didRegisterTabsRef.current = true; // ... });When the Suspense boundary catches and remounts,
didRegisterTabsRef.currentisfalse(ref is fresh). So whentabMap.size === 0initially, it returns early. Then tabs register,tabMapgrows, anddidRegisterTabsRef.currentis set totrue.Hmm, this seems fine.
Wait, I want to look at something else. The
useTransitionStatushook:if (open && !mounted) { setMounted(true); setTransitionStatus('starting'); }This is a render-time state update. In React, when you call
setStateduring render, React will re-render the component with the new state before continuing to render children. This is called a "state reducer" pattern.But here's the issue: when a child suspends, React needs to throw the promise up to the Suspense boundary. In the process, the render-time state updates might be handled differently.
Actually, I think I need to test this. Let me create a simple reproduction and see what happens.
But wait, let me first look at what version of React is being used in this repository.
-
- Assistant
Let me look at the git history for the
useTransitionStatushook and the PR #4704 changes more carefully. - Assistant
Let me understand the issue better. Let me look at the git history for the relevant files and try to reproduce the issue.
- Assistant
Let me focus on understanding the issue by looking at what PR #4704 changed in the critical path and also the CompositeList.
- Assistant
Let me look at how tabs register themselves.
- Assistant
Now let me understand the full issue. Let me look at the
useAnimationsFinishedhook and theuseTransitionStatushook in more detail. - Assistant
Let me trace through the issue. I need to understand what happens when a child suspends inside a
Tabs.Panelwith the Suspense boundary outsideTabs.Root. Let me examine the key flow more carefully. - Assistant
Let me look at how
setTabMapis called and trace through the issue step by step. The key insight is that when a child suspends insideTabs.Paneland the Suspense boundary is outsideTabs.Root, React may handle the render-phase state updates inuseTransitionStatusdifferently. Let me first reproduce the issue. - Assistant
Let me look at the Tabs list component to understand the tab registration flow:
- Assistant
Now I'm understanding the issue. Let me trace through the flow:
- User clicks Tab B →
setValue("b")→ Panel B renders withopen=true useTransitionStatus(true)setsmounted=trueduring render- Panel renders children →
SuspendingChildsuspends (throws Promise) - React catches at Suspense boundary outside Tabs.Root → shows fallback
- When Promise resolves → React re-renders from Suspense boundary
The key question is what happens to
tabMapstate after the Suspense resolves. The PR #4704 added logic that callscommitAutomaticValueChange(null, REASONS.missing)whentabMap.size === 0anddidRegisterTabsRef.current === trueandvalue !== null.Let me create a reproduction script and verify:
- User clicks Tab B →
- Assistant
Let me look at the existing tests for tabs and find the test setup:
- Assistant
Let me look at the existing tests to understand the testing setup.
- Assistant
Now I need to understand the actual issue. Let me trace through what happens step by step when a child suspends inside Tabs.Panel. Let me look at the useTransitionStatus hook and how the Suspense boundary interacts with it.
The key issue is in
useTransitionStatus- it has render-phase state updates (setMounted(true)) that happen during render. When a child component suspends after this state update, React needs to handle the interruption. Let me look at theuseTransitionStatushook and how it interacts with Suspense. - Assistant
Now I understand the issue. Let me trace through the flow:
- Click Tab B →
value = "b"→ Panel Bopen = true useTransitionStatus(true):setMounted(true)during render →shouldRender = true- Panel renders children →
SuspendingChildcallsuse(dataPromise)→ suspends - React catches at Suspense boundary (outside Tabs.Root)
- Tab effects cleanup →
unregister→tabMapbecomes empty - Layout effect in TabsRoot:
tabMap.size === 0,didRegisterTabsRef.current = true,value = "b"→commitAutomaticValueChange(null, REASONS.missing)→ value set to null! - When promise resolves, tabs re-register, but
valueis alreadynull→ no panel selected
The PR #4704 added this
tabMap.size === 0→commitAutomaticValueChange(null, ...)logic. Let me verify this by looking at the code and creating a fix. - Click Tab B →
- Assistant
Now I understand the issue. When the Suspense boundary catches and the tab effects clean up,
tabMapbecomes empty. The layout effect in TabsRoot then callscommitAutomaticValueChange(null, REASONS.missing)which setsvaluetonull. When the promise resolves, the value is alreadynullso no panel is selected.Let me fix this:
- Assistant
Now I have a clear picture of the issue. Let me trace the exact flow:
- User clicks Tab B →
setValue("b")→ Panel Bopen = true useTransitionStatus(true):setMounted(true)during render →shouldRender = true- Panel renders children →
SuspendingChildcallsuse(dataPromise)→ suspends - React catches at the Suspense boundary (outside
Tabs.Root) → shows fallback
Now here's the key: when the child suspends AFTER
setMounted(true)was called during render, React catches the suspension at the Suspense boundary. ThesetMounted(true)was a render-phase state update. React will roll back this render since the tree didn't fully commit (the suspension interrupted it).When the promise resolves, React re-renders. But the key question is what happens to
mounted.Let me write a test to confirm the issue and trace it:
- User clicks Tab B →
- Assistant
Let me look at the actual issue more carefully by examining the PR #4704 changes and the
useTransitionStatusbehavior with Suspense. - Assistant
Let me look at the test for the "missing" tab scenario added by PR #4704:
- Assistant
Now I understand the issue. Let me trace through the exact flow:
- User clicks Tab B →
value="b"→ Panel B hasopen=true useTransitionStatus(true)→setMounted(true)during render →shouldRender=true- Panel renders children →
SuspendingChildcallsuse(dataPromise)→ suspends - React catches at Suspense boundary (outside Tabs.Root) → shows fallback
- DOM elements get disconnected → CompositeList's MutationObserver fires →
sortedMaprecomputed with.filter((node) => node.isConnected)→ empty! setTabMap({})called →tabMap.size === 0- TabsRoot layout effect:
tabMap.size === 0 && didRegisterTabsRef.current && value !== null→commitAutomaticValueChange(null, REASONS.missing)→ value set to null! - Promise resolves → Suspense re-renders → but value is now null → no panel shows
- User clicks Tab B again → value="b" → panel renders (promise already resolved)
The fix should be in the
CompositeList- don't filter disconnected nodes fromsortedMap. This waytabMapwon't become empty when Suspense disconnects DOM nodes temporarily. - User clicks Tab B →
- Assistant
Let me look at the
CompositeList'sisConnectedfilter more carefully. When the Suspense boundary catches and removes DOM nodes, theisConnectedfilter causessortedMapto become empty, which triggers the automatic value change to null inTabsRoot. Let me fix this. - Assistant
Let me look at the
CompositeListcode more carefully. I can see the issue: when theSuspenseboundary catches, DOM nodes are disconnected, and theisConnectedfilter causessortedMapto become empty, which triggers thecommitAutomaticValueChange(null)inTabsRoot.Let me check what the full sortedMap computation looks like and also the
useIsoLayoutEffectthat callsonMapChange: - Assistant
Now I have a clear picture. The issue is in the
CompositeList'ssortedMapcomputation which filters nodes bynode.isConnected. When the Suspense boundary catches and removes the DOM, the nodes become disconnected, causingsortedMapto become empty. This triggerssetTabMap(new Map())inTabsRoot, and then the layout effectcommitAutomaticValueChange(null)setsvaluetonull.Let me look at the
sortByDocumentPositionfunction: - Assistant
Let me look at the
sortByDocumentPositionfunction: - Assistant
Let me look at how
tabMapgets populated and what happens during Suspense: - Assistant
Now I understand the issue! Let me trace through the exact problem:
- When a child inside
Tabs.Panelsuspends, theSuspenseboundary (outsideTabs.Root) catches it - When the Suspense boundary catches, DOM nodes get disconnected
- The
CompositeList'ssortedMapfilters out disconnected nodes viaisConnected→ becomes empty - This triggers
setTabMap(new Map())inTabsRoot→tabMap.size === 0 - The layout effect in
TabsRootseestabMap.size === 0anddidRegisterTabsRef.current === trueandvalue !== null→ callscommitAutomaticValueChange(null, REASONS.missing)→ sets value tonull! - When the promise resolves, value is already
null, so no panel is selected
The fix: In
TabsRoot, whentabMap.size === 0but tabs were previously registered, we should NOT immediately commit a null value change. We should wait to see if the tabs come back (which they do when Suspense resolves). - When a child inside
- Assistant
Now I have a clear understanding. The root cause is: when the Suspense boundary catches, DOM nodes get disconnected, and the
CompositeListfilters them out viaisConnected, causingtabMapto become empty. Then the layout effect inTabsRootcommitsvalue = null.The best fix is in the
CompositeList- don't filter out disconnected nodes fromsortedMap. Instead, sort them to the end. This waytabMapwon't become empty during Suspense. - Assistant
Now I understand the issue. The root cause is in
CompositeList- when theSuspenseboundary catches, DOM nodes become disconnected. TheisConnectedfilter removes them fromsortedMap, making it empty. This triggerssetTabMap({})in TabsRoot, which then triggers the layout effect to callcommitAutomaticValueChange(null, REASONS.missing), setting value to null. When the promise resolves, value is already null so no panel renders.The fix should be in
CompositeList- don't filter disconnected nodes out ofsortedMap. Instead, sort them to the end: - Assistant
Now I understand the issue completely. Let me trace through the exact problem:
- User clicks Tab B →
value = "b"→ Panel B renders withopen = true useTransitionStatus(true)setsmounted = true→ Panel renders childrenSuspendingChildsuspends → Suspense catches at boundary outside Tabs.Root- Suspense renders fallback → DOM nodes are disconnected
CompositeList'sMutationObserverfires →sortedMaprecomputed withisConnectedfilter → empty!onMapChange(emptyMap)→setTabMap(new Map())in TabsRoot →tabMap.size === 0- Layout effect:
tabMap.size === 0,didRegisterTabsRef.current = true,value = "b"→commitAutomaticValueChange(null, REASONS.missing)→ value set to null! - Promise resolves → React re-renders → but
valueis nownull→ no panel selected - User clicks Tab B again →
value = "b"→ panel renders (promise already resolved)
The fix: In
CompositeList, don't filter disconnected nodes out ofsortedMap. Instead, sort them to the end. This preventstabMapfrom becoming empty during Suspense. - User clicks Tab B →
- Assistant
Now let me check the MutationObserver code - it observes
node.parentElement, which would be null for disconnected nodes. The existing code already handles this withif (node.parentElement): - Assistant
Good, the MutationObserver already handles disconnected nodes with
if (node.parentElement). Now let me verify the fix works by running the existing tests: - Assistant
All tests pass. Let me also run any tests for the composite list component:
- Assistant
Let me run the CompositeList tests to make sure they pass too.
- Assistant
Now let me write a test to verify the fix for the specific issue:
- Assistant
All 186 tests pass. Let me also run a broader set of tests that might be affected by the CompositeList change:
- Assistant
All 1119 tests pass. Let me also run the full composite-related tests to make sure nothing is broken:
- Assistant
All tests pass. Let me verify the final state of my fix:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →