Repository navigation
[tabs] Fix suspended panel activation - #4903
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,548.94 ms +161.24 ms(+11.6%) | Renders: 50 (+0) | Paint: 2,333.79 ms +235.95 ms(+11.2%)
7 tests within noise — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
aa3bcc6 to
165a731
Compare
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 AssessmentThis fixes #4880, where a The root cause is that Suspense can clean up tab registration effects while keeping the DOM nodes connected. The PR’s fix is minimal and well-placed: VerificationValidated across both reviews:
Opus 4.8 additionally reported:
Opus 4.8 NotesOpus also called out a few optional considerations:
|
flaviendelangle
left a comment
There was a problem hiding this comment.
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 togetTabElementBySelectedValue(value)and break the fix, because during a Suspense reveal the selected tab may not yet be intabMap. - Tighten the comment at
TabsRoot.tsx:286-287to mention theisConnectedmechanism 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 = undefinedaftercommitAutomaticValueChange(null, REASONS.missing)to drop the strong reference to a now-detachedNode. 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, andfindByTextretries. The test analyzer ran this 5× without flake. - Consider adding
aria-selectedassertions afterfindByText('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 thedidRegisterTabsRef.currentguard, 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:880already locks in the!isConnectedpath — 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.
isConnectedis the correct minimal probe and is already shadow-DOM-safe by spec (consistent withCompositeList.tsx:58's same usage). - No CLAUDE.md/AGENTS.md violations: uses
useIsoLayoutEffect, noas any, no globaldocument/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, theelsebranch reassigns the probe ref. shouldNotifyInitialValueChangeRefconcern is unfounded — by the time the new Suspense-skip branch can fire (requiresdidRegisterTabsRef.current === true), the initial-notify ref has already been cleared in a prior commit.
Recommended Action
- Merge as-is is defensible — none of the items above are blocking.
- If the author has a spare minute: add the comment on
TabsRoot.tsx:299(load-bearing line, biggest maintainability win) and drop the redundantawait Promise.resolve();in the test. - The suggested follow-up tests (initial-mount suspension, re-suspension) could be a separate small PR if desired but aren't required.
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
Tabs.Root.