Repository navigation
Description
Summary
The shell_ app from #2027 uses hydration, lazy routes, Suspense, ViewTransition, transitions and signals together. Octane ships 124.3 kB gzip of framework code for it, React 19.3 + alien-signals ships 69.8 kB. Hydration is the largest single contributor to the gap:
shell_ app, framework chunk (oxc, gzip -9) |
Octane | React 19.3 |
|---|---|---|
hydrateRoot → createRoot |
−23.3 kB gz (−72.5 kB raw) | −60 B |
base app (createRoot + useState) + hydrateRoot alone |
+21.2 kB gz | — |
In React, every function in react-dom-client.production.js whose name involves hydration adds up to about 10.5 kB of minified JS (canHydrateInstance, updateDehydratedSuspenseComponent, prepareToHydrateHostInstance, popHydrationState, selective-hydration and replay helpers…). That covers dehydrated Suspense and Activity boundaries, selective hydration and event replay. React also has hydration branches inside beginWork/completeWork; this count leaves them out. Octane spends about 7× that on hydration. This issue proposes going back to the model Octane's hydration cursor was ported from, Ripple's hydrate_node, which Svelte 5 also uses: the compiled mount code is the hydration code.
Where the 72.9 kB raw goes
Sourcemap attribution of the shell_ framework chunk. Minified bytes are mapped to the top-level declaration that owns them, and the variant without hydrateRoot is diffed against the full app:
| Mechanism | Raw bytes | Largest pieces |
|---|---|---|
HydrationCapability class (169 members) |
24,001 | adopt 1,512, keepsStyle 731, settleValues 624, renderInPlace 599, htextSwap 591, claimRange 549, adoptOrDefer 549, useSeed 533, keepsText 526 |
| Hydrating branches inside shared render paths | 9,820 | childSlot +1,905, componentSlotImpl +1,289, renderPreparedChildList +748, mountItem +628, reconcileDeoptChildren +593 |
| Suspense / try / lazy / Activity hydration | 9,199 | renderInitialSuspenseHydration 1,860, mountTry +1,484, takeInitialSuspenseHydration 1,410, decodeHydrationRejectionPayload 748, lazyRootHolds 443 |
| Other hydration helpers | 8,547 | mountPassthroughListItem 871, inline caught-error reporting (~1.2 kB), skipFoldedHeadPrefix 377, markHydrationDiscard 363 |
| Signal seeds + native-read adoption | 7,688 | getInitialDocumentCapture 1,313, parseSeedJson 919, validateNativeSignalManifest 730, materializeNativeSignalManifest 511 |
hydrateRoot entry, fallback, binding leases |
5,673 | hydrateRootWithOutputHandler 3,725, installHydrationFallback 452 |
| Post-hydration range compaction | 4,859 | coalesceHydratedRanges 4,745 |
| Marker / stream protocol helpers | 3,103 | isBindingOpenComment 773, hydrationMarkerMultiplicity 368 ×2 (identical copies in runtime.ts and stream-protocol.ts) |
Outside the class, 107 functions in runtime.ts branch on hydrating or currentHydration, so hydration lives both in a large capability class and in branches spread through the mount paths. Even with no signals, Suspense, lazy or lists, hydrateRoot still pulls in signal seed decoding (native-read-seeds, data-encoding, early-values), lazy-root holds, Suspense-boundary hydration and try/catch replay.
Why it outgrew the Ripple/Svelte model
The cursor itself is small. Three layers were built on top of it:
- Mismatch recovery as per-value settlement. Svelte trusts server HTML; when the structure doesn't match, it clears the range and mounts fresh. Octane implements React 19's rules: a differing text does not match, while attributes, class, style and raw HTML are kept and listed in development. It implements them with deferred per-value bookkeeping (
keepsText/keepsStyle/keepsClass/settleValues/pendingTexts/staleServerValues) plus hydration-localrollback/undo/speculativestate. React gets the same observable behaviour by throwing to the nearest boundary and client-rendering it through its normal path. - A separate hydration path for each boundary kind. Dehydrated Suspense, stream rejection payloads, server-caught
@tryreplay (takeServerCatch,replayCaughtTry,fallBackServerCatch), lazy roots and Activity ordering each have their own adoption code instead of reusing the boundary's client retry path. - Adoption code for each internal render shape. Lite components with no range owner, unframed roots, passthrough ranges, deopt children, keyed and fast-host lists, and native-read signal bindings each need claim logic (
claimRange,renderUnframed,wrapUnframedRoot,framedRootRemainder,fragmentRemainder,lendRange,parkInPlace, …). SSR also emits an explicit marker pair for every range while client mounts share coextensive ranges. A one-shot pass (coalesceHydratedRanges) therefore rewires owners and deletes redundant comments after every hydration. Svelte keeps its markers instead.
Target design
- One cursor, read inline by compiled mount code.
clone,htext,child/siblingand block open/close read the cursor directly whenhydrating. No capability class, and no adopt variant per render tier. Every render tier must use the same range-owner shape. Where a tier can't, merging tiers is part of this work, not a reason to add another adopt path. - One marker protocol shared by SSR and the client. The server emits exactly the anchors a client mount creates, or the client keeps the server's markers. Either way
coalesceHydratedRanges, lent ranges and the remainder/unframed logic go away. - Mismatch means throwing to the nearest boundary. A text or structural mismatch throws to the nearest Suspense boundary,
@tryor the root, which client-renders it and reports a recoverable error. That is React 19's rule. Attribute/class/style differences are never patched; finding and reporting them is development-only code in a dev-only module, so production ships no per-value settlement. - Boundaries hydrate through their normal client path. A dehydrated Suspense boundary is one whose content is still server DOM. Stream completion,
$RXrejection and timeout all go through the same retry entry point that client Suspense uses. Server errors follow React (decided below): the boundary is sent as its fallback, marked for client rendering, and the client renders it fresh, so there is no server catch arm to adopt. - Signals own their seeds. Seed and manifest decoding and native-read adoption live in the signals client module and register with hydration only when it is imported. A hydrated app without signals ships none of it.
Plan
Each step should land on its own with its hydration suites green and a measured shell_ delta.
- Measure. Add a
createRoottwin of theshell_app, or ahydrateknockout row, so the bench report tracks the hydration delta on every PR (reported only, no budget). - Signals own seeds and native-read adoption. Lowest risk. A hydrated app that doesn't import signals saves up to about 7.7 kB raw; in
shell_the code moves to the signals module rather than disappearing. - One marker protocol. Delete post-hydration compaction and the range-lending and remainder machinery it needs.
- Recovery through boundaries. Delete per-value settlement and hydration-local rollback/undo, and move diagnostics to dev-only code.
- Boundary hydration through client retry. Dehydrated Suspense, stream rejection and lazy roots. Server errors switch to React's model:
@catchstops catching during server rendering, the rejection seeds stop carrying error details, and the server-catch replay paths are deleted (takeServerCatch,replayCaughtTry,fallBackServerCatch,settleServerCatch,adoptServerCatch,skipServerCatchSeeds). - Collapse
HydrationCapabilityinto the cursor. Delete per-tier adopt variants; unify range owners across lite, void, framed and unframed roots.
Goal: hydrateRoot costs no more than about 5 kB gzip in the shell_ app, against 23.3 kB today.
Must keep
- React 19 parity:
- text mismatch → client render of the nearest boundary, with a recoverable error
- server attributes kept and not patched, development-only diagnostics
- shallow
suppressHydrationWarning - stable
useId - streaming boundary completion
- server-errored boundaries client-render
- Adoption of server DOM nodes (identity), preserved pre-hydration user input, live events and refs, and focus.
<Hydrate when>deferred hydration and signal seed adoption for apps that use them.- Hydration performance: the
hydrate-framescenario and the app-frame hydration bench must not regress.
Decided
Server errors use React's model (2026-10-13). React's server renderer never runs error boundaries. A throw or rejected use() inside a Suspense boundary calls onError, sends the fallback marked for client rendering (<!--$!-->, or $RX once streamed), and the client renders the boundary fresh, reporting through onRecoverableError. If the client render throws too, the nearest client error boundary catches it. A throw outside any Suspense boundary fails the shell (onShellError).
For Octane this means:
@catchno longer catches during server rendering. A server error inside a@trywith@pendingmarks that boundary for client rendering, which Octane already does for errors no@catchhandles. A catch-only@trywith no enclosing@pendinglets the error reach the nearest Suspense boundary or the shell, as in React.- Production stops serializing error names, messages and fields into the seed script. React sends only a digest; adding React's digest (the return value of
onError) is an optional follow-up. - This changes observable behaviour. Update
docs/ssr.mdanddocs/differences-from-react.md(the "@trybody whose server render threw adopts the server's@catcharm" paragraph), and add a changeset that describes it.
Open questions
- Option A: SSR emits the client's compact range layout. Option B: the client keeps explicit server pairs. B is simpler but leaves more comments in the DOM; A moves the work into the server renderer.
- The transition, Suspense and off-screen machinery has a parallel size problem (undo journal, held transitions, off-screen capture, hide/reveal/resume, ViewTransition staging). Step 5 should land after, or together with, any redesign there, so boundary recovery isn't built twice.
Refs: #2027 (benchmark), #1801 (size umbrella), #1921 (bundle-size review).
🤖 Generated with Claude Code
Activity
trueadm commentedon Oct 13, 2026
Deep-dive breakdown
This follows up the issue body with a detailed pass over the same
shell_build (oxc minify, gzip -9, framework chunk). "Measured" means a real build with the named code stubbed through a Viteloadhook; "est." means sized from attribution.A fairer React reference
React 19.3's hydration costs about 16 kB raw / 5 kB gzip in total:
isHydratingbranches inside other functions: about 3 kB (est.)Octane's hydration costs 72.5 kB raw / 23.3 kB gzip, which is 23.3 of the 54.5 kB gzip gap between the twins.
Root cause: the server's markers don't match the client's mount shapes
The server emits one generic marker protocol: a frame for every component call and a
<!--[-->for every hole. About 12 families of client mount paths (roughly 40 functions) each check for a frame (isOpen(anchor)) and handle the framed, unframed, borrowed, lent and passthrough cases themselves. The families are:createElementchildrenchildSlotand the six text-hole forms@if/@switch/ActivityThat is where
renderInPlace/renderUnframed/settleUnclaimedand the per-owner settle variants come from. Range compaction then deletes the redundant pairs this protocol leaves behind. In Svelte and Ripple, one compiler places identical markers on both sides, so the client never checks.Implication for the plan: step 3 (one marker protocol) is the prerequisite for step 6 (collapse the capability class). It should land first.
The capability class has about 95 methods and 60 fields and is called from 318 sites. The guard
hydrating ? activeHydration() : nullappears about 150 times across 131 functions. Bundlers can't drop unused class methods, so every method's dependency graph ships wheneverhydrateRootdoes.What each piece is
$RC/$RX;useId/Activity; root entryuse()seeds + rejection payloads; server-caught@tryreplay (React streams$RXand client-renders, but never server-renders a catch arm); stale-capture attribute comparison; binding leases;<Hydrate>islands; passthrough ranges; range compactionMeasured by stubbing in the full app (raw / gzip):
use()seeds<Hydrate>islandsThat leaves about 49 kB raw / 16 kB gzip of (a) and (c) tangled together, which only the cursor redesign untangles.
Estimate for "mount code is hydration code", keeping only (a): about 12–14 kB raw / 4–4.5 kB gzip:
suppressHydrationWarningonRecoverableError$RC/$RXuseIdKeeping signal seeds as an opt-in module adds about 5 kB raw / 1.6 kB gzip for apps that use signals. That would put the full
shell_app at roughly 106–107 kB gzip from hydration alone.Writing to the DOM during render also costs hydration
Hydration inserts fresh markers during render, so a discarded attempt needs a DOM undo log (
save/rollback/journalRootChildren). There are also separate initial, streamed, speculative and deferred-mismatch Suspense paths. React never touches the DOM during render, so it has one dehydrated-boundary path. Step 5 here should land on #2029's commit model rather than before it.Quick wins that don't need the redesign
Measured in the base app plus
hydrateRoot, raw / gzip:tryBlockinstallsrenderInitialSuspenseHydrationinstead of the capability constructor (TRY_OPSalready works this way)hydrateRootWithOutputHandlerskipsinstallEarlyControlBridge, the seed-sidecar/native-manifest/document-signal capture, andownNativeAdoptionunless signals are importeduse()seed methods installed byuse()tryBlock__hydrateRootDefaultOptionscounterpart, soregisterRootErrorHandlersisn't always setRelated: #2029 (commit model), #2030 (one renderer), #2031 (signals).
trueadm commentedon Oct 13, 2026
Hydration bytes in a split-chunk rolldown + oxc build
These are measurements to keep for this redesign; byte-tuning here is paused. The build is Vite 8 (Rolldown 1.1.5) with
minify: 'oxc', ESM output, andcodeSplittinggroups that put Octane's runtime and signals engine in their own chunks. The app is thesplit-shellfixture from #2032: an SSR shell hydrated through a dynamic import after a renderer-free behavior island activates. It has native signal reads,<Hydrate when={visible()}>, a lazy route behinduseTransition,@tryoveruse(), a portal and a keyed@for. Base is d37bd28.The runtime chunk was 336,999 raw / 106,892 gzip. After #2033 it is 331,940 / 105,346.
What runs (Chromium precise coverage, mapped to declarations through the source map)
Runtime chunk by owning capability
The grouping is by declaration-name heuristics, so the shares are approximate. Byte sizes are minified, attributed through the source map.
HydrationCapabilityalone is 23.2 KB in this chunk, and 72% of it never runs. It is about 110 small members (100–970 B each): mismatch recovery, server catch arms, unframed and lent ranges, and seeds. The happy path never reaches them, but a hydrating app must ship them under the current design.Members kept only because the class is kept
This is a fixpoint over member names that nothing outside dead members references.
HydrationCapabilitymembersseedOrCreate457,adoptBindingText319)hydrate-framefixturehydrate-rootfixturedeferred-hydrationfixtureThe large numbers come from those fixtures rendering a single component. A follow-up check found that most of these members can't simply move to module functions. Their callers reach every client behind
hydratingguards, and esbuild never folds those guards, so the move would grow esbuild and Rspack createRoot-only bundles. That violates the invariant documented inhydration-flag.tsandhydration-free-gates.mjs. OnlyrenderSuspended,finishRootandkeepChanges, whose sole caller isactivateHydrateBoundary, can move safely, for about 0.4 KB. That work is paused for this issue.Eliminations under rolldown + oxc split chunks
The #1855 and #1942 eliminations do happen. I built the same app with static imports two ways and compared them with the source-map oracle:
Both keep identical declarations, and the unused ViewTransition, Activity and staged-DOM drivers are absent from the split runtime chunk. The split costs 1.3 KB: cross-chunk import/export glue, plus oxc no longer inlining small functions across a chunk boundary (
__derivedAt746 B vs 220 B,visible1,204 B vs 784 B).Building against the published
dist/instead of source changes each chunk by at most 10 B. #2032 checks that the drivers stay out of the split runtime chunk.trueadm commentedon Oct 13, 2026
HydrationCapability: feature-only members that ship, and what each one is gated on
Measured on 2026-10-13 with
benchmarks/bundle-size/run-minimal.mjs(Vite 8, Rolldown, oxc minify) at d37bd28, before #2033. This tuning is now paused for this issue, so the numbers are recorded here as input to steps 3–6.Method
A bundler keeps every method of a class it keeps, so every hydrating bundle ships all of
HydrationCapability. I scanned each minified fixture for class members whose name is never read as a property anywhere in the bundle. The scan iterates to a fixpoint, so a member counts as live only if live code reads it. Bytes are minified source bytes of each member.<Hydrate>island)@for,@if,@try+use(), style objects, portal, signals)The 13 KB on hydrate-root comes mostly from it being a one-component fixture. With a realistic mix of features (hydrate-frame), almost every capability member is live, so the cost is the intrinsic size of the hydration paths, not reachability.
Dead members by the feature whose code calls them
Each row's gate is the client function that calls the members; a bundle without that feature never calls them, but still ships them.
componentSlotImpl,componentSlotLite)@tryand unfinished arms (mountTry,mountErrorBoundary, catch switches)childSlot)childTextHole)ifBlock,switchBlock,renderBranchSlot, activity)htextSwap,reconcileDeopt*)use()seeds (theseedOrCreateexport)<Hydrate>island activation (activateHydrateBoundary)renderReturnedValue)forBlock,mountItem)bindingText)innerHTML(setHTML)Largest single members: keepsStyle 683, renderInPlace 599, claimRange 549, htextSwap 486, hydrateOnlyChild 462, seedOrCreate 457, settleClaim 410, fallBackServerCatch 399, holeOpen 391, replayCaughtTry 379, renderUnframed 369, allowAttribute 346, takeServerCatch 334, adoptBindingText 318, renderAdoptedArm 314, settleServerCatch 291, hempty 275, renderTryBody 255.
The server-catch row (takeServerCatch, replayCaughtTry, settleServerCatch, skipServerCatchSeeds, adoptServerCatch, fallBackServerCatch) goes away with the React error model decision.
Why most of these cannot simply become tree-shakable module functions
Almost every caller above is client-reachable code.
hydration-flag.tsandrun-hydration-free.mjsrequire that hydration bodies live on the capability or on a driver that hydration installs, because esbuild never folds thehydratingflag. I tested this by movingkeepsStyleout of the class and adding it to the gate's hydration-only list:create-root-export-vitestill dropped it: oxc foldshydrating ? activeHydration() : nulland the call behind it.create-root-export-esbuildkept it.So making these members shake-able per feature would add each feature's hydration code to every esbuild (and probably Rspack) createRoot-only bundle that uses the feature. Bundlers keep whatever any path reaches, so only flag folding can give both per-feature hydration code and a hydration-free esbuild client. That is one more reason for the inline cursor this issue plans: hydration work that compiled mount code reads inline, behind a guard that folds, has no class to keep alive.
What can move safely today
Only members whose caller constructs the capability itself.
renderSuspended,finishRootandkeepChangesare called only fromactivateHydrateBoundary. As module functions beside it, the results (base 5594cb0, after #2033) were:Every other run-minimal row, including all createRoot-only Vite and esbuild rows, was byte-identical. This is parked as draft #2038 rather than landed, since the class is going away.
Test gaps found on the way
These are worth carrying into the cursor rewrite:
finishRootreports. That is an island whose server HTML continues past its range, so the island must fall back once and remove the extra node.renderSuspendedre-claiming that range), but none asserts on it. Skipping the re-claim left trailing server content inside the call's range in place, unreported, and all 252 tests that reach the path still passed.HeldBranchfixture intests/hydration/unframed-component-range.test.tsthat pins both, under development and production compiles.trueadm commentedon Oct 13, 2026
This issue is closed by accident. #2033's merge closed it, though that PR's body says it does not close #2028. Steps 3–6 remain, so @trueadm may want to reopen it.
Step 5's scheduling rule: hydrate Suspense boundaries after the shell
@trueadm decided on 2026-10-13 (#1864) how one large root yields during hydration. The decision goes into step 5: when boundaries hydrate through the client retry path, they follow React 19's schedule. This is the hydration half of #1864's scheduling work.
hydrateRootadopts and commits the shell in one task. Every server-resolved Suspense arm stays a dehydrated boundary whose content is still server DOM. Arms hydrate in later host tasks, in the order hydration reached them, so an outer arm comes before its nested arms. Each task hydrates at least one arm, and more while the shared ~5 ms host budget (yieldForHostBudget) lasts. The shell's effects run before any arm's, andact()drains waiting arms.SelectiveHydrationExceptionat a bumped lane. The arm renders on the client only when hydrating it first is impossible.frame-boundariesscenario: the app frame with its 11 sections in Suspense boundaries. It also adds trace-based longest-task and busy-total metrics. Gate: longest task under 50 ms at 4× CPU, busy total flat against the base, and the boundary-lessframescenario unchanged.Evidence from the 2026-10-13 evaluation
Each sample ran on a cold page at 4× CPU, in 15 interleaved rounds.
React 19.2.8.
lanes & 127takesrenderRootSync.Block-level budgets and load-deferred
<Hydrate>are unsafe. The render has no resumable unit. Committing per chunk breaks the guarantee that refs and layout effects see their children.load()deferral changes its documented contract.A budget-only prototype deferred arms past the budget and resumed them through
scheduleRender(parentBlock):mainrenderBlockInnercallsIt also exposed four defects:
Reference implementation: #2040
#2040 implements this policy on today's engine. It stays as a draft reference for step 5 and won't merge on this engine. Measured with
frame-boundariesat 4× CPU, 15 interleaved pairs againstmain:mainat5594cb06ea, after #2033framewas unchanged. Renders equalled Blocks: 1,674 for 1,674.#2040 builds three pieces on today's engine, and step 5 has to rebuild them on #2029's commit model:
renderInitialSuspenseHydration, inside its root's render transaction and with its parent's render context. That context isCURRENT_BLOCK/CURRENT_SCOPEand the explicit signal owner of the pass that deferred it. Arms commit in batches, and the parent never re-renders.tryBlock, new inputs that reach a waiting arm hydrate it from its server inputs first, then render the update over it.Lessons for step 5:
Delegation is lazy per event type, which is why the listeners have to be capture listeners above the root. A hook in
dispatchDelegatednever ran for a type no handler had registered yet. Aninputinto a native signal control that had noonInputwas lost, and the control's state diverged from the DOM.preserveRootCreatedDomcosts per Block. An arm rendered in a fresh, non-hydrating root transaction called it once per created Block: 1,660 calls onframe-boundaries, about +5% busy time. Inside the root pass the arms had hydrated withROOT_DISCARD_STAMP = -1. Marking the arm's transactionhydratingbrought production calls back to within 0.15% ofmain.Hydrate before the update, not inside its render. Hydrating an arm inside its parent's update render failed in
examples/hacker-news:/to/?page=1. That changed an external store before the arm's turn.Hydrating the arm before applying the update, as React's bumped lane does, avoids this.
Bindings may assume synchronous boundary hydration.
@octanejs/tanstack-router's transitioner assumes its match tree committed before the shell's layout effects. perf(octane): hydrate server-resolved Suspense boundaries after the shell #2040 had it wait forMatchesInner's first commit.The suspended-arm retry still replays the parent. An arm whose own hydration suspends retries through
resumeOnSettle→scheduleRender(state.parentBlock), as onmain. Step 5 should give every dehydrated arm one resume route.Remaining busy time. The +3.8% left was task posting (
postHostTaskand the budget sentinel, ~1.3 ms at 4×), one root transaction and commit per batch (~0.9 ms), and listener setup (~0.3 ms).Tests. About 15 existing test files asserted an arm's effects or handlers right after
hydrateRoot+flushSync, and neededawait act().The
frame-boundariesscenario and its trace metrics land separately, on today's engine, as the gate step 5 must pass.Refs: #1864 (policy), #2029 (commit model), #2040 (draft reference).
test(bench): add a Suspense-bounded app frame and trace its longest t…
trueadm commentedon Oct 13, 2026
The commit-model, one-renderer and signals issues are consolidated into #2043, which sets out the shared vision. This issue stays open for hydration. Under #2043's commit model, a hydrating render never runs commit functions and records adopted values as committed.
test(octane): audit where hydration probes for ranges
fix(octane): pass suspension on from a server @Try without @pending (#…
docs(octane): a server @Try without @pending does not hold a suspensi…
test(octane): gate hydration range probes by mount-path family (#2028)
feat(octane): render a returned value directly in its component's ran…
36 remaining items
perf(octane): let value writers keep adopted values, and stop trackin…
perf(octane): settle a Hydrate island's content like an adopted range…
perf(octane): settle every adopted range with one check, and drop lit…
perf(octane): settle a text hole's tail like any range, and move the …
perf(octane): client-render a root over a component's unframed markup…
test(lucide, phosphor-icons): hydrate the icon roots from Octane's ow…
fix(octane): render a server element entry as its component's root, a…
fix(octane): read a server descriptor's children only after the scope…
test: pin protocol v3 root marks in pack canaries, Bun preload, and p…
chore: point the Redact ledger's root-ownership reference at installH…
perf(octane): render computes, commit writes — runtime size redesign (#…
fix(octane): give a server descriptor list item with a portal child i…
fix(octane): classify adoptText's write under its function name in th…
perf(octane): move the hydration-only HydrationCapability methods to …
refactor: integrate next runtime redesign (#2103)