Skip to content

fix(octane): render a server element entry as its component's root, as hydrateRoot does - #2078

Merged
trueadm merged 4 commits into
mainfrom
fix/ssr-element-entry-root
Oct 15, 2026
Merged

trueadm merged 4 commits into
mainfrom
fix/ssr-element-entry-root

Conversation

@trueadm

@trueadm trueadm commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • renderToString(<App />), renderToReadableStream(<App />) and the other server entry points (renderToStaticMarkup, renderToPipeableStream, prerender, and prerenderToNodeStream through prerender) now render a component element as that component's root, the way hydrateRoot(container, <App />) does. Either server entry form now hydrates through either hydrateRoot form with no recoverable error.
  • Found while working on perf(octane): render computes, commit writes — runtime size redesign (#2043) #2044, the runtime redesign. This ports that branch's fix to main's server runtime and wire format.

Why

  • Given an element, the server rendered it as a value the root returns (renderEntryValue → ssrChild(<App />)), which frames App in a range of its own. hydrateRoot(container, <App />) unwraps an element whose type is a function into the root's body and props, as it does for App itself, so the client expects App's content with no surrounding range. The two sides disagreed, so hydration discarded the server DOM and client-rendered with a recoverable error.
  • The new matrix test, packages/octane/tests/hydration/root-entry-forms.test.ts, fails 80 of 256 cases on main (e8e155514c) across the octane and octane-prod projects. Every failure is a server element entry where App returns a component, a fragment, a Suspense boundary or a template, or renders its children. In each one, every server <p>/<main> node is replaced on hydration. Every server pairing given App itself already passes, as do element entries whose root returns host JSX, text or null.
  • With this change: 256 of 256 pass.

Changes

  • packages/octane/src/runtime.server.ts:
    • New renderEntry(entry, props, options) mirrors hydrateRoot's rule. A component element renders as that component's root, with the props its descriptor renders it with. A component function passes through unchanged. Any other value (a host element, Fragment, array, primitive or null) still renders through renderEntryValue, with the second argument read as options.
    • The five server entry points use it in place of their identical inline preludes.
    • descriptorProps(d) is extracted from ssrComponentDescriptor's three branches. It holds the existing scoped-props / omitted-children / legacy-children rule and is shared by both callers.
  • packages/octane/tests/hydration/root-entry-forms.test.ts + _fixtures/root-entry-forms.tsrx: the matrix covers renderToString and renderToReadableStream, each given App or <App />, against hydrateRoot(c, App, props) and hydrateRoot(c, <App />). The roots return host JSX, a template, a component, a fragment, text, null, a Suspense boundary, or their children, all with props, in dev and prod compiles. Each case asserts that every server element stays connected, that there are no recoverable errors, and that no hydration console.error fires. It asserts behaviour rather than marker text, so it needed no wire-format changes from the perf(octane): render computes, commit writes — runtime size redesign (#2043) #2044 version.
  • docs/ssr.md: a paragraph in the renderToString section on the element entry form.
  • .changeset/server-element-entry-root.md: octane patch.

Validation

  • targeted: pnpm vitest run --project octane --project octane-prod packages/octane/tests/hydration/root-entry-forms.test.ts: 80 failed / 176 passed of 256 on main (before the fix), then 256 / 256 passed.
  • targeted: pnpm vitest run --project octane --project octane-prod packages/octane/tests/hydration/ packages/octane/tests/hydration-ssr-diagnostics.test.ts packages/octane/tests/hydrate-compiler.test.ts packages/octane/tests/ssr plus the 38 conformance files that render on the server (every packages/octane/tests/conformance/*.test.* that imports octane/server or calls a server renderer): 470 files, 20,938 tests passed.
  • targeted: pnpm vitest run --project octane --project octane-prod packages/octane/tests/server-renderable-contract.test.ts: 102 passed. It covers host, primitive, array and empty roots through renderToString/renderToStaticMarkup/prerender, plus second-argument options for a component element root in all five transports.
  • pnpm vitest run --project website-unit: 31 files, 443 tests passed.
  • harbor e2e (examples/harbor, pnpm test:e2e): 4 / 4 passed. Harbor uses <App /> on both sides through React's renderToPipeableStream/hydrateRoot, with Octane islands inside, so it is end-to-end host-integration evidence rather than a direct exercise of Octane's own element entry.
  • pnpm typecheck: passed. pnpm typecheck:files on the changed source, test and fixture also passed.
  • pnpm format:files:check on the five changed files: passed.
  • pnpm sync: no generated changes.
  • pnpm format:check (repo-wide): not run; the changed files were checked directly.
  • pnpm test (full): not run locally; left to CI.
  • perf-review: see below.
  • one-off check (not committed): for all 8 fixture roots, renderToString(<App />) and renderToString(App, props) produced byte-identical HTML, and so did the two renderToReadableStream forms.
  • concise-code: src +38 −54 (runtime +38 −54, all in the server runtime runtime.server.ts; the client runtime.ts is untouched). New files: the test and its fixture (the regression), plus the changeset. No new exports. Alternatives: (a) make hydrateRoot frame an element entry the way the server does. Rejected: it would change client hydration for every hydrateRoot(<App />) caller, and it would break the App-form servers, which already agree with the client. (b) Unwrap the element inline in each of the five entry points. Rejected: that is five copies of the same rule, where one renderEntry replaces the five copies already there. Bytes: client bundles unchanged (runtime.ts is untouched). The minified server runtime (esbuild, NODE_ENV=production, packages external) goes from 175,004 to 174,770 B raw (−234 B), and from 58,004 to 58,045 B under gzip -9 (+41 B).

Perf review: fix/ssr-element-entry-root (origin/main e8e1555..a51aadc)

Scan: node scripts/perf-review-scan.mjs → 0 candidates.
Hot paths touched: ssrComponentDescriptor (per component descriptor rendered on the server, per request). It now calls descriptorProps, which runs the same checks as before in the same order and returns the original d.props or the same single spread. That is one small monomorphic call, likely inlined, with no new allocation. renderEntry runs once per server render call, so it is cold. It allocates one 3-element tuple per request.

# Severity Location Dimension Finding Required evidence Provided?
— — — — No findings — —

Dismissed candidates: none.
Not checked: server request throughput, because the change adds no per-node work; no SSR bench was run.

Risk / follow-ups

  • The HTML for a component element entry changes: the root no longer sits inside its own <!--[-->…<!--]--> range, and it now matches renderToString(App, props) byte for byte (checked for the eight fixture roots). A consumer that hydrated renderToString(<App />) output with something other than hydrateRoot of App or <App /> could see a different frame. Within this repo, the tanstack-router, tanstack-start, astro, email and apollo bindings all pass the component form, so they are unaffected.
  • The element's key is not rendered for a root element. The client uses the root key only to decide whether a later root.render remounts, so it never affects markup, and renderToString(App, props) has no key either.
  • Root elements whose type is another callable built-in (a Context provider, Suspense, ViewTransition) now also render as the root, again matching the client's unwrap. Fragment and Activity are tag values, not functions, so they keep the renderEntryValue path. hydration-ssr-diagnostics (a Context provider element entry) passes.

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.


Note

Medium Risk
Changes SSR HTML framing for component-element roots (drops extra hydration range), which could affect consumers that relied on the old markup shape; core hydration paths are heavily tested.

Overview
Server render entry points now treat a root component element like hydrateRoot, so renderToString(<App {...props} />) (and streaming/static equivalents) produce the same framing as renderToString(App, props) instead of wrapping the element through renderEntryValue.

The server runtime adds shared renderEntry and descriptorProps helpers: component-function roots pass through unchanged; component-element roots unwrap to that component and its descriptor props; other roots still use the value-renderer path with the second argument interpreted as options. prerender, renderToString, renderToStaticMarkup, renderToPipeableStream, and renderToReadableStream all use this instead of duplicated prelude logic.

Docs note React-style element entry; a hydration matrix test covers server/client component vs element entry across root return kinds, plus a scoped-children SSR test when the entry is a scoped element.

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

…s hydrateRoot does

renderToString(<App />), and every other server renderer given an element,
rendered the element as a value its root returns (renderEntryValue), which
frames the component in a range of its own. hydrateRoot(container, <App />)
unwraps an element whose type is a component into the root's body and props,
as it does App itself, so the client root has no such range. When App returns
a component, a fragment, a Suspense boundary or a template, or renders its
children, the server's HTML did not match, and the root rendered on the
client with a recoverable error.

Each server renderer now reads its entry through renderEntry: a component
element renders as that component's root, with the props its descriptor
renders it with (descriptorProps, shared with ssrComponentDescriptor), and any
other value as before. The two entry forms produce the same HTML, and either
hydrates through either hydrateRoot form.

root-entry-forms pins every pairing of renderToString and
renderToReadableStream, each given App or <App />, with hydrateRoot given App
or <App />, for a root that returns host JSX, a template, a component, a
fragment, text, null, a Suspense boundary or its children, in dev and prod
compiles: 80 of its 256 cases fail before this change.

Client bundles are unchanged; the minified server runtime shrinks 234 B raw.

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 15, 2026
@trueadm
trueadm marked this pull request as ready for review October 15, 2026 10:50
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp a0f38ca Commit Preview URL

Branch Preview URL
Oct 15 2026, 12:00 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website a0f38ca Commit Preview URL

Branch Preview URL
Oct 15 2026, 12:02 PM

@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 prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Scoped children resolve too early
    • Moved the SCOPED_ELEMENT_PROPS.has(d.props) check before the d.children access in descriptorProps so scoped descriptors return d.props without triggering the deferred children getter in the parent scope.

Create PR

Or push these changes by commenting:

@cursor push 4ba11f9da9
Preview (4ba11f9da9)
diff --git a/packages/octane/src/runtime.server.ts b/packages/octane/src/runtime.server.ts
--- a/packages/octane/src/runtime.server.ts
+++ b/packages/octane/src/runtime.server.ts
@@ -2354,8 +2354,9 @@
 // with a distinct non-null children field need a repaired props object.
 /** The props a component descriptor renders its component with, its children among them. */
 function descriptorProps(d: ElementDescriptor): any {
+	if (SCOPED_ELEMENT_PROPS.has(d.props)) return d.props;
 	const children = d.children;
-	return SCOPED_ELEMENT_PROPS.has(d.props) || children == null || children === d.props?.children
+	return children == null || children === d.props?.children
 		? d.props
 		: { ...d.props, children };
 }

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit a51aadc. Configure here.

Comment thread packages/octane/src/runtime.server.ts Resolved
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-reachability: 1 value(s) increased

Compares 1622fa020, the merge commit's first parent with 1016bf321 on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.775 2.575 ±0.0% −7.2% … +3.6% ⚪ within noise
octane-tsrx replace 6.633 7.675 +3.2% −1.5% … +7.4% ⚪ within noise
octane-tsrx add 2.650 2.592 −0.0% −3.7% … +4.0% ⚪ within noise
octane-tsrx update 0.163 0.168 +1.1% −2.7% … +6.5% ⚪ within noise
octane-tsrx select 0.007 0.007 −0.6% −9.1% … +4.3% ⚪ within noise
octane-tsrx swap 0.020 0.021 +0.5% −2.5% … +5.8% ⚪ within noise
octane-tsrx remove 0.020 0.020 +2.0% −0.4% … +7.2% ⚪ within noise
octane-tsrx runlots 27.517 27.150 +0.0% −2.8% … +2.1% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 −1.0% −2.1% … +1.4% ⚪ within noise
octane-tsrx clear 47.325 50.258 −1.2% −3.9% … +0.5% ⚪ within noise
octane-jsx run 3.600 3.617 −7.4% −11.5% … −1.3% ⚪ within noise
octane-jsx replace 6.883 7.158 ±0.0% −3.7% … +8.2% ⚪ within noise
octane-jsx add 3.208 3.167 +0.0% −1.5% … +3.9% ⚪ within noise
octane-jsx update 0.261 0.256 −0.3% −2.6% … +1.6% ⚪ within noise
octane-jsx select 0.129 0.133 +0.3% −1.6% … +1.4% ⚪ within noise
octane-jsx swap 0.201 0.192 +0.0% −3.0% … +4.3% ⚪ within noise
octane-jsx remove 0.196 0.191 +1.1% −1.5% … +5.0% ⚪ within noise
octane-jsx runlots 34.542 34.225 +3.0% −4.1% … +5.2% ⚪ within noise
octane-jsx select_lots 1.745 1.730 +2.4% −2.2% … +5.6% ⚪ within noise
octane-jsx clear 46.950 51.817 +6.9% +1.8% … +8.9% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 93 measured values.

Public-import reachability bundles (bytes)

target metric base head Δ
server-render raw 64,153 64,136 −17 (−0.0%) 🟢
server-render gzip 22,069 22,085 +16 (+0.1%) 🔴
server-render brotli 20,001 19,991 −10 (−0.0%) 🟢

117 other measured values are unchanged.

trueadm and others added 3 commits October 15, 2026 12:07
…d check

A scoped component descriptor's children getter resolves deferred children,
so reading it first ran them in the parent's scope before the component
entered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit c6cb71a into main Oct 15, 2026
29 of 30 checks passed
@trueadm
trueadm deleted the fix/ssr-element-entry-root branch October 15, 2026 12:12
@trueadm trueadm mentioned this pull request Oct 15, 2026
6 of 7 tasks
trueadm added a commit that referenced this pull request Oct 15, 2026
* fix(octane): remove a .tsx Provider's children when they become null (#2076)

* fix(octane): remove a .tsx Provider's children when they become null

* fix(octane): remove CompiledContext children when they become null

* fix(octane): keep CompiledContext's emptied dialect so a rolled-back transition can't duplicate its children

* test(website): reload the dev /devtools warm-up once before failing

Main a9dfdf7 failed the website integration suite: the dev-SSR beforeAll
waited 120 s for the TanStack Devtools trigger on /devtools and skipped all 37
dev-SSR tests. The wait came with #2062 and has failed on main and two
branches since, while passing locally on every cold warm-up (~3.9 s).

The devtools client mounts after hydration from modules a cold dev server may
only discover on that first visit, and Vite recovers with a reload a slow
runner can miss. Wait 60 s, log what the first attempt saw, reload once, and
fail with the page errors if the trigger still never appears. The devtools
tests themselves still assert the trigger and panel on fresh loads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(three): render Canvas as a Strong template (#2080)

* fix(octane): seed nothing for a pending snapshot read instead of throwing (#2077)

A server module that reads module signals installs the native read collector
as it loads, and every later render in the process then collects its reads
for the hydration snapshot. A render that read a pending query through
snapshot(), such as an automatically streamed query, completed with a read it
could not seed and threw "A completed native server read has no serializable
ready value". On main 0bb503f, 28 of the 30 early-independent-intent cases
throw once that collector exists, while the same page renders in a server
that has loaded no such module.

A snapshot renders a pending or failed state as it is, without suspending.
The client resolves that state itself, or takes a stream's later delivery, so
the read now contributes no seed, which is also no invented ready one. A
completed value read of an unready source still throws.

The signals-hydration case that pinned the throw now asserts that contract:
the pending output renders with no hydration snapshot, adopts the same node,
and shows the result once the query resolves. The supplemental native DOM
smoke case says the same. The new streamed test loads a module-signal page,
renders a pending snapshot under streamed signals, hydrates while the client
is still pending, and takes the stream's result without a second fetch.

Co-authored-by: Claude Opus 5.5 <[email protected]>

* fix(octane): render a server element entry as its component's root, as hydrateRoot does (#2078)

* fix(octane): render a server element entry as its component's root, as hydrateRoot does

renderToString(<App />), and every other server renderer given an element,
rendered the element as a value its root returns (renderEntryValue), which
frames the component in a range of its own. hydrateRoot(container, <App />)
unwraps an element whose type is a component into the root's body and props,
as it does App itself, so the client root has no such range. When App returns
a component, a fragment, a Suspense boundary or a template, or renders its
children, the server's HTML did not match, and the root rendered on the
client with a recoverable error.

Each server renderer now reads its entry through renderEntry: a component
element renders as that component's root, with the props its descriptor
renders it with (descriptorProps, shared with ssrComponentDescriptor), and any
other value as before. The two entry forms produce the same HTML, and either
hydrates through either hydrateRoot form.

root-entry-forms pins every pairing of renderToString and
renderToReadableStream, each given App or <App />, with hydrateRoot given App
or <App />, for a root that returns host JSX, a template, a component, a
fragment, text, null, a Suspense boundary or its children, in dev and prod
compiles: 80 of its 256 cases fail before this change.

Client bundles are unchanged; the minified server runtime shrinks 234 B raw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(octane): read a server descriptor's children only after the scoped check

A scoped component descriptor's children getter resolves deferred children,
so reading it first ran them in the parent's scope before the component
entered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

* test(website): let the generated MDX hot-update test re-write and outwait a slow runner

Main 8318702 failed the website integration suite: "hot-updates
generated MDX twice while preserving the surrounding interactive page" timed
out waiting 20 s for an edit to reach the page. It also failed on
perf/runtime-size-redesign; it passes locally every time. Until 1622fa0
the /devtools warm-up flake skipped the whole dev-SSR block, which hid it.

Each edit now waits in 15 s rounds, re-writing the file between rounds in
case the watcher dropped a write that followed the previous one, for up to
60 s; the test's budget grows to 180 s. The assertions are unchanged: the
generated text updates, the sibling counter keeps its state, and no errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(octane): keep an emptied Provider's dialect, and refill it through a frontier (#2043)

Clearing an emptied CompiledContext at commit dropped its hooks map, so the
empty dialect was lost; it is now kept. A refill's reset opens the scope's
frontier like a dialect flip, so its incoming body builds off-document.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Olzhas Alexandrov <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: domgan-oai <[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