Skip to content

[tabs] Fix suspended panel activation - #4903

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:codex/fix-tabs-suspense-panel
Jun 1, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
atomiks:codex/fix-tabs-suspense-panel

Conversation

@atomiks

@atomiks atomiks commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4880

Opening a tab whose panel suspends no longer makes Tabs treat the temporarily empty tab registry as real tab removal.

Root cause

Suspense can clean up tab registration effects while keeping the previous tab nodes connected, so the automatic missing-tab fallback reset the value before the suspended panel could resume. The connectivity check has to run from the root effect after the DOM settles; during a real unmount, unregister can run before React detaches the DOM node.

Changes

  • Track a previously registered tab element and only commit the missing-tab fallback when that element is disconnected.
  • Add a React 19 Suspense regression test for opening a suspending panel with the boundary outside Tabs.Root.

@atomiks atomiks added component: tabs Changes related to the tabs component. type: regression A bug, but worse, it used to behave as expected. labels May 25, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 25, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4903
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4903
    

commit: c3acc13

@code-infra-dashboard

code-infra-dashboard Bot commented May 25, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+67B(+0.01%) 🔺+32B(+0.02%)

Details of bundle changes

Performance

Total duration: 1,548.94 ms +161.24 ms(+11.6%) | Renders: 50 (+0) | Paint: 2,333.79 ms +235.95 ms(+11.2%)

Test Duration Renders
Menu mount (300 instances) 199.54 ms 🔺+37.04 ms(+22.8%) 2 (+0)
Mixed surface mount (app-like density) 98.24 ms 🔺+17.44 ms(+21.6%) 5 (+0)
Select open (500 options) 65.64 ms 🔺+15.06 ms(+29.8%) 14 (+0)
Tooltip mount (300 contained roots) 65.86 ms 🔺+13.13 ms(+24.9%) 1 (+0)
Checkbox mount (500 instances) 69.01 ms ▼-22.67 ms(-24.7%) 1 (+0)

7 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented May 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit c3acc13
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a1d32c0e3b77a0008fa6cb5
😎 Deploy Preview https://deploy-preview-4903--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the codex/fix-tabs-suspense-panel branch from aa3bcc6 to 165a731 Compare May 25, 2026 06:19
@atomiks
atomiks marked this pull request as ready for review May 25, 2026 07:03
@atomiks

atomiks commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

Code Review (GPT-5.5 + Opus 4.8)

Approve ✅: Both reviews found the fix correctly scoped and validated by a regression test that fails on master and passes with the PR.

1. Bugs / Issues (None)

No blocking or non-blocking defects found.

Combined Assessment

This fixes #4880, where a Tabs.Panel child suspending with the Suspense boundary outside Tabs.Root left the panel blank until a second click.

The root cause is that Suspense can clean up tab registration effects while keeping the DOM nodes connected. TabsRoot then saw tabMap.size === 0 and incorrectly treated it as real tab removal, committing the missing fallback and resetting the value.

The PR’s fix is minimal and well-placed: TabsRoot tracks a previously registered tab node and only commits the missing-tab fallback when that node is actually disconnected.

Verification

Validated across both reviews:

Opus 4.8 additionally reported:

  • The test passes with the fix and fails when only the source fix is removed.
  • ESLint and Prettier passed for the changed files.
  • Typecheck showed only unrelated pre-existing TS6305 build-cache noise, with no tabs-related type errors.

Opus 4.8 Notes

Opus also called out a few optional considerations:

  • Tracking the first tab node is fine because any surviving tab works as the connectivity probe, but a short comment could make that clearer.
  • A theoretical reparenting case could keep the probe connected, though this is not a realistic Tabs concern.
  • Other composite components still share the cleanup-as-removal assumption, but Tabs is the one with missing-value auto-fallback behavior, so this scope is appropriate.

@flaviendelangle flaviendelangle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Branch restored. Here is the synthesized review.

PR #4903 Review Summary — [tabs] Fix suspended panel activation

Four specialized agents reviewed the PR (code quality, test coverage, comments, silent failures). Across all four, no critical or blocking issues were found. The fix is correct, minimal, and well-scoped. Below is the consolidated action plan.

Critical Issues

None. All four agents independently concluded the PR is ready to merge.

Important Issues

None. The previously-existing GitHub review comment (GPT-5.5 + Opus 4.8) had already cleared the fix; this deeper pass confirms it.

Suggestions (nice-to-have)

Source code (TabsRoot.tsx)

  • Add a comment on the probe-selection line at TabsRoot.tsx:299 — lastKnownTabElementRef.current = tabMap.keys().next().value;. This is the load-bearing line; the "any surviving tab works as the probe" rationale isn't self-evident. A future maintainer could "improve" it to getTabElementBySelectedValue(value) and break the fix, because during a Suspense reveal the selected tab may not yet be in tabMap.
  • Tighten the comment at TabsRoot.tsx:286-287 to mention the isConnected mechanism explicitly (e.g. "Use a previously-registered tab as a liveness probe: if it is still connected, the empty tabMap is a Suspense effect-teardown artifact, not a real removal"). Current wording "previous tabs connected" is ambiguous (could be read as prior selection).
  • Consider broadening "Suspense boundary outside the root" to "an ancestor Suspense boundary" — the same code path triggers wherever a Suspense ancestor is above the registered tabs.
  • Optional: clear lastKnownTabElementRef.current = undefined after commitAutomaticValueChange(null, REASONS.missing) to drop the strong reference to a now-detached Node. Not a real leak (single node), but tidies up.

Tests (TabsPanel.test.tsx)

  • Drop await Promise.resolve(); at line 71 — empirically verified the test still passes both jsdom and chromium without it. act's async-callback resolution already drains microtasks, and findByText retries. The test analyzer ran this 5× without flake.
  • Consider adding aria-selected assertions after findByText('Panel B') (lines 74-77) to catch a future regression where panel content renders by accident while value state is wrong.
  • Consider a follow-up test for initial-mount suspension (defaultValue="b" with a Tab B panel that suspends on first render). This locks in the didRegisterTabsRef.current guard, which is a different code path than the click-to-suspend case the new test covers.
  • The test arguably belongs in TabsRoot.test.tsx (the fix lives in TabsRoot's effect) per the project's file-per-source-file convention, but this is purely cosmetic.

Strengths

  • Empirically validated: the new test fails on master, passes on the PR, and mutation tests confirm each guard in the rewritten branch is covered by some existing test.
  • Pre-existing real-removal coverage at TabsRoot.test.tsx:880 already locks in the !isConnected path — no coverage gap there.
  • Suspense vs unmount discrimination is sound: when a sibling suspends, React tears down effects but leaves DOM connected; when tabs actually unmount, the host node is detached. isConnected is the correct minimal probe and is already shadow-DOM-safe by spec (consistent with CompositeList.tsx:58's same usage).
  • No CLAUDE.md/AGENTS.md violations: uses useIsoLayoutEffect, no as any, no global document/window, no shadow-DOM-unsafe traversal.
  • The "lonely tab removal" edge case can't fire — the new condition is inside if (tabMap.size === 0), so by definition no tab survives; if even one did, the else branch reassigns the probe ref.
  • shouldNotifyInitialValueChangeRef concern is unfounded — by the time the new Suspense-skip branch can fire (requires didRegisterTabsRef.current === true), the initial-notify ref has already been cleared in a prior commit.

Recommended Action

  1. Merge as-is is defensible — none of the items above are blocking.
  2. If the author has a spare minute: add the comment on TabsRoot.tsx:299 (load-bearing line, biggest maintainability win) and drop the redundant await Promise.resolve(); in the test.
  3. The suggested follow-up tests (initial-mount suspension, re-suspension) could be a separate small PR if desired but aren't required.

@atomiks
atomiks merged commit e9c3146 into mui:master Jun 1, 2026
6 checks passed
@atomiks
atomiks deleted the codex/fix-tabs-suspense-panel branch June 1, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: tabs Changes related to the tabs component. type: regression A bug, but worse, it used to behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants