Skip to content

Streamed document roots always lead with <!DOCTYPE html> (React Fizz parity) - #174

Merged
trueadm merged 1 commit into
mainfrom
claude/ssr-doctype-parity
Jul 19, 2026
Merged

trueadm merged 1 commit into
mainfrom
claude/ssr-doctype-parity

Conversation

@trueadm

@trueadm trueadm commented Jul 19, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The remaining octane follow-up from docs/ssr-stream-injection-plan.md (after #169 and #168): the <!DOCTYPE html> preamble was gated on the injection document mode, but it is actually a React parity behavior — verified empirically against react-dom 19.2.7:

  • Streaming (renderToPipeableStream / renderToReadableStream): Fizz emits <!DOCTYPE html> whenever the root renders <html>; its own test harness asserts a doctype-less <html> is "almost certainly a bug in React" (ReactDOMFizzServer-test.js:237, canary b740af2).
  • Buffered (renderToString / renderToStaticMarkup): no doctype — React leaves it to the caller.

What

  • The streaming shell prepends <!DOCTYPE html> for document roots unconditionally — detected by an O(wrapper-depth) prefix scan (hydration block markers + <html), so fragment streams pay a few byte compares, not a body scan. The injection document mode keeps its tail-holding/head-folding behavior but no longer owns the doctype.
  • Buffered renderers stay doctype-free, matching React. The vendored Start bot path (finalizeBufferedHtml) already prepends its own onto the buffered output — no doubling.
  • Incidental: the injection branch's tail scan is now gated on the same document-root check, sparing injected fragment renders the full-body suffix scan.
  • Docs (docs/ssr.md), changeset, and the plan doc updated.

Testing

  • New doctype parity suite in streaming-ssr-injection.test.ts (× both compile modes): streamed pipeable + web documents lead with exactly one doctype, fragments never receive one, buffered document renders stay bare. The three streaming pins were red-checked against the pre-change runtime (exactly those fail, everything else passes).
  • Full suite 11311 passed, zero failures (clean run); octane + octane-prod projects 7846 passed; website ssr-hydration e2e 32/32 on a cold vite cache — the native Start path already emitted the doctype via document mode, so website output is byte-identical.
  • streaming-ssr bench flat (staggered shell 0.13ms / all-fast 0.11ms — at or below prior baselines); typecheck, format, changeset checks green.

🤖 Generated with Claude Code


Note

Low Risk
Targeted streaming shell assembly change with explicit parity tests; buffered APIs and fragment streams are unchanged aside from documented doctype behavior.

Overview
Streaming SSR now prepends <!DOCTYPE html> whenever the shell root is a document (<html>), matching React Fizz — not only when injection document mode is active. Detection uses a cheap prefix scan (isDocumentRoot); fragments are unchanged.

Injection document mode still holds the closing tail and folds styles/head into <head>, but that path is gated on documentRoot so injected fragment renders skip the full-body tail scan. Buffered renderToString / renderToStaticMarkup stay doctype-free (React parity).

Docs, changeset, and contract tests were updated; the no-injection streaming case now expects the doctype on the first chunk.

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

…parity)

React Fizz emits the doctype whenever the STREAMED root renders <html> —
its test harness treats a doctype-less <html> as "almost certainly a bug in
React" (per ReactDOMFizzServer-test.js:237, React canary b740af2) — while
the buffered renderToString/renderToStaticMarkup emit none (verified against
react-dom 19.2.7). Octane now matches on both sides: the streaming shell
prepends <!DOCTYPE html> for document roots regardless of the injection
option (previously document-mode-only), detected by an O(wrapper-depth)
prefix scan so fragment streams pay a few byte compares; buffered renderers
stay doctype-free (framework bot paths that want one — e.g. Start's
prerender handler — already prepend it themselves).

Also gates the injection branch's tail scan on the same document-root check,
sparing injected fragment renders the full-body suffix scan.

Evidence: doctype parity suite added to streaming-ssr-injection.test.ts
(streamed pipeable/web documents lead with exactly one doctype, fragments
never, buffered stays bare — the three streaming pins red-checked against
the pre-change runtime); octane + octane-prod 7846 passed; full suite 11311
passed clean; website e2e 32/32 cold cache (the native Start path already
emitted the doctype, so website output is byte-identical); streaming-ssr
bench flat; typecheck/format/changeset green.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel

vercel Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Ready Ready Preview, Comment Jul 19, 2026 12:13am
octane-website-mcp Ready Ready Preview, Comment Jul 19, 2026 12:13am

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 19, 2026 00:13 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 19, 2026 00:13 Inactive
@trueadm
trueadm merged commit e0c2f09 into main Jul 19, 2026
21 checks passed
@trueadm
trueadm deleted the claude/ssr-doctype-parity branch July 19, 2026 00:24

This branch was previously deployed

2 inactive deployments
Preview – octane-website — 308fdf7d Deployed Jul 19, 2026 by vercel[bot]
Preview – octane-website-mcp — 308fdf7d Deployed Jul 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant