Repository navigation
[tabs] Position pre-hydration indicator inside streamed Suspense - #5171
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,158.24 ms -50.52 ms(-4.2%) | Renders: 78 (+0) | Paint: 1,785.66 ms -95.85 ms(-5.1%)
13 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
e6257e8 to
f711d6e
Compare
5bed197 to
a1a38a3
Compare
atomiks
left a comment
There was a problem hiding this comment.
Review summary
The core rewrite looks correct. I regenerated the minified script from the template with terser (ecma: 2020) and it matches the committed prehydrationScript.min.ts byte-for-byte, and the common (non-streaming) SSR path is behaviorally identical to before (the removed if (activeTab != null && tabsList != null) block was already dead — both were guaranteed non-null by the earlier early-returns). The diff is a net simplification on top of the fix.
One non-blocking finding left inline: a newly-introduced ResizeObserver/DOM retention on an abandoned-before-reveal lifecycle.
Note — test coverage: the new ResizeObserver path has no automated coverage; the existing pre-hydration rendering tests only assert the script's presence, nonce, and post-hydration removal, not its runtime effect. That's hard to address in the current harness (jsdom has no layout so offsetWidth is always 0 and inline scripts aren't executed; the chromium env resolves #prehydration/tabs/indicator to the empty stub), so relying on the headless-Chromium repro + the experiment page is a reasonable call — flagging so the gap is a deliberate choice.
Verdict: Approve after nits — no correctness regressions; the only actionable item is the narrow-window observer retention, which can be mitigated or knowingly accepted.
🤖 Review generated with Claude Code
a1a38a3 to
f3009e9
Compare
9e126c7 to
388f08a
Compare
|
@atomiks Updated to add a lifetime timer which cancels the observer after 10sec of inactivity. |
388f08a to
622de68
Compare
PR reviewTwo correctness issues remain, one merge-blocking. I reproduced both DOM-level mechanisms in headless Chromium using the PR’s observer logic. I could not run the repository test suite locally. Bugs (2)1. 🔴 Hydration can resurrect an indicator for a stale server tabLocation: const activeTab = tabsList.querySelector('[data-active]');
observer = new ResizeObserver(() => {
if (!indicator.isConnected || !indicator.hasAttribute('hidden')) {
stop();
return;
}
if (activeTab.offsetWidth > 0 && tabsList.offsetWidth > 0) {
stop();
position();
}
});
That assumption is incorrect. The hydrated component intentionally leaves the indicator hidden when the controlled value has no matching tab, and this behavior already has explicit test coverage. The observer can nevertheless call Failure scenario: The server renders tab Fix: Revalidate ownership and selection before mutating: const currentActiveTab = tabsList.querySelector('[data-active]');
if (currentActiveTab !== activeTab) {
stop();
return;
}Capturing 2. 🟠 The observer disconnects before positioning has actually succeededLocation: if (activeTab.offsetWidth > 0 && tabsList.offsetWidth > 0) {
stop();
position();
}The callback considers only width before permanently disconnecting, while Failure scenario: A streamed list has a fixed nonzero size, while an active icon-only tab initially has a CSS/flex width but zero height until its image or styles resolve. Revealing the segment makes the width check pass, so the observer disconnects. Fix: Have Tests (1)1. 🟠 The new runtime observer path has no automated coverageLocation: The new runtime observer path has no automated coverage. The existing pre-hydration tests verify only that the script is emitted, has contents and a nonce, survives hydration, and is subsequently removed. None executes the script or exercises its delayed Failure scenario: Both bugs above, or a future regression where revealing the streamed segment no longer positions the indicator, pass the entire current test suite. Fix: Add a Chromium test or E2E fixture using the real generated script that covers:
Simplifications (0)No findings. Docs (0)No findings. VerdictRequest changes - the delayed observer can override hydrated state and display an indicator for a tab that is no longer active. 🤖 Review generated with Codex |
4b98341 to
db5f00d
Compare
The ResizeObserver only self-disconnects from its own callback, which never fires if the tabs subtree is removed while still 0×0. Arm a bounded timeout alongside observe() so the observer can't retain the subtree indefinitely, and clear it when the observer resolves early.
The delayed ResizeObserver in the pre-hydration script could override state that hydration had already settled: - It captured the server-rendered active tab and never revalidated it, so when hydration moved the selection (or selected a value with no matching tab, which intentionally keeps the indicator hidden), a late delivery would position the indicator over the stale tab and unhide it. The callback now bails once the captured tab loses `data-active`. - It disconnected on a width-only check while positioning requires both width and height, permanently giving up on tabs that were not yet fully measurable. Positioning now reports success, the observer only stops after it, and it watches the active tab as well as the list so the tab gaining size on its own still triggers a delivery. Add Chromium tests that execute the real generated script against hand-built server markup, covering segment reveal, the stale-tab guard, hydration taking ownership first, and a tab that becomes measurable late. Assisted by Claude Fable 5
db5f00d to
b8e1974
Compare
atomiks
left a comment
There was a problem hiding this comment.
PR review
No correctness regressions or merge-blocking issues found. The implementation is appropriately narrow overall, but one observer target appears unnecessary.
Bugs (0)
No findings.
Tests (0)
No findings.
Simplifications (1)
1. 🟡 Observe only the active tab
Location: packages/react/src/tabs/indicator/prehydrationScript.template.js:114
observer.observe(tabsList);
observer.observe(activeTab);Observing tabsList appears redundant. updatePosition() returns false only while the captured active tab has zero width or height, and it can return true only after that tab’s box becomes measurable.
Revealing the streamed Suspense segment changes the active tab from 0×0 to its rendered dimensions, so observing activeTab already covers the primary case. It also covers the independently-delayed width or height case exercised by the new test.
Failure scenario: There is no behavioral failure, but each pre-hydration indicator installs an additional observation that cannot independently make the positioning retry succeed.
Fix: Remove the list observation and retain only:
observer.observe(activeTab);The initial measurement, hydration guards, stale-selection guard, bounded timeout, and success-returning updatePosition() are otherwise all justified.
Docs (0)
No findings.
Verdict
Approve after nits - the implementation is correct, but the redundant tabsList observation can be removed to make the fix as small as possible.
🤖 Review generated with Codex
Problem
With streaming SSR,
<Tabs.Indicator renderBeforeHydration />stays[hidden]until hydration when the tabs are below a Suspense boundary that resolves after the shell. React parses such content inside a hidden container (<div hidden id="S:…">), so everything measures 0×0 and the prehydration script bails permanently on its zero-size guard.Repro: https://github.com/brijeshb42/base-ui-tabs-indicator-streaming-repro
There's also an experiment page in this PR (
/experiments/tabs/tabs-streaming-ssr, needspnpm docs:devsince it relies on server rendering) with the same setup against the repo source: a control tab bar, a streamed one, and hydration held back 5s so the pre-hydration window is easy to observe. Can be removed before merge.Screen.Recording.2026-07-04.at.10.52.44.PM.mov
Fix
On zero size, observe the tabs list with a ResizeObserver: inside the hidden segment it has no box so nothing fires, and when React reveals the segment it gains one — the callback runs after layout but before paint, so the indicator still never flashes in late. It disconnects on success or when hydration gets there first. The measurable-at-parse-time path is unchanged, and browsers without ResizeObserver degrade to today's behavior (wait for hydration).
Verified with the repro in headless Chromium (hydration delayed 4s): the streamed indicator goes from
{hidden: true, width: 0}to{hidden: false, width: 62}pre-hydration.The slider thumb prehydration script has the same failure mode; left out to keep this focused. Can be updated to have same behaviour.