Skip to content

Make production hydration template-free on the happy path - #218

Merged
trueadm merged 3 commits into
mainfrom
claude/adoring-banach-2749a6
Jul 21, 2026
Merged

trueadm merged 3 commits into
mainfrom
claude/adoring-banach-2749a6

Conversation

@trueadm

@trueadm trueadm commented Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

What

P1 of the news-benchmark hydrate regression plan: production hydration no longer parses (or clones) compiler templates on the happy adoption path.

  • Prod validation at an adoption root = nodeType + localName only (React parity — prod React hydration doesn't attribute-validate either). hydrationNodeMatches early-returns after the tag check in prod; dev keeps the full deep walk, attribute compare, and warnHydrationStructuralMismatch unchanged. All divergence is process.env.NODE_ENV-guarded (build-time stripped).
  • The root check is answered from the template's source string. LazyTemplateRecord gains a lazily-computed root descriptor (charcode scan — element tag, or nodeType 3/8 for text/anchor roots; the compiler-prewrapped octane-frag tag marks HTML multi-root fragments). The exported clone() routes prod-hydrating lazy templates to a new cloneLazy capability entry; it and the dev/non-lazy clone share one private adopt(), which resolves the parse only on cold paths: mismatch recovery, cursor-null client builds, and the once-per-hydrateRoot fragment root claim.
  • Edge cases: case-only tag differences fall back through toLowerCase (SVG case-adjustment table), and the HTML parser's one tag rewrite (<image> → img) is special-cased so it can't cause silent prod rebuilds.
  • Hydration never clones template DOM (adoption returns the server cursor — already true, now pinned by a Node.prototype.cloneNode spy).

Documented narrowing

In prod, same-tag branches differing only in static attributes (e.g. @switch cases all <span> with different class) are no longer detected, so no recovery fires for them; dev still warns + rebuilds. Tag-level and text-level mismatches still detect and recover in prod (text holes self-correct via the compiler-seeded prev value). Documented in docs/differences-from-react.md and docs/react-parity-migration-plan.md.

Tests

New prod-runtime describe in mismatch-structural.test.ts (stubs NODE_ENV=production; the runtime reads it at call time): parse-free + clone-free happy adoption, tag-level detection + silent recovery, the attribute-narrowing divergence (// OCTANE DIVERGENCE), and multi-root fragment adoption. The two contract-changing tests fail against the pre-change runtime; the recovery tests pass in both worlds. No existing tests weakened.

Validation

  • pnpm test: 12,086 / 12,087 across all projects incl. octane-prod and the website SSR-hydration e2e. The one failure is environmental and pre-existing: stale untracked pnpm leftovers in packages/tanstack-start/vendor/ trip package-boundary.test.ts locally (rm -rf fixes it; nothing tracked).
  • pnpm typecheck, pnpm format:check: clean.
  • Changeset added (patch).

Benchmark (news, prod builds, headless Chromium, 20 iters, same machine/run)

hydrate score / median
octane-tsrx before 1.78 / 1.80 ms
octane-tsrx after 1.54 / 1.60 ms
svelte (reference) 1.50 / 1.50 ms

Harness correctness gates green both runs (no-rebuild=true, interactive=true). Gap vs Svelte: 1.19× → 1.03×, before P0 (static template-namespace resolution, separate session) stacks on top.

🤖 Generated with Claude Code


Note

Medium Risk
Changes core hydration adoption and narrows prod structural mismatch detection (same-tag/static-attribute divergences may persist until client updates), though tag/text recovery and extensive new prod tests mitigate regressions on the hot path.

Overview
Production hydration no longer parses or clones compiler templates when server markup matches the client’s expected root nodeType + tag. The adoption check reads a lazily cached root descriptor from the template HTML string (cloneLazy / lazyRootMatches), so the happy path only compares against the server cursor.

Structural validation is split by environment: in production, hydrationNodeMatches stops after localName (React parity—no static-attribute or nested-static walk). Tag and text mismatches still recover; same-tag branches that differ only in static attributes are not detected in prod (dev keeps full compare, warnings, and rebuild). Template parsing is deferred to mismatch recovery, cursor-null client builds, and fragment root claims.

Docs and a new prod-runtime test block pin the contract (parse/clone-free adoption, silent tag-level recovery, attribute-narrowing divergence, fragment adoption).

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

Prod hydration now validates an adoption root by nodeType + localName
only (React parity: prod React doesn't attribute-validate either),
answered straight off the template's source string via a lazily-scanned
root descriptor — so adopting server DOM never parses the template.
Parsing happens only on the cold paths: mismatch recovery, client-side
mounts while hydration is suspended, and the once-per-root fragment
claim. Dev keeps the full deep walk + attribute compare + warnings,
build-time stripped behind NODE_ENV.

Tag-level and text-level mismatches still detect and recover in prod;
same-tag branches differing only in static attributes are no longer
detected there (documented narrowing in differences-from-react.md).
Hydration also never clones template DOM — that was already true
(adoption returns the server cursor) and is now pinned by a
Node.prototype.cloneNode spy.

news bench (prod, headless Chromium, 20 iters): hydrate 1.78 -> 1.54 ms
(Svelte 1.50 in the same run), correctness gates green.

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

vercel Bot commented Jul 21, 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 21, 2026 8:42pm
octane-website-mcp Ready Ready Preview, Comment Jul 21, 2026 8:42pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 21, 2026 20:26 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 21, 2026 20:27 Inactive
Comment thread packages/octane/src/runtime.ts Resolved
The compiler namespaces `image` roots as SVG (SVG_ONLY_TAGS), where the
parser keeps `image` and the exact compare already matches — so the
HTML-parser rewrite arm was unreachable for compiled templates, and on
an SVG-`image`/HTML-`img` branch swap it would wrongly adopt instead of
recovering.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 21, 2026 20:31 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 21, 2026 20:32 Inactive

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cd32300. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
Same fail-open shape as the image->img arm: for every VALID pairing the
parser canonicalizes the server localName to the source spelling (HTML/
MathML lowercase, SVG camelCase restored by the case-adjustment table),
so the exact compare suffices. The toLowerCase fallback only "matched"
invalid markup — an SVG-only camelCase root misplaced in an HTML parent
parses as a lowercased HTMLUnknownElement — where prod would then adopt
the wrong-namespace node while the pre-narrowing parsed-template compare
(and dev today) mismatches and rebuilds. Exact-only fails safe.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 21, 2026 20:41 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 21, 2026 20:42 Inactive
@trueadm
trueadm merged commit 40d562b into main Jul 21, 2026
22 checks passed
@trueadm
trueadm deleted the claude/adoring-banach-2749a6 branch July 21, 2026 20:50
mrdiyorbek-juraev added a commit to mrdiyorbek-juraev/octane that referenced this pull request Jul 22, 2026
Brings in 12 upstream commits, including the shared TSRX semantic analysis
across client/server/universal/Volar compilation (octanejs#230), the deferred
hydration fix (octanejs#229), Lynx Milestone 7 worklets (octanejs#227), template-free
production hydration (octanejs#218), and the dependency/TSRX toolchain refresh
(octanejs#223) with the release that followed it.

Two conflicts, both in generated files, resolved by taking upstream and
regenerating from the merged tree:

- docs/packages.md — 47 publishable packages upstream, 48 here. Verified
  as a strict superset: every package upstream lists is still present,
  and the only additions are `@octanejs/cmdk` and `packages/cmdk`.
- packages/octane-evals/.../manifest.jsonl — all 19 task ids match
  upstream, and a field-level comparison shows only
  environment.overlayLockfileHash and grader.graderDigest differ. No
  prompt, policy, reference or grader command changed, so task semantics
  are untouched; both fields derive from the lockfile, which necessarily
  moved.

pnpm install also rewrote pnpm-workspace.yaml as a side effect — it
flattened upstream's `*esrap_common` YAML anchor and appended
[email protected] to minimumReleaseAgeExclude. Both are reverted, so the file
differs from upstream by exactly one line: the `cmdk: 1.1.1` catalog pin
this package needs.

packages/cmdk is unchanged apart from one comparator re-wrapped by the
refreshed prettier; the whitespace-only diff is the entire delta.

Verified: 43/43 cmdk and cmdk-ssr against the new compiler, 48/48 evals
(including the corpus freshness gate), tsrx-tsc, tsgo, prettier, and all
five generated-artifact gates current.

This branch was previously deployed

2 inactive deployments
Preview – octane-website — ffcc24b5 Deployed Jul 21, 2026 by vercel[bot]
Preview – octane-website-mcp — ffcc24b5 Deployed Jul 21, 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