Skip to content

fix: ship Float sheet resources discovered after the streaming shell - #727

Merged
trueadm merged 1 commit into
mainfrom
fix/streamed-late-float-sheets
Aug 12, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/streamed-late-float-sheets

Conversation

@trueadm

@trueadm trueadm commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Streaming SSR (renderToPipeableStream / renderToReadableStream) now ships Float sheet resources (<link rel="stylesheet" href precedence>, <style href precedence>) discovered after the shell flushed. Previously only the shell pass's head was ever written, so a sheet registered on a later resolution wave — a nested pending boundary's sheet, or an href computed from a use() resolution — appeared nowhere in the response.
  • Consequences fixed: streamed late content revealed unstyled (FOUC until hydration re-inserted the sheet client-side), and documents consumed without JavaScript permanently missed the CSS.
  • Unblocks the deferred ReactDOMFloat conformance behaviors: ReactDOMFloat-test.js:1923 (child boundary stylesheet in the reveal), :2041 and :2350 (partial-boundary resources hoist to the parent boundary), each cited in the new tests.

Why

Each resolution wave re-runs a full pass, but the wave loop only diffed pass.cssEntries (scoped CSS) — the pass's HeadBuffer sheet registrations were folded into a head string for the shell and discarded on every later pass. React ships late boundary stylesheets with the boundary reveal instruction; Octane dropped them entirely. Reveal gating on sheet load (suspensey commits) remains a documented non-goal — the sheet just has to reach the document.

Changes

  • packages/octane/src/runtime.server.ts
    • HeadBuffer.sheets changed from Map<precedence, concatenatedHtml> to per-resource Map<href, { precedence, html }>; headHtmlWithSheets derives precedence groups at fold time (byte-identical output, first-encounter group order preserved).
    • FullPassResult exposes the pass's sheet map; runStream tracks flushedSheets (seeded from the shell pass) and each wave ships only new tags via floatResourceChunk — real markup in a <div hidden data-oct-fr="…"> carrier ahead of the wave's segment reveals, so no-JS consumers still get working CSS.
    • New inline $OCTRH(id) in the stream swap runtime hoists carrier tags into document.head with the client's precedence-group insertion policy. A still-pending child boundary's sheet rides its parent's reveal wave (arm-root registrations run before the arm's use() throws), matching React's partial-boundary hoisting.
  • packages/octane/src/runtime.ts: once client Float resource state exists, resourceState() installs window.$OCTFR; $OCTRH hands tags to it so one live authority keeps dedupe and group ordering through mid-stream hydration (no duplicates in either direction). resetFloatResourceState() clears it.
  • packages/octane/src/constants.ts: new internal STREAM_RESOURCE_ATTR (data-oct-fr).
  • packages/octane/tests/_fixtures/float-stream.tsrx + a "streamed late boundaries" describe in float-resources.test.ts: dynamic-href sheet end-to-end (stream → head hoist → hydration adoption, CSP nonce on every emitted script), nested-boundary parent-wave hoisting, no re-ship of shell-flushed sheets, live-client-state routing race. Three cases were seen red pre-fix (dev + prod projects); the dedupe case was proven red against a deliberately broken implementation.
  • docs/ssr.md + design comments: the streamed-head divergence is narrowed — head elements and hints from late boundaries still recreate on hydration; the sheet family now streams.

Performance: no per-node/per-render path touched — all additions are gated behind pass.sheets !== null (null unless the page uses Float sheets), per-wave, or per-resource. The inline stream runtime grows 494 chars (~306 B gz alone) and is only emitted on responses with pending boundaries. No benchmark exercises Float SSR, so no wall-clock claim is made.

Validation

  • pnpm format:check — changed files clean; the repo-wide run can race git-ignored test-generated .react-cache-ssr/ files (pre-existing gap, follow-up task spawned)
  • pnpm typecheck
  • pnpm test — 21,106 passed; the handful of failures reproduce identically on unmodified main (day-picker date-drift assertions, alien-signals/hook-form pinned-upstream suites, vaul browser drag — local-environment issues, follow-up task spawned) or pass in isolation (octane browser events, drei e2e — parallel-run contention); none touch this diff's code paths
  • targeted tests: float-resources.test.ts 36/36 (dev + prod), streaming/SSR/stream-state suites 356/356, fizz conformance + hydration 806/806

Risk / follow-ups

  • Late-discovered resource hints and <script async src> Float resources still wait for hydration (unchanged, documented); follow-up if parity there matters.
  • A late boundary can still flash briefly while its CSS fetches — reveal gating on sheet load stays a documented non-goal.
  • Two bundled Octane runtime copies on one page share the single $OCTFR global — a pre-existing multi-copy hazard, unchanged.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


Note

Medium Risk
Touches the streaming SSR protocol and client Float resource registration ($OCTRH/$OCTFR), which affect head ordering and hydration adoption. Changes are gated behind Float sheet usage and covered by new end-to-end stream tests.

Overview
Streaming SSR now ships Float sheet resources discovered after the shell, fixing FOUC on late boundaries and missing CSS for no-JS consumers.

Each resolution wave diffs per-resource sheet registrations (href → tag) against what already flushed and emits new tags in a hidden data-oct-fr carrier ahead of segment reveals. Inline $OCTRH hoists them into document.head under client precedence grouping; once live Float state exists, tags go through $OCTFR so dedupe stays in one authority. Nested pending sheets ride the parent's reveal wave.

HeadBuffer.sheets is now keyed by href (groups fold at emit time). Docs narrow the streamed-head gap to non-sheet head elements/hints; tests cover dynamic hrefs, nested hoisting, shell dedupe, and mid-stream client-state handoff.

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

Streaming SSR dropped stylesheet-link and style Float resources whose
registration only ran on a post-shell pass (a nested pending boundary's
sheet, or an href computed from a use() resolution): only the shell
pass's head ever flushed, so late content revealed unstyled until
hydration re-inserted the sheet, and no-JS consumers never got the CSS.

HeadBuffer.sheets now keeps per-resource entries (href -> precedence +
tag; the fold derives groups byte-identically), each wave diffs them
against what is already on the wire, and new tags ship with the wave
chunk as real markup in a hidden data-oct-fr carrier ahead of the
segment reveals. The inline $OCTRH runtime hoists them into
document.head under the client's precedence grouping, handing tags to
the live client runtime (window.$OCTFR, installed once client Float
state exists) so one authority keeps dedupe and group order through
mid-stream hydration. A still-pending child boundary's sheet rides its
parent's reveal wave, matching React's partial-boundary hoisting.

Co-Authored-By: Claude Fable 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 Aug 12, 2026
@trueadm
trueadm marked this pull request as ready for review August 12, 2026 14:33
@trueadm
trueadm merged commit 603756a into main Aug 12, 2026
48 checks passed
@trueadm
trueadm deleted the fix/streamed-late-float-sheets branch August 12, 2026 14:45
trueadm added a commit that referenced this pull request Aug 12, 2026
PR #727 made streaming SSR ship Float stylesheet resources discovered after
the shell with their boundary's reveal wave, closing the gap #725 had
deferred three ReactDOMFloat-test.js ledger cases against. Flip those cases
(:1923 …7b6da8a5, :2041 …8d52f5f3, :2350 …745930fa) to covered with evidence
into the 'streamed late boundaries' describe, add one adapted test for the
:2350 inline-flush shape (inner boundary resolves first; its complete content
and sheet ride the parent's reveal wave exactly once), and regenerate the
coverage report. ReactDOMFloat planned drops 8 -> 5.

Co-authored-by: Claude Fable 5 <[email protected]>
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