Repository navigation
Conversation
…hell hydrateRoot now adopts the shell in one task and leaves each Suspense boundary the server resolved dehydrated, as React 19 leaves them at OffscreenLane (policy A, decided on #1864). Queued boundaries hydrate in later host tasks, at least one per task and more while the shared ~5 ms host budget lasts, rendered directly in their parent's context rather than through a parent re-render. - A discrete event aimed at a waiting boundary hydrates it first, from a listener on the boundary's root node installed only while boundaries are waiting. - New inputs from a parent render hydrate a waiting boundary from its server inputs first, then render the update over it. A context change before its turn hydrates it as stale (the <Hydrate> epoch check). - act() hydrates every waiting boundary. - benchmarks/app-frame-hydration gains the frame-boundaries scenario, trace-based longest-task and busy metrics, and an early-click check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
View logs |
octane-website | dfdeeac | Oct 13 2026, 11:51 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
View logs |
octane-website-mcp | dfdeeac | Oct 13 2026, 11:51 AM |
…race A sample's trace can lack the RunTask around a task tracing joined late, or drop a long task entirely. Count the outermost main-thread events, with each microtask checkpoint folded into its task, wait a frame before the measured task, and rerun a sample whose longest task is shorter than its hydrateRoot call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
Autofix Details
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Effects can skip the clicked arm
- When re-entrant effects during commitEffects/drainPassivesBeforeRender splice an earlier arm from the queue, the matched arm shifts left; the fix searches for the shifted state via indexOf and updates the index instead of blindly continuing.
- ✅ Fixed: Shadow clicks miss waiting arms
- Replaced event.composedPath()[0] with event.target so that events from open shadow trees use the retargeted shadow host node, which is in the light DOM tree where the arm's start/end markers live and thus passes rangeContains.
Or push these changes by commenting:
@cursor push 21a894a6b1
Preview (21a894a6b1)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -43389,7 +43389,7 @@
*/
function hydrateEventTarget(event: Event): void {
if (DEFERRED_ARMS && !inFlush && CURRENT_BLOCK === null)
- DEFERRED_ARMS.hydrate(event.composedPath()[0] as Node);
+ DEFERRED_ARMS.hydrate(event.target as Node);
}
function listenForArmInput(host: Node, listen: boolean): void {
@@ -43427,7 +43427,11 @@
settled = true;
commitEffects();
drainPassivesBeforeRender();
- if (arms.queue[i] !== state) continue;
+ if (arms.queue[i] !== state) {
+ const shifted = arms.queue.indexOf(state);
+ if (shifted === -1) continue;
+ i = shifted;
+ }
}
arms.queue.splice(i, 1);
hydrateDeferredArm(state);You can send follow-ups to the cloud agent here.
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
62 other measured values are unchanged. Public-import reachability bundles (bytes)
87 other measured values are unchanged. |
…e hydrates The transitioner's mount layout effect assumed the match tree had already committed. Hydration now leaves the router's server-rendered Suspense boundary for a later task, so canonicalizing the URL (/ to /?page=1 in the hacker-news example) started a navigation that hydrated the boundary from matches the server never rendered and replaced its rows. When the location is already resolved, the mount work now waits for MatchesInner's first commit. Also lists the deferred-arm listener and range checks as reviewed native operations for check-staged-dom. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… hydration tests Their readers and loads sit in Suspense arms, which now hydrate after the shell; flushSync no longer reaches them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closing without merging. Per @trueadm's decision, the arm deferral folds into #2028 step 5, on #2029's commit model, rather than landing on today's engine. The rule and this PR's findings are on #2028 and #2029. The branch The open Bugbot findings (a re-entrant dequeue and shadow-DOM targets) and the CI reds are deliberately not addressed here. Step 5 should cover both cases. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Mount work races with early clicks
- Replaced synchronous
mount?.()call in MatchesInner's layout effect withqueueMicrotask(mount)so the deferred mount work runs after event dispatch ends, letting the click handler's navigation take precedence over URL canonicalization.
- Replaced synchronous
Or push these changes by commenting:
@cursor push 810070112a
Preview (810070112a)
diff --git a/packages/tanstack-router/src/Matches.tsrx b/packages/tanstack-router/src/Matches.tsrx
--- a/packages/tanstack-router/src/Matches.tsrx
+++ b/packages/tanstack-router/src/Matches.tsrx
@@ -58,12 +58,16 @@
if (acknowledgement[0] === matches) settleOwner(acknowledgement, true);
}, [acknowledgement, matches]);
// The router's mount work waits for this first commit (useTransitioner).
+ // Defer the call: selective hydration flushes this effect in the capture
+ // phase of the discrete event that revealed the arm, before the event
+ // reaches its handler. A synchronous commitLocation here would race with
+ // the click's own navigation. A microtask runs after event dispatch ends.
useLayoutEffect(() => {
const routerState = router as any;
routerState._matchesCommitted = true;
const mount = routerState._mountAfterMatches;
routerState._mountAfterMatches = undefined;
- mount?.();
+ if (mount) queueMicrotask(mount);
}, [router]);
<MatchContext value={routeId}>You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit dfdeeac. Configure here.
| } as any); | ||
| if (trimPathRight(location.publicHref) !== trimPathRight(nextLocation.publicHref)) { | ||
| router.commitLocation({ ...nextLocation, replace: true, ignoreBlocker: true }); | ||
| return; |
There was a problem hiding this comment.
Mount work races with early clicks
Medium Severity
A click that selective-hydrates the deferred root Suspense arm runs MatchesInner's layout effect in that same turn, which invokes the waiting mount work before the event reaches its handler. mount can still commitLocation to canonicalize the URL, starting a navigation that races with the original click and can drop it or overwrite it.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit dfdeeac. Configure here.



Summary
hydrateRootnow hydrates server-resolved Suspense boundaries after the shell, as React 19 does. This implements policy A, which @trueadm chose on #1864 (decision): always defer them.yieldForHostBudget+postHostTask; no new task poster).Moves toward the dehydrated-boundary model in #2028.
Why
A large root hydrated in one long task. On the
frame-boundariesbench, which is the app frame with its 11 sections in Suspense boundaries, that task took about 88 ms at 4× CPU. React hydrates the shell without yielding and leaves each server-rendered boundary dehydrated at OffscreenLane. Its time-sliced work loop then hydrates them later, so the unit of yielding is the author's Suspense boundary.The 2026-10-13 prototype deferred boundaries only once a budget was spent. It surfaced four defects, which this PR fixes:
Changes
packages/octane/src/runtime.ts:renderInitialSuspenseHydrationleaves an arm dehydrated when any hydration pass reaches it. The arm is queued once that pass commits, through a render cleanup, so an attempt that is rolled back never queues it.<Hydrate>island's own content boundary is excluded (isHydrateContent). Its activation still hydrates its content as a unit by its own strategy, so theload()andinteraction()contracts are unchanged.hydrateDeferredArmhydrates the arm through the existing initial-arm path. It runs in the root's render transaction, in its parent's render context (CURRENT_BLOCK/CURRENT_SCOPE, plus the explicit signal owner of the pass that deferred it), withoutscheduleRender(state.parentBlock).DeferredArmsdriver listens in the capture phase for discrete interaction events on each waiting arm's root node: the document, a shadow root, or the top of a detached tree. An event aimed at a waiting arm hydrates it, and any waiting arm around it, before the root's own listeners run.inputinto a native signal binding.dispatchDelegatedis unchanged, so the hot dispatch path pays nothing. The listeners are removed when the queue empties.tryBlock:SelectiveHydrationException.<Hydrate>'s epoch-and-compare check, now factored ashydrateContextsChanged. A stale arm falls back silently on any difference and reports nothing.act(). Syncact()hydrates every waiting arm. Asyncact()keeps draining while any are queued.@octanejs/tanstack-router: the transitioner's mount layout effect assumed "the match tree has already committed". The router's root<Suspense>boundary now hydrates after the shell, so that no longer held./to/?page=1and started a navigation.main.The fix: when the location is already resolved, the mount work now waits for
MatchesInner's first commit. React would hit the same ordering, since shell layout effects run before boundaries hydrate.scripts/check-staged-dom.mjslists the new native operations as reviewed exemptions:getRootNode, the listener add/remove, andcompareDocumentPosition.Docs:
differences-from-react.md§Scheduler, §Streaming and §Hydration, and the website differences page.Bench (
benchmarks/app-frame-hydration):frame-boundariesscenario;longest_task_cold/busy_coldops, traced fromhydrateRootuntil every boundary's layout effects and the remaining passive effects have run;hydrateRootreturns must still collapse it;Tests:
New
hydration/deferred-suspense-arms.test.tscovers:act().Four of its cases fail on
main. The others pin the behaviors deferral could have broken.15 existing test files asserted a boundary's effects or handlers right after
hydrateRoot+flushSync. They now wait withact(), as React tests do.Validation
main:tests/hydration/**plus every edited test file: 175 files and 8,313 tests passed.octaneproject: everything passed except two compiler tests outside this change, which I did not rerun onmain:compiler-vite-options(a 6 s compile limit missed under machine load) andvolar(a StyleX type-check). Binding hydration tests (i18next, tanstack-router, testing-library, markdown, astro, app-core) passed: 7 files, 47 tests.pnpm typecheck:filesonruntime.ts, the new test and fixture, and the bench sources. Test files still show the type errorsmainhas, 458 forstreaming-ssr.test.ts, which this diff does not change.pnpm format:files,pnpm sync(no generated changes).node --test scripts/check-staged-dom.test.mjs: 9/9.examples/hacker-newse2e: 26 passed (jsx + tsrx), including the SSR adoption spec under 6× CPU throttling.octane-prodontests/hydration/**plus every edited file: 175 files, 8,665 tests.octane-signals,octane-signals-strongandoctane-signals-prodonsignals-hydrationandsignals-parallel-use: 24/24 each. These two files now hydrate insideact(), so that a Suspense arm's readers and loads are reached.pnpm test,pnpm typecheckandpnpm format:checkwere left to CI.node benchmarks/app-frame-hydration/run.mjs 15 --base=<main checkout> --scenarios=frame,frame-boundaries. Chromium headless, 4× CPU, 15 interleaved pairs, re-run after mergingmainat5594cb06ea(which includes perf(hydration): measure shell overhead, retain server ranges and opt in native seeds #2033):frameframeframe-boundariesframe-boundariesframe-boundariesframe: production calls (221,900) and heap are identical.frame-boundaries: production calls are 229,894 → 230,269 (+0.16%), Blocks and renders are 1,674 in both, heap is +138 KB, and the median task count is 14.hydrateRootcall, so such a sample reruns.perf-review:node scripts/perf-review-scan.mjsfound 0 candidates. By hand:tryBlockgains two reads ofinitial.deferredon the branch whereinitial !== undefined, which only hydrated arms reach. Dispatch is unchanged. Everything else runs once per arm or per batch.postHostTaskandyieldForHostBudget. There is no microtask hop, and no render per value.renderInitialSuspenseHydration, whichHydrationCapability's constructor installs.act()reads the driver by truthiness.concise-code:dispatchDelegated/dispatchDelegatedCapture: they miss event types no handler has delegated, so a native signal control lost its edit, and they cost a check on every dispatch.Risk / follow-ups
Busy total is +3.9%, not flat. A CPU profile over 21 pairs attributes the remaining ~4 ms of JS to:
postHostTask+ the budget sentinel, ~1.3 ms at 4×;Chromium's per-task overhead covers the rest of the traced gap. The prototype was +26%.
Timing change for apps and tests. A boundary's effects and handlers now arrive after the shell, and the changeset is
minor. Code that asserts on them right afterhydrateRootneedsawait act().@octanejs/testing-library'srender({ hydrate: true })settles withflushSync, so boundaries stay pending untilact/waitFor. RTL wraps the hydrate inact(), which drains them. Making the binding match RTL is a candidate follow-up.Context changes differ from React. A context change before a boundary's turn hydrates it with the new value, falling back silently on any difference. React hydrates it with the old value first.
Hoisted head entries can be left behind. A root unmounted before a boundary's turn leaves the
<head>entries the boundary hoisted, as it already did for a boundary whose hydration suspended.Capture handlers on detached roots. When a detached root's container is itself the root node, an
onXxxCapturehandler inside a waiting arm misses the first event. Bubble handlers are unaffected.Bindings that mutate external state from shell effects. A binding that does this, before a boundary it renders has hydrated, now hydrates that boundary from the new state. The tanstack-router transitioner was the one CI exposed. Other bindings with mount-time navigation or store writes may need the same "wait for the match tree" treatment.
Second resume route. An arm whose own hydration suspends still retries through
scheduleRender(state.parentBlock), as onmain. Routing that retry through the same queue would leave one resume route for dehydrated boundaries, which fits Hydration: collapse the hydration engine back into the mount path (Ripple/Svelte-style cursor), 23 kB → ~5 kB gzip #2028's single-path goal.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.Note
High Risk
Changes core client hydration scheduling and effect ordering for every Suspense boundary; apps and bindings that assumed synchronous post-
hydrateRootbehavior (e.g. router mount) need the new timing contract.Overview
hydrateRootnow matches React 19: the shell adopts and commits in one task; each server-resolved Suspense boundary keeps its HTML and hydrates in later host tasks (ordered outer→inner, at least one per task, more while a ~5 ms host budget lasts). Shell effects run before boundary effects.The runtime adds a
DeferredArmsqueue with capture-phase listeners so discrete interaction (click, key, focus, IME/input) can hydrate a waiting boundary—and enclosing boundaries—before handlers run. Parent updates with new inputs hydrate a waiting arm from its server props first, then render over the adopted DOM; unchanged parent renders leave it waiting.act()flushes all pending boundaries. Context changes before a boundary’s turn mark it stale and can fall back silently (documented divergence from React).@octanejs/tanstack-routerdefers transitioner mount work (URL canonicalization / initial load) untilMatchesInner’s first commit, so SSR no longer navigates while the root Suspense boundary is still dehydrated.Benchmarks add a
frame-boundariesscenario plus trace-based longest-task/busy metrics and an early-click correctness gate. Docs and many hydration tests switch toawait act()afterhydrateRootwhere boundary effects matter.Reviewed by Cursor Bugbot for commit dfdeeac. Bugbot is set up for automated code reviews on this repo. Configure here.