Repository navigation
fix(ssr): balance list and binding ranges when revealing a streamed fallback - #1570
Conversation
…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]>
Benchmark report🟢 No size increases and no timing regressions outside noise. Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 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
Compares the CI run for The run concluded
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
|
…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]>
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 helperMcounted only[and[Nopens. That missed two kinds of open, each closed by a plain]:@forranges:[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:@foror@emptyfallback: the fallback's close marker stayed in the DOM and the content was inserted before it.hydrateRootthen threwHierarchyRequestError: Node can't be inserted in a #comment parent.@pending { <ul>@for…</ul> }was never affected, because the list markers sit inside the<ul>.Fix:
dom-binding-protocol.tsexportsBINDING_OPEN_TAIL_SOURCE, regular-expression source equivalent toisBindingOpenComment. It is a plain string literal beside that function, so client bundles drop it.Membeds that source plus the[f0/[f1arms, which come fromhydration-markers.ts. It now accepts exactly the opens the client range parser accepts.$OCTRC.marker, so it now records an exit for every fallback element.$OCTRXdoesn't walk ranges.mountTrypath that takes over a still-pending shell already found the boundary close throughhydration.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:checkon every changed fileoctane-tsc -p packages/octane/tsconfig.json(0 errors)pnpm typecheck(not run in full)pnpm test(not run in full)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 theoctaneandoctane-prodprojects: 743/744 pass. The one failure,ssr-suspense"streams a waterfall of already-resolved thrown resources without pacing it", is a wall-clock assertion. Withmain'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:
hydrateRoot: fallbacks with list items, an@emptylist, 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, noconsole.errororonRecoverableError, and a working click. Before the fix:HierarchyRequestError, or visible fallback nodes.^(f[01]|b;)rule passes the behavioral tests but fails here, as does.in place of[^]for a key containing U+2028.[f0/[f1counting is broken.Risk / follow-ups
hydrationMarkerMultiplicityand intoBINDING_OPEN_TAIL_SOURCE. The parity test only catches drift for the payloads it lists.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith 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
@forlist markers or a'use dom bindings'view directly next to the stream template (not wrapped in a host element).The inline
$OCTRCswap script’s range-balancing helperMpreviously treated only plain[/[Nopens; it now also counts[f0/[f1and binding receipt opens, using exportedBINDING_OPEN_TAIL_SOURCEplus hydration marker prefixes embedded at build time so the walk matches the clientrendererRangeClosegrammar. That removes stray close comments (HierarchyRequestErroronhydrateRoot) 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
ListExitAppview-transition regression.Reviewed by Cursor Bugbot for commit 707a202. Bugbot is set up for automated code reviews on this repo. Configure here.