Skip to content

fix(ssr): balance list and binding ranges when revealing a streamed fallback - #1570

Merged
trueadm merged 5 commits into
mainfrom
fix/stream-fallback-list-ranges
Oct 2, 2026
Merged

trueadm merged 5 commits into
mainfrom
fix/stream-fallback-list-ranges

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The inline segment swap ($OCTRC) removes a pending boundary's fallback by walking the template's following siblings and balancing hydration comments. Its marker helper M counted only [ and [N opens. That missed two kinds of open, each closed by a plain ]:

  • @for ranges: [f0 (empty) and [f1 (items).
  • 'use dom bindings' receipts: [b;… and [f1;b;….

When a fallback renders one of these directly beside the <template data-oct-b> (not inside a host element), the walk ended at the wrong close:

  • Direct @for or @empty fallback: the fallback's close marker stayed in the DOM and the content was inserted before it. hydrateRoot then threw HierarchyRequestError: Node can't be inserted in a #comment parent.
  • Binding-view fallback: its root, list and item opens were all skipped, so fallback nodes stayed visible beside the revealed content.

@pending { <ul>@for…</ul> } was never affected, because the list markers sit inside the <ul>.

Fix:

  • dom-binding-protocol.ts exports BINDING_OPEN_TAIL_SOURCE, regular-expression source equivalent to isBindingOpenComment. It is a plain string literal beside that function, so client bundles drop it.
  • M embeds that source plus the [f0/[f1 arms, which come from hydration-markers.ts. It now accepts exactly the opens the client range parser accepts.
  • The optional streaming view-transition driver uses the same helper through $OCTRC.marker, so it now records an exit for every fallback element. $OCTRX doesn't walk ranges.
  • The client mountTry path that takes over a still-pending shell already found the boundary close through hydration.close, with the client's full marker grammar. It needed no change, and this PR adds a test for it.

Cost: the inline script grows by 106 bytes raw, 76 gzip and 76 brotli (2316 → 2422 raw), once per streamed document. Server CPU per render is unchanged because the script string is built once per process.

Validation

  • pnpm format:files:check on every changed file
  • octane-tsc -p packages/octane/tsconfig.json (0 errors)
  • pnpm typecheck (not run in full)
  • pnpm test (not run in full)
  • targeted tests, after merging current main: streaming-ssr, view-transition-ssr, wire-protocol-single-owner, ssr-stream-state-regressions, stream-ownership-collisions, ssr-suspense, hydration/suspense-hydrate, hydration/range-boundary, scalar-dom-bindings, binding-handoff, in the octane and octane-prod projects: 743/744 pass. The one failure, ssr-suspense "streams a waterfall of already-resolved thrown resources without pacing it", is a wall-clock assertion. With main's source for both changed files on the same machine (load average ~55), it failed in 3 of 4 runs, so it is not caused by this change.
  • pnpm sync (no generated changes)

New tests. Each one failed with the old helper:

  • Stream, reveal, then hydrateRoot: fallbacks with list items, an @empty list, and binding views with one and three items. Each case checks: no leftover fallback, adoption of the content and of the sibling after the boundary, no console.error or onRecoverableError, and a working click. Before the fix: HierarchyRequestError, or visible fallback nodes.
  • Parity: the emitted swap script runs over 39 payloads (valid opens and near misses). For each one it must stop at the boundary close the client range parser finds. A loose ^(f[01]|b;) rule passes the behavioral tests but fails here, as does . in place of [^] for a key containing U+2028.
  • View-transition driver: a fallback with two direct lists and a trailing element. Before the fix, the trailing element's exit was never recorded.
  • Still-pending shell: hydrating before the segment arrives, with a list or binding-view fallback. The test fails if the client's [f0/[f1 counting is broken.

Risk / follow-ups

  • If a new kind of range-open marker is ever added, it has to go into both copies of hydrationMarkerMultiplicity and into BINDING_OPEN_TAIL_SOURCE. The parity test only catches drift for the payloads it lists.

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
Changes inline streaming swap logic and marker grammar parity; mistakes could mis-boundary streamed reveals or hydration, though coverage is extensive.

Overview
Fixes streamed Suspense reveal when the @pending fallback outputs @for list markers or a 'use dom bindings' view directly next to the stream template (not wrapped in a host element).

The inline $OCTRC swap script’s range-balancing helper M previously treated only plain [ / [N opens; it now also counts [f0 / [f1 and binding receipt opens, using exported BINDING_OPEN_TAIL_SOURCE plus hydration marker prefixes embedded at build time so the walk matches the client rendererRangeClose grammar. That removes stray close comments ( HierarchyRequestError on hydrateRoot ) and leftover fallback DOM, and lets the streaming view-transition driver record every fallback exit.

Adds parity tests over many marker payloads, end-to-end stream/hydrate cases for list and binding fallbacks (including still-pending shells), and a ListExitApp view-transition regression.

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

trueadm and others added 2 commits October 2, 2026 15:15
…allback

The inline segment swap ($OCTRC) removed a pending boundary's fallback by
balancing hydration comments, but its marker helper counted only `[` and
`[N` opens. A fallback that renders an @for list (`[f0`/`[f1`) or a
'use dom bindings' view (`[b;…`, `[f1;b;…`) directly beside the stream
sentinel closed those ranges with plain `]`, so the walk ended early: it
left the fallback's close marker (hydrateRoot then threw a
HierarchyRequestError) or left fallback nodes visible beside the content.

The helper now accepts every open the client range parser accepts. The
binding grammar is exported once, as regular-expression source beside
isBindingOpenComment, and the inline runtime embeds it. The optional
view-transition driver shares the helper through $OCTRC.marker, so it now
captures the exit of every fallback element as well.

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 fix PR: bug fix labels Oct 2, 2026
@github-actions
github-actions Bot marked this pull request as draft October 2, 2026 15:03
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 15:08
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No size increases and no timing regressions outside noise.

Compares fdf54feac with 2d2069c85 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)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 3.85 3.73 −3.1% ±28% ⚪ within noise
octane-tsrx replace 9.47 9.55 +0.8% ±16% ⚪ within noise
octane-tsrx add 3.83 3.88 +1.3% ±21% ⚪ within noise
octane-tsrx update 0.66 0.65 −1.5% ±35% ⚪ within noise
octane-tsrx select 0.34 0.26 −23.5% ±50% ⚪ within noise
octane-tsrx swap 0.67 0.51 −23.9% ±58% ⚪ within noise
octane-tsrx remove 0.70 0.55 −21.4% ±43% ⚪ within noise
octane-tsrx runlots 33.56 33.71 +0.4% ±15% ⚪ within noise
octane-tsrx select_lots 0.30 0.32 +6.7% ±46% ⚪ within noise
octane-tsrx clear 50.43 54.18 +7.4% ±21% ⚪ within noise
octane-jsx run 4.09 4.65 +13.7% ±47% ⚪ within noise
octane-jsx replace 9.71 11.34 +16.8% ±44% ⚪ within noise
octane-jsx add 3.53 3.68 +4.2% ±16% ⚪ within noise
octane-jsx update 0.96 0.86 −10.4% ±50% ⚪ within noise
octane-jsx select 0.60 0.71 +18.3% ±54% ⚪ within noise
octane-jsx swap 0.97 0.89 −8.2% ±42% ⚪ within noise
octane-jsx remove 0.92 0.98 +6.5% ±49% ⚪ within noise
octane-jsx runlots 32.56 37.74 +15.9% ±36% ⚪ within noise
octane-jsx select_lots 2.79 3.20 +14.7% ±35% ⚪ within noise
octane-jsx clear 54.75 56.21 +2.7% ±14% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

No changes across 105 measured values.

CI job durations

  • 🟡 8 job(s) slower than every recent main run: test shard (Node 24, 2/4), test shard (Node 24, 1/4), lint checks, test shard (Node 24, 4/4), test shard (Node 24, 3/4), validate publishable packages, example apps (3/3), example apps (1/3)
  • 🟢 2 job(s) faster than every recent main run: typecheck checks, React parity checks

Compares the CI run for 707a2027e (run) with the last 3 successful main push runs. A job is only slower or faster outside the whole main range, by at least 10% and 15s. Job time excludes runner setup.

The run concluded failure; only successful jobs are timed.

job main median main range this PR Δ
wall clock (first job start to last job end) 8m 39s 7m 39s–8m 45s 13m 40s +5m 01s (+58%) ⚪ partial run
total job time 87m 11s 86m 21s–91m 45s 143m 50s +56m 39s (+65%) ⚪ partial run
test shard (Node 24, 2/4) 5m 23s 5m 21s–5m 35s 12m 06s +6m 43s (+125%) 🟡 slower
test shard (Node 24, 1/4) 6m 09s 6m 05s–6m 09s 12m 30s +6m 21s (+103%) 🟡 slower
lint checks 3m 17s 2m 50s–3m 26s 9m 22s +6m 05s (+185%) 🟡 slower
test shard (Node 24, 4/4) 5m 45s 4m 34s–6m 08s 11m 22s +5m 37s (+98%) 🟡 slower
test shard (Node 24, 3/4) 5m 28s 5m 17s–5m 35s 11m 04s +5m 36s (+102%) 🟡 slower
validate publishable packages 2m 22s 2m 21s–2m 30s 4m 15s +1m 53s (+80%) 🟡 slower
example apps (3/3) 2m 57s 2m 54s–2m 59s 3m 53s +56s (+32%) 🟡 slower
example apps (1/3) 2m 59s 2m 54s–3m 00s 3m 29s +30s (+17%) 🟡 slower
typecheck checks 4m 32s 3m 54s–4m 33s 3m 01s −1m 31s (−33%) 🟢 faster
React parity checks 2m 45s 2m 44s–2m 46s 12s −2m 33s (−93%) 🟢 faster

Not compared (skipped, failed, or not run on this pull request): Lynx compatibility (minimum), heavy integration (runtime-loaders), Three compatibility (minimum r156), Three compatibility (current), heavy integration (browser), heavy integration (eval-corpus), website integration suite, Lynx compatibility (current), test shard (Node 22.22.2, 1/4), heavy integration (package-builds), heavy integration (astro), test shard (Node 22.22.2, 2/4), test shard (Node 22.22.2, 3/4), test shard (Node 22.22.2, 4/4), test (24), test (22), CI provenance.

All 23 timed jobs
job main median main range this PR Δ
heavy integration (package builds, eval corpus, runtime loaders, Astro) – – 5m 19s – 🆕 new
heavy integration (browser - chromium) – – 13m 09s – 🆕 new
React parity shard (2/4) – – 10m 34s – 🆕 new
Lynx compatibility – – 1m 41s – 🆕 new
React parity shard (4/4) – – 11m 24s – 🆕 new
Three compatibility – – 3m 11s – 🆕 new
React parity shard (1/4) – – 11m 15s – 🆕 new
React parity shard (3/4) – – 11m 26s – 🆕 new
test shard (Node 24, 2/4) 5m 23s 5m 21s–5m 35s 12m 06s +6m 43s (+125%) 🟡 slower
test shard (Node 24, 1/4) 6m 09s 6m 05s–6m 09s 12m 30s +6m 21s (+103%) 🟡 slower
lint checks 3m 17s 2m 50s–3m 26s 9m 22s +6m 05s (+185%) 🟡 slower
test shard (Node 24, 4/4) 5m 45s 4m 34s–6m 08s 11m 22s +5m 37s (+98%) 🟡 slower
test shard (Node 24, 3/4) 5m 28s 5m 17s–5m 35s 11m 04s +5m 36s (+102%) 🟡 slower
validate publishable packages 2m 22s 2m 21s–2m 30s 4m 15s +1m 53s (+80%) 🟡 slower
example apps (3/3) 2m 57s 2m 54s–2m 59s 3m 53s +56s (+32%) 🟡 slower
example apps (2/3) 3m 16s 3m 16s–5m 23s 3m 59s +43s (+22%) ⚪ within noise
example apps (1/3) 2m 59s 2m 54s–3m 00s 3m 29s +30s (+17%) 🟡 slower
classify changeset release 9s 8s–10s 17s +8s (+89%) ⚪ within noise
lint 2s 2s–2s 8s +6s (+300%) ⚪ within noise
typecheck 2s 2s–3s 7s +5s (+250%) ⚪ within noise
examples 3s 2s–3s 6s +3s (+100%) ⚪ within noise
typecheck checks 4m 32s 3m 54s–4m 33s 3m 01s −1m 31s (−33%) 🟢 faster
React parity checks 2m 45s 2m 44s–2m 46s 12s −2m 33s (−93%) 🟢 faster

trueadm and others added 2 commits October 2, 2026 16:34
…ture

The binding-view fallback compiles to a presentation-binding server import
that ssr-render-options.test.ts's own loader does not provide, so adding it
to ssr-suspense.tsrx broke that suite's module setup. The list-fallback
fixtures now live in their own file, loaded through the shared
loadServerFixture harness, and ssr-suspense.tsrx is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit b98179f into main Oct 2, 2026
53 of 56 checks passed
@trueadm
trueadm deleted the fix/stream-fallback-list-ranges branch October 2, 2026 15:58
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 fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant