Skip to content

perf(hydration): keep the streamed-boundary validator out of client-only @try apps - #1623

Merged
domgan-oai merged 2 commits into
mainfrom
perf/try-stream-template-capability
Oct 3, 2026
Merged

domgan-oai merged 2 commits into
mainfrom
perf/try-stream-template-capability

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

mountTry claimed a streamed shell's pending <template data-oct-b> sentinel inline. As a result, every client app that uses @try/Suspense retained stream-protocol's isRendererStreamBoundaryTemplate → rendererRangeClose → hydrationMarkerMultiplicity graph, even though it never hydrates.

The claim is now HydrationCapability.claimStreamTemplate(cursor, end). It returns the boundary id, or null when the cursor isn't a renderer sentinel. HydrationCapability is constructed only on hydration paths, so client-only bundles drop the validator along with the class. The method body is the old branch body, unchanged: it removes the sentinel and the server fallback up to state.end, then sets the cursor. mountTry sets hasScopedBoundary, freshBoundary, streamedBoundaryId and adoptCursor from the result.

The other stream-protocol callers (resolveEventPath, isDormantServerHydrateOwner, hasPendingHydrateStreamReveal, permanentStaticHydrationRangeEnd) are only reachable from hydrating code. After this change, none of the validator's exports render in any never-hydrating client scenario. capture-only still keeps the validator, legitimately, through event-capture.

Bundle size

node benchmarks/bundle-size/run-minimal.mjs <scenarios>, one run before and after (byte counts are deterministic):

Scenario raw gzip brotli
suspense-transition 167387 → 166160 (−1227) 53803 → 53397 (−406) 47008 → 46752 (−256)
hydrate-root 169643 → 169728 (+85) 53945 → 53956 (+11) 47135 → 47135 (0)
deferred-hydration 233041 → 233126 (+85) 73828 → 73833 (+5) 63686 → 63769 (+83)
capture-only, cli-spa-starter, context, prop-attributes unchanged

The hydrating bundles grow slightly because of the method's definition and call.

dom-binding-protocol.ts stays in suspense-transition on main, because bindingText still retains it. The separate binding-text change moves that path into HydrationCapability. Checked with an unminified Vite probe, the module leaves suspense-transition only when both changes are applied; either one alone keeps it.

Reachability gate

run-minimal.mjs adds streamClaimFreeClientScenarios, the nine never-hydrating client scenarios. Each must not render isRendererStreamBoundaryTemplate from stream-protocol. hydrate-root is the control: it must still keep the export, so a rename can't make the check pass silently.

The check reads export names rather than whether the module is emitted. Every client bundle still ships about 104 bytes of stream-protocol, from the module-level `template[${STREAM_BOUNDARY_ATTR}]` selector that Rolldown can't drop. That leak is a separate follow-up.

Validation

  • pnpm format:check: scoped pnpm format:files:check on the changed files only
  • pnpm typecheck: scoped pnpm typecheck:files on runtime.ts, the fixture and the test only. No new errors versus main; the 117 errors in that selection are pre-existing, in the untyped streaming fixtures.
  • pnpm test: left to PR CI
  • targeted tests:
    • streaming-ssr.test.ts: 73/73 on both octane and octane-prod.
    • stream-ownership-collisions + ssr-stream-state-regressions: 26/26.
    • The other ssr-suspense fixture users (ssr-suspense, ssr-rejection-hydration-fidelity, ssr-render-options, hydration/suspense-hydrate): 112/112.
    • node scripts/react-parity/check.mjs --validate-only: current.
    • run-minimal.mjs on the scenarios above, with the new gate: passes.
  • Tests went red with the code broken:
    • With claimStreamTemplate disabled, 8 existing streaming tests fail, including "claims a still-pending shell…" (both variants) and "hydrates a pending shell with the template boundary useId namespace".
    • No existing test pinned the cursor write (this.node = end). The new test "keeps the client fallback when a root-level pending shell is claimed" (RootBoundary fixture) fails without it, because the root sweeps the client's fallback. It also fails with the claim disabled.

The local test runs above were against the pre-rebase base (6ea582e and 62e76bf). The rebase onto #1613/#1615 applied cleanly; CI runs the current head.

Risk / follow-ups

  • On main, a root-level streamed @try hydrated before its segment swaps has a separate bug: it reports a spurious "stale remainder was discarded" recoverable error and loses the boundary's end marker. The cursor parks on end, but a root-level slot must park past it. fix(hydration): park past every boundary, list, and activity range #1621's parkPast after mountTry fixes this; I applied its runtime diff locally and the error and lost marker both go away. The new test therefore doesn't assert on recoverable errors. Once fix(hydration): park past every boundary, list, and activity range #1621 lands, the test can add that assertion, and the cursor write here becomes redundant.
  • Whichever of this PR and the binding-text change lands second should add suspense-transition to that change's markerFreeClientScenarios.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Refactors hydration-critical @try/stream boundary claiming; behavior is covered by existing and new streaming tests, but mistakes could affect streamed SSR hydration or root-level boundaries.

Overview
Moves streamed <template data-oct-b> boundary claiming off the generic @try mount path and onto HydrationCapability.claimStreamTemplate, which only exists when hydrating. Client-only @try/Suspense apps no longer pull in stream-protocol's isRendererStreamBoundaryTemplate and related range-marker helpers (~400 B gzip on suspense-transition); hydrateRoot behavior is unchanged—the same DOM cleanup and cursor update, now behind the hydration method.

mountTry delegates to hydration.claimStreamTemplate(adoptCursor, state.end) instead of inlining the validator. Bundle reachability adds streamClaimFreeClientScenarios and asserts those scenarios do not export the validator, with hydrate-root as the control that must still include it.

Adds RootBoundary and a streaming SSR test ensuring that when the boundary is the root's only output, claiming the pending shell does not discard the client-mounted fallback before resolve.

Reviewed by Cursor Bugbot for commit f501dc5. Bugbot is set up for automated code reviews on this repo. Configure here.

…nly @Try apps

mountTry claimed a streamed shell's pending <template> sentinel inline, so
every client app with @try/Suspense retained stream-protocol's
isRendererStreamBoundaryTemplate -> rendererRangeClose ->
hydrationMarkerMultiplicity graph even though it never hydrates. The claim
is now HydrationCapability.claimStreamTemplate, which returns the boundary
id or null; behavior is unchanged.

suspense-transition: -1227 raw / -406 gzip / -256 brotli. Hydrating
bundles: +85 raw, +5..11 gzip. run-minimal gates the validator's absence
for never-hydrating clients, with hydrate-root as the control.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Oct 3, 2026
@github-actions
github-actions Bot marked this pull request as draft October 3, 2026 00:29
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 1 timed operation(s) possibly slower
  • 🔴 bundle-reachability: 5 value(s) increased

Compares 8e900489e with effa6e353 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

target operation base head Δ noise
octane-tsrx replace 7.96 9.42 +18.3% ±15% 🟡 slower
All 20 timed operations (19 within noise)
target operation base head Δ noise
octane-tsrx run 3.53 3.83 +8.5% ±29% ⚪ within noise
octane-tsrx replace 7.96 9.42 +18.3% ±15% 🟡 slower
octane-tsrx add 3.76 3.85 +2.4% ±34% ⚪ within noise
octane-tsrx update 0.50 0.53 +6.0% ±39% ⚪ within noise
octane-tsrx select 0.23 0.24 +4.3% ±54% ⚪ within noise
octane-tsrx swap 0.46 0.54 +17.4% ±33% ⚪ within noise
octane-tsrx remove 0.49 0.49 −0.0% ±53% ⚪ within noise
octane-tsrx runlots 33.28 34.24 +2.9% ±25% ⚪ within noise
octane-tsrx select_lots 0.26 0.28 +7.7% ±53% ⚪ within noise
octane-tsrx clear 50.20 47.13 −6.1% ±15% ⚪ within noise
octane-jsx run 3.92 3.88 −1.0% ±6% ⚪ within noise
octane-jsx replace 9.12 9.20 +0.9% ±23% ⚪ within noise
octane-jsx add 3.56 3.56 −0.0% ±31% ⚪ within noise
octane-jsx update 0.74 0.76 +2.7% ±31% ⚪ within noise
octane-jsx select 0.54 0.50 −7.4% ±44% ⚪ within noise
octane-jsx swap 0.99 0.84 −15.2% ±45% ⚪ within noise
octane-jsx remove 0.81 0.70 −13.6% ±45% ⚪ within noise
octane-jsx runlots 33.23 31.41 −5.5% ±15% ⚪ within noise
octane-jsx select_lots 2.77 2.70 −2.5% ±26% ⚪ within noise
octane-jsx clear 49.16 50.67 +3.1% ±14% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 171,079 171,164 +85 (+0.0%) 🔴
hydrate-root gzip 54,316 54,319 +3 (+0.0%) 🔴
hydrate-root brotli 47,392 47,374 −18 (−0.0%) 🟢
deferred-hydration raw 234,493 234,578 +85 (+0.0%) 🔴
deferred-hydration gzip 74,202 74,209 +7 (+0.0%) 🔴
deferred-hydration brotli 64,035 64,086 +51 (+0.1%) 🔴
suspense-transition raw 167,390 166,163 −1,227 (−0.7%) 🟢
suspense-transition gzip 53,803 53,397 −406 (−0.8%) 🟢
suspense-transition brotli 47,025 46,699 −326 (−0.7%) 🟢

96 other measured values are unchanged.

@trueadm
trueadm marked this pull request as ready for review October 3, 2026 00:43
@domgan-oai
domgan-oai merged commit 27c2a12 into main Oct 3, 2026
43 of 49 checks passed
@domgan-oai
domgan-oai deleted the perf/try-stream-template-capability branch October 3, 2026 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants