ISSUE DESCRIPTION [tabs] Tabs.Panel content not rendered if a child component suspends…
- User
ISSUE DESCRIPTION
[tabs] Tabs.Panel content not rendered if a child component suspends without boundary within Tabs.Root
Bug report
Current behavior
If a tab panel has a child that suspends and the suspense unmounts the tab root (i.e., the next boundary is outside the
Tabs.Rootcomponent), the panel content is not rendered when opening a tab for the first time.Only when clicking the trigger a second time, the panel is rendered.
Expected behavior
The panel content is rendered also when first opening a tab like it did in v1.4.1.
Reproducible example
Click on tab B in this Stackblitz
Alternatively, run this code snippet locally:
import { Tabs } from '@base-ui/react/tabs'; import { Suspense, use } from 'react'; // Promise used to suspend. const dataPromise = new Promise<string>((resolve) => setTimeout(() => resolve('Panel B is rendered'), 500) ); function SuspendingChild() { return <div>{use(dataPromise)}</div>; } export default function App() { return ( // The Suspense boundary is outside the <Tabs.Root> and the panels/panel content don't use a separate suspense boundary. <Suspense fallback={<div>Loading…</div>}> <Tabs.Root defaultValue="a"> <Tabs.List> <Tabs.Tab value="a">Tab A</Tabs.Tab> <Tabs.Tab value="b">Tab B</Tabs.Tab> </Tabs.List> <Tabs.Panel value="a">Panel A (no suspense)</Tabs.Panel> <Tabs.Panel value="b"> <SuspendingChild /> </Tabs.Panel> </Tabs.Root> </Suspense> ); }Base UI version
The only affected version is v1.5.0
v1.4.1 is not affected
Which browser are you using?
Reproducible in Chrome/Safari/Firefox
Additional context
Potentially a side effect of https://github.com/mui/base-ui/pull/4704
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Assistant
I’ll first inspect the repository structure and the tabs implementation/history around the referenced regression, then identify the relevant tests and reproduce the behavior before changing source code.
- Assistant
The working tree is clean, and there is a very recent tabs state-edge-case change. I’ll inspect the tabs panel/root implementation, its tests, and the diffs/history for both that change and PR #4704 to isolate the lifecycle logic involved.
- Assistant
The panel currently registers its ID in a layout effect and uses root state to populate
aria-controls; suspension outside the root can discard the render/effect attempt. PR #4704 changed automatic selection and registration behavior, so I’ll compare the exact pre/post implementation and read focused panel/root tests plus transition-status semantics. - Assistant
The likely mechanism is a render-phase state update in
useTransitionStatus: opening panel B sets its localmountedstate while rendering; then its child suspends and React abandons/unmounts the whole root. On retry, preserving that render-phase update can leave root/panel registration and automatic-selection state inconsistent. I need the concise PR diff and release tag ancestry to determine the intended minimal fix rather than broadly changing shared transition behavior. - Assistant
The regression is more specifically tied to PR #4704’s new
tabMap.size === 0branch: when the outer Suspense boundary hides the root, descendant layout-effect cleanups temporarily unregister every tab. The still-mounted root then interprets this transient empty map as “all tabs removed” and changes the uncontrolled value away from B. Simply restoring the old early return would fix suspension but regress the newly supported genuine “all tabs removed” case, so I’ll inspect composite registration timing and React test utilities to find a reliable distinction and create a focused temporary reproduction without modifying tests. - Assistant
Composite entries are registered in layout effects rather than ref callbacks, so Suspense deactivation runs their cleanup just like true removal. However, the tab DOM nodes remain connected while React hides an already-visible Suspense primary tree, whereas truly removed tabs are disconnected. The root already retains tab element references separately (
tabPanelRefsis unrelated; the composite map itself is mutated). I’ll verify exact cleanup behavior with a temporary test using fake timers/controlled promise and log callbacks/state, then assess whether retaining the last nonempty map or checking DOM connectivity can safely defer only transient emptiness. - Assistant
A key detail is that
Tabs.Rootreceives an immutable sorted-map snapshot fromTabs.List; the list’s internal mutable registration map loses entries during Suspense cleanup. I’ll inspect the list wiring and run a standalone temporary Vitest file outside tracked test paths (then remove it), reproducing the exact click/suspend/resolve sequence and recording whether tabs stay connected while fallback is shown. - Assistant
The first test invocation was blocked by Corepack’s package-manager download confirmation (an environment/tooling prompt), not by the code. The temporary test file remains because the command timed out before cleanup. I’ll rerun noninteractively with Corepack’s prompt disabled and a longer timeout, while separately displaying the list wiring afterward if needed.
- Assistant
Vitest’s working directory is
packages/react, so the filter path was wrong and it found no test. I’ll recreate the same temporary test and invoke it using the package-relative path; this will establish the baseline failure and DOM connectivity observation. - Assistant
The corrected test reaches Vitest but repository setup currently cannot resolve
@base-ui/utils/error, indicating generated workspace build artifacts are absent; this affects all tests, not the reproduction itself. Before spending time on a full build, I’ll inspect workspace scripts and package exports. In parallel, I’ll use React’s DOM semantics to design a fix: retain the prior map snapshot long enough to check whether formerly registered tab nodes remain connected, which distinguishes Suspense hiding from actual removal without changing public interfaces. - Assistant
The focused fix will cache the latest nonempty tab map and, only when registration reports zero tabs, avoid automatic null fallback if any previously registered tab node is still connected. React Suspense disconnects layout effects but keeps the hidden primary DOM connected; genuine tab removal disconnects those nodes before registration cleanup. This preserves #4704’s all-tabs-removed behavior and also avoids introducing timing delays. I’ll implement that minimal root-only change, then build/repair workspace links enough to run the reproduction and tabs tests.
- Assistant
Python is unavailable in this environment, so no source change occurred. I also confirmed the test failure’s cause:
packages/react/node_modules/@base-ui/utilspoints to the absentpackages/utils/build. I’ll apply the same exact edit with the repository’sreplacehelper, then build the utils workspace package to restore the test dependency. - Assistant
The cache insertion succeeded and utils built successfully. The second replacement missed because the current branch’s empty-map condition includes a subtle
didRegisterTabsRefvariant not identical to the quoted block. I’ll open that exact section and patch it against the actual text. - Assistant
The actual block is exactly at lines 292–300. I’ll replace those lines directly, validate formatting, then rerun the temporary reproduction now that the utils build exists.
- Assistant
The direct edit is correct; it only lacks the existing blank-line style after the empty-map branch, which Prettier will normalize. I’ll format the file, recreate the focused test, and run it. This time the workspace dependency is built, so we should obtain the behavioral baseline-after-fix result.
- Assistant
The utils build completed, but Vitest still cannot resolve it. I’ll inspect the generated package and symlink target; this is likely a broken relative symlink caused by the uploaded
node_moduleslayout rather than source. I’ll correct only the local generated/link setup (not tracked files), then rerun. - Assistant
The symlink and files are valid. The remaining issue is likely the generated package export map omitting
./errordespite the source wildcard export; I’ll confirm, and if so run tests under the repository’s source-resolution condition/config rather than alter generated metadata. - Assistant
The wildcard exists, so I’ll inspect its conditional paths and Vite aliases. A likely mismatch is that package-level Vitest is being run from a subproject while shared config aliases point at a different expected install/build condition.
- Assistant
Node resolves the package correctly, so the issue is specific to Vite’s shared aliases. I’ll locate the installed monorepo test config and inspect its alias rules; this should reveal whether a companion React build is also expected before tests.
- Assistant
The failure is explained: invoking through
pnpm --filterchangesprocess.cwd()topackages/react, but the shared alias config assumes repository-root cwd and constructs nonexistentpackages/react/packages/utils/src. I’ll run Vitest directly from the repository root with the React project selected, which is the project’s intended invocation. - Assistant
Vitest does not name the project
packages/react; the explicit project filter is invalid. Since the temporary file uniquely matches only React’s project, I’ll omit the project filter and pass the root-relative test path. - Assistant
The previous startup-error command’s cleanup did remove the temporary file, so the last invocation correctly found nothing. I’ll recreate it once more and run from root without a project filter; then remove it only after completion.
- Assistant
The test infrastructure now runs; the temporary test used
createRenderer()inside the test, while this repository requires creating it at suite/module scope. I’ll correct that harness detail and rerun. - Assistant
The fixed reproduction passes and confirms the key invariant: while fallback is visible, both original tab nodes remain connected and no spurious automatic value change occurs (
changescontains only the user’s B selection). To satisfy the requested reproduction check rigorously, I’ll temporarily save the modified source, restore the original root implementation, run the same focused test expecting its assertion to fail, then restore the fix and remove the temporary test. - Assistant
Baseline is now conclusively reproduced: after resolution it emits
[null, 'missing']and panel B is absent. The fixed source is restored. I’ll run the complete tabs test directory (including the existing genuine “all tabs removed” test), then TypeScript checking for the React package and inspect the final diff. - Assistant
All 209 tabs tests (171 run, 38 environment-skipped) pass, including existing fallback/removal coverage, and React TypeScript passes. The final diff reveals the direct line edit removed a visual blank line after the branch; I’ll run Prettier once more, then targeted ESLint and a final status/diff check before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.