Skip to content

Hydration: collapse the hydration engine back into the mount path (Ripple/Svelte-style cursor), 23 kB → ~5 kB gzip #2028

Closed

Description

@trueadm

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:

  1. 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-local rollback/undo/speculative state. React gets the same observable behaviour by throwing to the nearest boundary and client-rendering it through its normal path.
  2. A separate hydration path for each boundary kind. Dehydrated Suspense, stream rejection payloads, server-caught @try replay (takeServerCatch, replayCaughtTry, fallBackServerCatch), lazy roots and Activity ordering each have their own adoption code instead of reusing the boundary's client retry path.
  3. 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/sibling and block open/close read the cursor directly when hydrating. 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, @try or 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, $RX rejection 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.

  1. Measure. Add a createRoot twin of the shell_ app, or a hydrate knockout row, so the bench report tracks the hydration delta on every PR (reported only, no budget).
  2. 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.
  3. One marker protocol. Delete post-hydration compaction and the range-lending and remainder machinery it needs.
  4. Recovery through boundaries. Delete per-value settlement and hydration-local rollback/undo, and move diagnostics to dev-only code.
  5. Boundary hydration through client retry. Dehydrated Suspense, stream rejection and lazy roots. Server errors switch to React's model: @catch stops 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).
  6. Collapse HydrationCapability into 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-frame scenario 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:

  • @catch no longer catches during server rendering. A server error inside a @try with @pending marks that boundary for client rendering, which Octane already does for errors no @catch handles. A catch-only @try with no enclosing @pending lets 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.md and docs/differences-from-react.md (the "@try body whose server render threw adopts the server's @catch arm" 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

  1. added
    perf
    agent-authored
    on Oct 13, 2026
  2. trueadm commented on Oct 13, 2026

    @trueadm
    CollaboratorAuthor

    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 Vite load hook; "est." means sized from attribution.

    A fairer React reference

    React 19.3's hydration costs about 16 kB raw / 5 kB gzip in total:

    • the named hydration functions: 9.2 kB raw / 2.7 kB gzip
    • event replay: 3.8 kB raw / 1.1 kB gzip
    • isHydrating branches 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:

    • compiled templates (eager and lazy, with two root checkers)
    • strong/lite/void components
    • deopt createElement children
    • childSlot and the six text-hole forms
    • keyed lists
    • @if/@switch/Activity
    • try/Suspense
    • portals
    • head
    • about 20 attribute writers
    • direct signal bindings

    That is where renderInPlace/renderUnframed/settleUnclaimed and 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() : null appears about 150 times across 131 functions. Bundlers can't drop unused class methods, so every method's dependency graph ships whenever hydrateRoot does.

    What each piece is

    Class Meaning Examples
    (a) React-parity requirement text mismatch → boundary client render; dehydrated Suspense; $RC/$RX; useId/Activity; root entry
    (b) Octane-only feature signal seeds + native adoption; use() seeds + rejection payloads; server-caught @try replay (React streams $RX and client-renders, but never server-renders a catch arm); stale-capture attribute comparison; binding leases; <Hydrate> islands; passthrough ranges; range compaction
    (c) incidental per-tier claim variants; capability-class indirection; unframed in-place adoption; lazy-template parse-free checks; the DOM undo log

    Measured by stubbing in the full app (raw / gzip):

    Stubbed piece Class Saving
    signal seeds b −5.6 / −1.6
    range compaction b −4.9 / −1.4
    use() seeds b −3.9 / −1.2
    binding leases b −1.6 / −0.5
    server-catch replay b −1.6 / −0.5
    stale-capture compare b −0.9 / −0.3
    passthrough ranges b −0.9 / −0.3
    <Hydrate> islands b −0.4 / −0.1
    all (b) together b −19.9 / −6.0
    unframed in-place adoption c −1.9 / −0.4
    lazy-template parse-free checks c −1.3 / −0.5
    DOM undo log c −0.7 / −0.2
    all (b) plus these three (c) −23.7 / −7.1

    That 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:

    Item raw
    cursor ops with tag check and range open/close ~2 kB
    text compare, empty text, suppressHydrationWarning 0.4 kB
    one attribute-skip guard plus pre-hydration form values 0.5 kB
    mismatch → clear range, client render, onRecoverableError 1.5 kB
    dehydrated Suspense (pending/client render), lazy keeps server HTML, $RC/$RX ~4 kB
    Activity and useId 0.4 kB
    root entry and Float/foreign skipping 1.5 kB

    Keeping 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:

    Change Saving
    tryBlock installs renderInitialSuspenseHydration instead of the capability constructor (TRY_OPS already works this way) −2.3 / −0.8
    hydrateRootWithOutputHandler skips installEarlyControlBridge, the seed-sidecar/native-manifest/document-signal capture, and ownNativeAdoption unless signals are imported −6.9 / −2.0
    use() seed methods installed by use() −3.9 / −1.2
    try/server-catch methods installed by tryBlock −3.6 / −1.2
    a __hydrateRootDefaultOptions counterpart, so registerRootErrorHandlers isn't always set −1.3 / −0.4
    all of these plus bindings and passthrough −21.6 / −6.8 (hydrate cost 21.3 → 14.5 kB gzip)

    Related: #2029 (commit model), #2030 (one renderer), #2031 (signals).

  3. trueadm commented on Oct 13, 2026

    @trueadm
    CollaboratorAuthor

    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, and codeSplitting groups that put Octane's runtime and signals engine in their own chunks. The app is the split-shell fixture 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 behind useTransition, @try over use(), 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 signals chunk
    executed through hydrate + one task 23.1% 27.0%
    executed after menu, portal and route-transition interactions 36.9% 31.6%

    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.

    Capability KB run at hydrate run after interactions largest never-run (bytes)
    hydration capability + adoption 56.1 33% 34% hydrateRootWithOutputHandler 2,295, coalesceHydratedRanges 1,078, HydrationCapability.adopt 974, renderInitialSuspenseHydration 949
    render core / roots / scheduler 46.8 29% 46% componentSlotImpl 3,461, renderBranchSlot 2,993, makeRoot 2,326
    Suspense / @Try / offscreen 35.1 15% 30% switchToCatchInner 1,803, attemptHiddenRevealInner 1,783, mountTry 1,596
    generic children / descriptors / de-opt 30.9 1% 15% childSlot 7,551, renderPreparedChildList 3,236, deoptItemBody 1,966
    transitions + render journal 23.7 6% 50% holdRootTransition 793, nativeCandidateForAction 717, rollbackRootRender 584
    keyed lists 18.6 10% 13% reconcileKeyed 3,970, forBlock 1,400
    deferred Hydrate / island activation 18.1 35% 38% activateHydrateBoundary 1,551, handleEarlyHydrationIntent 1,497, constructHydrationReplayEvent 1,316
    DOM props / forms / controlled 17.3 36% 48% maybeEnqueueRestore 1,317, setAttribute 1,260
    hooks / effects / refs 16.2 26% 36% detachRegisteredSubtreeRefs 1,032, reconnectBailedEffects 805
    native signal reads (renderer side) 14.0 31% 39% bindSignalChild 942, bindDirectSignal 800
    behavior root 12.8 32% 48% registerExternalRange 1,246, registerBehavior 799
    events 11.7 32% 61% dispatchDelegatedCapture 553, finishCaptureDispatch 422
    portals 4.4 1% 47% resolvePortalEventOwner 585
    other 30.2 26% 40%

    HydrationCapability alone 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.

    Bundle Unreferenced HydrationCapability members
    this shell ~1.3 KB (seedOrCreate 457, adoptBindingText 319)
    hydrate-frame fixture ~0.9 KB
    hydrate-root fixture 13.1 KB (71 members)
    deferred-hydration fixture 7.2 KB

    The 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 hydrating guards, and esbuild never folds those guards, so the move would grow esbuild and Rspack createRoot-only bundles. That violates the invariant documented in hydration-flag.ts and hydration-free-gates.mjs. Only renderSuspended, finishRoot and keepChanges, whose sole caller is activateHydrateBoundary, 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:

    • as one IIFE: 419,959 raw;
    • as split ESM chunks: 421,287 raw.

    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 (__derivedAt 746 B vs 220 B, visible 1,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.

  4. trueadm commented on Oct 13, 2026

    @trueadm
    CollaboratorAuthor

    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.

    fixture bundle (raw) dead class members of which HydrationCapability
    hydrate-root (one component, one text hole) 118,834 71 / 13,105 B 13,105 B
    deferred-hydration (one <Hydrate> island) 199,963 32 / 7,201 B 7,201 B
    hydrate-frame (components, @for, @if, @try + use(), style objects, portal, signals) 348,219 11 / 1,363 B 891 B

    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.

    gate (calling code) hydrate-root deferred-hydration hydrate-frame
    Component claim / in-place / unframed calls (componentSlotImpl, componentSlotLite) 2,577 – –
    Server-caught @try and unfinished arms (mountTry, mountErrorBoundary, catch switches) 2,511 – –
    Renderable holes (childSlot) 1,832 1,833 –
    Host value settlement (attribute, class and style setters) 1,273 1,273 21
    Text-only children (childTextHole) 1,226 1,226 –
    Branches (ifBlock, switchBlock, renderBranchSlot, activity) 925 520 –
    De-opt children (htextSwap, reconcileDeopt*) 665 665 –
    Compiled use() seeds (the seedOrCreate export) 457 457 457
    <Hydrate> island activation (activateHydrateBoundary) 413 – 413
    Returned values (renderReturnedValue) 413 413 –
    Keyed lists (forBlock, mountItem) 327 327 –
    Binding-view text holes (bindingText) 318 319 –
    innerHTML (setHTML) 168 168 –

    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.ts and run-hydration-free.mjs require that hydration bodies live on the capability or on a driver that hydration installs, because esbuild never folds the hydrating flag. I tested this by moving keepsStyle out of the class and adding it to the gate's hydration-only list:

    • create-root-export-vite still dropped it: oxc folds hydrating ? activeHydration() : null and the call behind it.
    • create-root-export-esbuild kept 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, finishRoot and keepChanges are called only from activateHydrateBoundary. As module functions beside it, the results (base 5594cb0, after #2033) were:

    row raw gzip brotli
    hydrate-root −413 −106 −87
    hydrate-frame −413 −88 −127
    deferred-hydration (uses an island, so keeps them) −67 −11 +41

    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:

    • No hydration test reached the island-trailing-content mismatch, which finishRoot reports. That is an island whose server HTML continues past its range, so the island must fall back once and remove the extra node.
    • Several files reach the resume of an island call that suspended in its own adopted range (renderSuspended re-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.
    • perf(hydration): ship island-only activation code only with <Hydrate> #2038 adds a HeldBranch fixture in tests/hydration/unframed-component-range.test.ts that pins both, under development and production compiles.
    • Observed, not changed: a server element injected inside an island's nested ranges, after the arm's content and before the island's closing markers, is kept with no mismatch reported. It is worth checking against the shared marker protocol.
  5. trueadm commented on Oct 13, 2026

    @trueadm
    CollaboratorAuthor

    Agent-authored note (Claude Code, for @trueadm).

    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.

    • Arms after the shell. hydrateRoot adopts 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, and act() drains waiting arms.
    • Selective hydration. A discrete event aimed at a dehydrated arm hydrates it synchronously, then dispatches the original event, as React 19 does at SyncLane.
    • Updates. An update or a context change that reaches a dehydrated arm hydrates it first, with the inputs and context its server HTML had, then applies the update. React does this with SelectiveHydrationException at a bumped lane. The arm renders on the client only when hydrating it first is impossible.
    • Resume without a parent replay. Resuming an arm must not re-render its parent. It renders only the boundary, as React re-enters the boundary's fiber.
    • Bench gate. Step 5 lands with the frame-boundaries scenario: 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-less frame scenario 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.

      • The shell does not yield: lanes & 127 takes renderRootSync.
      • Each server-rendered boundary is left at OffscreenLane and hydrated later by the time-sliced loop.
      • A boundary-less root is one task in React too.
    • 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):

      main prototype
      Longest task 96.8 ms 30.3 ms
      Busy total 96.8 ms 122.4 ms (+26%)
      renderBlockInner calls 1,674 2,886
      Production calls 291,195 362,291

      It also exposed four defects:

      1. An ancestor re-render client-rendered still-deferred arms, replacing 654 of 1,156 server elements.
      2. An early click on a deferred arm was lost.
      3. Effect order depended on device speed.
      4. A provider change before an arm's turn went undetected.

    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-boundaries at 4× CPU, 15 interleaved pairs against main:

    main at Longest task Busy total
    before #2033 87.7 → 20.5 ms (0.236 [0.232–0.240]) +3.8% (1.038 [1.024–1.046])
    5594cb06ea, after #2033 71.9 → 19.0 ms +3.9%

    frame was 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:

    • Direct resume. A deferred arm hydrates through the existing renderInitialSuspenseHydration, inside its root's render transaction and with its parent's render context. That context is CURRENT_BLOCK/CURRENT_SCOPE and the explicit signal owner of the pass that deferred it. Arms commit in batches, and the parent never re-renders.
    • Root-node capture listeners for selective hydration. While arms wait, a capture listener for each discrete interaction type sits on each arm's root node: the document, a shadow root, or a detached tree's top. An event aimed at a waiting arm hydrates that arm, and the arms around it, before the root's own listeners run.
    • Hydrate-first on update. In 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 dispatchDelegated never ran for a type no handler had registered yet. An input into a native signal control that had no onInput was lost, and the control's state diverged from the DOM.

    • preserveRootCreatedDom costs per Block. An arm rendered in a fresh, non-hydrating root transaction called it once per created Block: 1,660 calls on frame-boundaries, about +5% busy time. Inside the root pass the arms had hydrated with ROOT_DISCARD_STAMP = -1. Marking the arm's transaction hydrating brought production calls back to within 0.15% of main.

    • Hydrate before the update, not inside its render. Hydrating an arm inside its parent's update render failed in examples/hacker-news:

      • The router transitioner, a shell layout effect, canonicalizes / to /?page=1. That changed an external store before the arm's turn.
      • The arm then hydrated from matches the server never rendered, and fell back.

      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 for MatchesInner's first commit.

    • The suspended-arm retry still replays the parent. An arm whose own hydration suspends retries through resumeOnSettle → scheduleRender(state.parentBlock), as on main. Step 5 should give every dehydrated arm one resume route.

    • Remaining busy time. The +3.8% left was task posting (postHostTask and 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 needed await act().

    The frame-boundaries scenario 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).

  6. trueadm commented on Oct 13, 2026

    @trueadm
    CollaboratorAuthor

    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.

  7. 36 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-authoredperfssr

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions