Skip to content

perf(octane): hydrate server-resolved Suspense boundaries after the shell - #2040

Closed
trueadm wants to merge 5 commits into
mainfrom
perf/hydration-defer-arms
Closed

trueadm wants to merge 5 commits into
mainfrom
perf/hydration-defer-arms

Conversation

@trueadm

@trueadm trueadm commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Reference implementation for #2028 step 5. It won't merge on today's engine. Per @trueadm's 2026-10-13 decision, hydrating Suspense boundaries after the shell folds into #2028 step 5, on #2029's commit model. This branch documents the policy-A behavior, its tests, the bench result and the lessons; see #2028 and #2029. The frame-boundaries bench lands separately in #2041.

Summary

hydrateRoot now 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.

  • Shell: the shell is adopted and committed in one task. Every Suspense boundary the server resolved keeps its server DOM.
  • Boundary turns: waiting boundaries hydrate in later host tasks, in the order hydration reached them, so an outer boundary comes before the boundaries inside it. Each task hydrates at least one, and more while the shared ~5 ms host budget lasts (yieldForHostBudget + postHostTask; no new task poster).
  • Effect order: the shell's effects run before any boundary's.

Moves toward the dehydrated-boundary model in #2028.

Why

A large root hydrated in one long task. On the frame-boundaries bench, 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:

  • resuming through a parent replay added 1,212 renders (+26% busy time);
  • early clicks were lost;
  • a parent re-render discarded 654 server elements;
  • context changes went undetected.

Changes

packages/octane/src/runtime.ts:

  • Deferral. renderInitialSuspenseHydration leaves 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.
    • A <Hydrate> island's own content boundary is excluded (isHydrateContent). Its activation still hydrates its content as a unit by its own strategy, so the load() and interaction() contracts are unchanged.
  • Direct resume. hydrateDeferredArm hydrates 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), without scheduleRender(state.parentBlock).
    • Each batch of arms commits together.
    • Bench renders are now 1,674 for 1,674 Blocks. The prototype rendered 2,886.
  • Selective hydration. While arms wait, the DeferredArms driver 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.
    • This covers event types no handler has delegated yet, such as input into a native signal binding.
    • dispatchDelegated is unchanged, so the hot dispatch path pays nothing. The listeners are removed when the queue empties.
  • Updates. In tryBlock:
    • New inputs that reach a waiting arm hydrate it first, from the inputs its server HTML was rendered with, and the update then renders over the adopted DOM. This mirrors React's SelectiveHydrationException.
    • A parent render that brings no new inputs leaves the arm waiting.
    • A context change before the arm's turn makes it stale. This reuses <Hydrate>'s epoch-and-compare check, now factored as hydrateContextsChanged. A stale arm falls back silently on any difference and reports nothing.
  • act(). Sync act() hydrates every waiting arm. Async act() 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.

  • On mount it canonicalized / to /?page=1 and started a navigation.
  • That navigation hydrated the boundary from matches the server never rendered, and the boundary fell back to a client render.
  • The hacker-news example's SSR e2e caught this in CI as a replaced server row. It reproduced locally at 6× CPU and passed on 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.mjs lists the new native operations as reviewed exemptions: getRootNode, the listener add/remove, and compareDocumentPosition.

Docs: differences-from-react.md §Scheduler, §Streaming and §Hydration, and the website differences page.

Bench (benchmarks/app-frame-hydration):

  • adds the frame-boundaries scenario;
  • adds trace-based longest_task_cold / busy_cold ops, traced from hydrateRoot until every boundary's layout effects and the remaining passive effects have run;
  • adds a Chromium gate: a click on a sidebar section made right after hydrateRoot returns must still collapse it;
  • counts work through settle.

Tests:

  • New hydration/deferred-suspense-arms.test.ts covers:

    • shell-first ordering and one arm per task once the budget is spent;
    • an early click, including one on a nested arm;
    • an event type nobody delegates;
    • an IME session typed into an arm before its turn;
    • parent renders with and without new inputs, and a provider change before the turn;
    • unmount while pending;
    • a mismatch that reports once;
    • sync 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 with act(), as React tests do.

Validation

  • Targeted tests, after merging main: tests/hydration/** plus every edited test file: 175 files and 8,313 tests passed.
  • Before the merge, the full octane project: everything passed except two compiler tests outside this change, which I did not rerun on main: compiler-vite-options (a 6 s compile limit missed under machine load) and volar (a StyleX type-check). Binding hydration tests (i18next, tanstack-router, testing-library, markdown, astro, app-core) passed: 7 files, 47 tests.
  • pnpm typecheck:files on runtime.ts, the new test and fixture, and the bench sources. Test files still show the type errors main has, 458 for streaming-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-news e2e: 26 passed (jsx + tsrx), including the SSR adoption spec under 6× CPU throttling.
  • tanstack-router tests: 23 files, 114 tests.
  • octane-prod on tests/hydration/** plus every edited file: 175 files, 8,665 tests.
  • octane-signals, octane-signals-strong and octane-signals-prod on signals-hydration and signals-parallel-use: 24/24 each. These two files now hydrate inside act(), so that a Suspense arm's readers and loads are reached.
  • Full pnpm test, pnpm typecheck and pnpm format:check were left to CI.
  • Bench: 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 merging main at 5594cb06ea (which includes perf(hydration): measure shell overhead, retain server ranges and opt in native seeds #2033):
scenario metric main this PR head/base [95% CI]
frame hydrateRoot task (cold) 62.0 ms 62.2 ms 1.002 [0.979–1.011]
frame longest task / busy 64.1 ms 62.9 ms 0.995 [0.980–1.008]
frame-boundaries hydrateRoot task (cold) 70.1 ms 17.3 ms 0.246 [0.242–0.253]
frame-boundaries longest task 71.9 ms 19.0 ms 0.264 [0.261–0.267]
frame-boundaries busy total 71.9 ms 74.2 ms 1.039 [1.009–1.050]
  • frame: 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.
  • The early-click gate passed for both candidates in both scenarios.
  • Before that merge, the same comparison measured a longest task of 87.7 → 20.5 ms and busy 1.038 [1.024–1.046].
  • The trace counts the outermost main-thread events and folds each microtask checkpoint into its task. Chromium occasionally drops a long task from a trace, which shows as a longest task shorter than the hydrateRoot call, so such a sample reruns.
  • perf-review: node scripts/perf-review-scan.mjs found 0 candidates. By hand:
    • Hot paths: tryBlock gains two reads of initial.deferred on the branch where initial !== undefined, which only hydrated arms reach. Dispatch is unchanged. Everything else runs once per arm or per batch.
    • Scheduling: it reuses postHostTask and yieldForHostBudget. There is no microtask hop, and no render per value.
    • Reachability: the queue, task and listeners are reached only from renderInitialSuspenseHydration, which HydrationCapability's constructor installs. act() reads the driver by truthiness.
    • needs-evidence: the busy-time residual below.
  • concise-code:
    • Size: src +221 −10, all in the runtime.
    • New files: the test, its fixture and the changeset. No new exports.
    • Alternatives rejected:
      • Budget-only deferral (the prototype): timing-dependent effect order and +26% busy time.
      • Hooks inside 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.
      • Stale-only update policy: a parent update that changes an arm's output would discard its server DOM.
      • A parent-replay resume: +1,212 renders.
    • Bytes: see the CI bench report.

Risk / follow-ups

  • Busy total is +3.9%, not flat. A CPU profile over 21 pairs attributes the remaining ~4 ms of JS to:

    • task posting: postHostTask + the budget sentinel, ~1.3 ms at 4×;
    • one root transaction and commit per batch, ~0.9 ms;
    • listener install, ~0.3 ms;
    • the root's range coalescing rescanning still-dehydrated arm ranges, ~1 ms.

    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 after hydrateRoot needs await act(). @octanejs/testing-library's render({ hydrate: true }) settles with flushSync, so boundaries stay pending until act/waitFor. RTL wraps the hydrate in act(), 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 onXxxCapture handler 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 on main. 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

  • 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

High Risk
Changes core client hydration scheduling and effect ordering for every Suspense boundary; apps and bindings that assumed synchronous post-hydrateRoot behavior (e.g. router mount) need the new timing contract.

Overview
hydrateRoot now 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 DeferredArms queue 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-router defers transitioner mount work (URL canonicalization / initial load) until MatchesInner’s first commit, so SSR no longer navigates while the root Suspense boundary is still dehydrated.

Benchmarks add a frame-boundaries scenario plus trace-based longest-task/busy metrics and an early-click correctness gate. Docs and many hydration tests switch to await act() after hydrateRoot where boundary effects matter.

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

trueadm and others added 2 commits October 13, 2026 12:19
…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]>
@trueadm
trueadm marked this pull request as ready for review October 13, 2026 11:21
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Oct 13, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 13, 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 Updated (UTC)
⚠️ Deployment skipped
View logs
octane-website dfdeeac Oct 13 2026, 11:51 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 13, 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 Updated (UTC)
⚠️ Deployment skipped
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]>

@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 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.

Create PR

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.

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

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 26 value(s) increased
  • 🔴 bundle-reachability: 22 value(s) increased

Compares 5594cb06e, the merge commit's first parent with b2d64eb4a 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.758 2.675 ±0.0% −0.0% … ±0.0% ⚪ within noise
octane-tsrx replace 6.092 6.133 −1.4% −5.2% … +6.8% ⚪ within noise
octane-tsrx add 2.525 2.517 +0.0% −5.9% … +4.3% ⚪ within noise
octane-tsrx update 0.135 0.134 −0.2% −1.1% … +1.9% ⚪ within noise
octane-tsrx select 0.006 0.006 +2.1% +0.5% … +3.4% ⚪ within noise
octane-tsrx swap 0.016 0.016 +3.4% +1.5% … +7.4% ⚪ within noise
octane-tsrx remove 0.013 0.013 +0.9% −1.9% … +5.3% ⚪ within noise
octane-tsrx runlots 28.492 28.317 +1.1% −1.1% … +4.7% ⚪ within noise
octane-tsrx select_lots 0.007 0.007 +0.5% −0.0% … +1.6% ⚪ within noise
octane-tsrx clear 55.742 56.208 −2.1% −5.7% … +5.4% ⚪ within noise
octane-jsx run 4.042 3.975 +2.5% −3.7% … +5.8% ⚪ within noise
octane-jsx replace 7.242 7.042 ±0.0% −2.1% … +3.3% ⚪ within noise
octane-jsx add 3.167 3.067 ±0.0% −3.2% … +3.3% ⚪ within noise
octane-jsx update 0.259 0.267 +0.7% −1.6% … +1.7% ⚪ within noise
octane-jsx select 0.130 0.131 +1.1% −0.5% … +3.0% ⚪ within noise
octane-jsx swap 0.177 0.177 +1.7% +0.5% … +4.7% ⚪ within noise
octane-jsx remove 0.171 0.189 +0.9% −0.3% … +2.1% ⚪ within noise
octane-jsx runlots 29.042 29.175 +1.5% −1.0% … +5.3% ⚪ within noise
octane-jsx select_lots 1.540 1.556 +1.2% −0.0% … +3.3% ⚪ within noise
octane-jsx clear 47.775 47.000 +0.0% −2.7% … +1.6% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx wayfinder_js_raw 459,987 462,488 +2,501 (+0.5%) 🔴
octane-tsrx wayfinder_js_gzip 149,391 150,376 +985 (+0.7%) 🔴
octane-tsrx wayfinder_js_brotli 129,474 130,267 +793 (+0.6%) 🔴
octane-tsrx pagecraft_oxc_js_raw 540,857 541,029 +172 (+0.0%) 🔴
octane-tsrx pagecraft_oxc_js_gzip 169,365 169,445 +80 (+0.0%) 🔴
octane-tsrx pagecraft_oxc_js_brotli 143,132 143,129 −3 (−0.0%) 🟢
octane-tsrx pagecraft_esbuild_js_raw 591,071 591,160 +89 (+0.0%) 🔴
octane-tsrx pagecraft_esbuild_js_gzip 188,776 188,820 +44 (+0.0%) 🔴
octane-tsrx pagecraft_esbuild_js_brotli 159,602 159,622 +20 (+0.0%) 🔴
octane-tsrx full_fw_raw 568,834 570,793 +1,959 (+0.3%) 🔴
octane-tsrx full_fw_gzip 172,158 172,883 +725 (+0.4%) 🔴
octane-tsrx full_fw_brotli 145,017 145,569 +552 (+0.4%) 🔴
octane-jsx shell_js_raw 392,280 395,053 +2,773 (+0.7%) 🔴
octane-jsx shell_js_gzip 123,035 124,015 +980 (+0.8%) 🔴
octane-jsx shell_js_brotli 105,105 105,822 +717 (+0.7%) 🔴
octane-jsx shell_app_gzip 770 767 −3 (−0.4%) 🟢
octane-jsx shell_app_brotli 668 672 +4 (+0.6%) 🔴
octane-jsx shell_fw_raw 391,187 393,960 +2,773 (+0.7%) 🔴
octane-jsx shell_fw_gzip 122,265 123,248 +983 (+0.8%) 🔴
octane-jsx shell_fw_brotli 104,437 105,150 +713 (+0.7%) 🔴
octane-jsx shell_client_js_raw 326,214 326,383 +169 (+0.1%) 🔴
octane-jsx shell_client_js_gzip 101,755 101,821 +66 (+0.1%) 🔴
octane-jsx shell_client_js_brotli 87,793 87,771 −22 (−0.0%) 🟢
octane-jsx shell_client_app_gzip 768 772 +4 (+0.5%) 🔴
octane-jsx shell_client_app_brotli 663 659 −4 (−0.6%) 🟢
octane-jsx shell_client_fw_raw 325,113 325,282 +169 (+0.1%) 🔴
octane-jsx shell_client_fw_gzip 100,987 101,049 +62 (+0.1%) 🔴
octane-jsx shell_client_fw_brotli 87,130 87,112 −18 (−0.0%) 🟢
octane-jsx full_fw_raw 568,834 570,793 +1,959 (+0.3%) 🔴
octane-jsx full_fw_gzip 172,158 172,883 +725 (+0.4%) 🔴
octane-jsx full_fw_brotli 145,017 145,569 +552 (+0.4%) 🔴

62 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 108,731 113,199 +4,468 (+4.1%) 🔴
hydrate-root gzip 35,766 37,320 +1,554 (+4.3%) 🔴
hydrate-root brotli 31,676 33,160 +1,484 (+4.7%) 🔴
deferred-hydration raw 191,201 194,843 +3,642 (+1.9%) 🔴
deferred-hydration gzip 61,094 62,386 +1,292 (+2.1%) 🔴
deferred-hydration brotli 53,249 54,446 +1,197 (+2.2%) 🔴
hydrate-frame raw 343,339 345,928 +2,589 (+0.8%) 🔴
hydrate-frame gzip 108,745 109,704 +959 (+0.9%) 🔴
hydrate-frame brotli 93,421 94,202 +781 (+0.8%) 🔴
suspense-transition raw 123,226 123,398 +172 (+0.1%) 🔴
suspense-transition gzip 39,540 39,611 +71 (+0.2%) 🔴
suspense-transition brotli 35,083 35,140 +57 (+0.2%) 🔴
binding-base-ui-esbuild raw 216,499 216,503 +4 (+0.0%) 🔴
binding-base-ui-esbuild gzip 70,468 70,470 +2 (+0.0%) 🔴
binding-base-ui-esbuild brotli 61,271 61,402 +131 (+0.2%) 🔴
binding-radix-esbuild raw 216,645 216,649 +4 (+0.0%) 🔴
binding-radix-esbuild gzip 70,378 70,381 +3 (+0.0%) 🔴
binding-radix-esbuild brotli 61,167 61,263 +96 (+0.2%) 🔴
binding-mantine-hooks-esbuild raw 75,517 75,521 +4 (+0.0%) 🔴
binding-mantine-hooks-esbuild brotli 23,540 23,502 −38 (−0.2%) 🟢
binding-apollo-client-esbuild raw 366,673 366,677 +4 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 102,153 102,152 −1 (−0.0%) 🟢
binding-usehooks-ts-esbuild raw 76,285 76,289 +4 (+0.0%) 🔴
binding-usehooks-ts-esbuild brotli 23,742 23,813 +71 (+0.3%) 🔴

87 other measured values are unchanged.

trueadm and others added 2 commits October 13, 2026 12:48
…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]>
@trueadm

trueadm commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

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

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 perf/hydration-defer-arms stays as a reference for the frame-boundaries bench, its trace metrics, the tests and the tanstack-router finding.

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.

@trueadm trueadm closed this Oct 13, 2026

@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: Mount work races with early clicks
    • Replaced synchronous mount?.() call in MatchesInner's layout effect with queueMicrotask(mount) so the deferred mount work runs after event dispatch ends, letting the click handler's navigation take precedence over URL canonicalization.

Create PR

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit dfdeeac. Configure here.

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 perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant