Skip to content

fix(hydration): keep a hookless component's signal level below its arms and rows - #1616

Merged
trueadm merged 8 commits into
mainfrom
claude/wizardly-tereshkova-5593c0
Oct 3, 2026
Merged

trueadm merged 8 commits into
mainfrom
claude/wizardly-tereshkova-5593c0

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A component rendered inside an @if or @for arm of a hookless (lite) .tsrx component got a different signal instance key in the browser than on the server. Hydration therefore started fresh cells instead of resuming the server's. This was found while working on #1601; it predates that PR and is independent of it.

For a value under a lite component's @if arm, before this change:

  • server: ["","root"]["c:<Card>",[],""]["c:<Leaf>",[],""]
  • client: ["","root"]["c:<Leaf>",["u:"],""]

The client dropped the lite component's level and added a bogus u: item token.

Cause. Arms, rows and value slots created in a lite body hang off the lite scope's LiteBlockImpl DOM stand-in, not the scope. The stand-in was never stamped, so the key walk skipped the component's level. It also has no forSlot field, so forSlot !== null treated it as a list row and pushed u:. Nested lite components lost every lite level the same way.

Second bug, same cause. signalRetrySlot used the same strict check. On a lite target, undefined === undefined matched slots belonging to an earlier lite sibling, so later lite siblings collided on one retry path. When hydration retried a suspended @try body, the second sibling took the third's owner. This only happens in dev builds, where the earlier sibling is also compiled lite.

Fix. The fix is on the stamping side, in packages/octane/src/runtime.ts:

  • stampSignalInstance now stamps the stand-in with its lite scope's recipe, so the walks resolve the component's level there. It now writes only the parent and site, because the scope is always freshly created at that point.
  • structuralSignalInstanceKey, signalRetrySlot and scopeSignalOwner read forSlot loosely, so a stand-in never counts as a list row.
  • I did not give LiteBlockImpl a forSlot = null field. That cost +18 B raw and +42 B brotli in every bundle. It would also have changed childSlot's passthrough list-anchor walk, which stops at a stand-in's end marker.
  • invalidateRender already skips stand-ins.

Bundle size. root-chained-jsx against main 6ea582e:

raw gzip brotli
main 86002 28544 25337
this PR 85981 28545 25337

main already sat exactly on the gzip budget (28544). Every equivalent spelling of the reader checks was +1 to +8 B gzip or over the brotli budget; I measured 24 of them. This PR therefore raises only the root-chained-jsx gzip budget by one 32 B step, to 28576, as #1548, #1549 and #1582 did. All five gated scenarios are 21 B smaller raw. The other four stay within budget, between −2 and 0 B gzip and between −6 and +63 B brotli.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check passed on the 4 changed files.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files passed on the runtime and the test file.
  • pnpm test: not run locally. CI covers it.
  • targeted tests: vitest run --project octane packages/octane/tests/hydration/signal-instance-identity.test.ts, 167/167 passing.
    • New describe, hookless component signal instance identity, 14 cases in dev and prod.
    • Owner keys: values under @if (component and host roots), a value under @for, a component under @if, and nested hookless arms. Each case asserts every browser owner key equals the server's key for the same component, plus DOM adoption.
    • Retry: hookless siblings through a browser-only use() suspension and hydration retry, after an earlier hookless sibling that contains a nested hookless child or an @if arm.
    • On main, 11 of the 14 cases fail. The 3 that pass are prod builds where the compiler emits a full Block.
    • I also broke each part of the fix on its own. Without the stand-in stamp, or with the strict walk check, the owner-key cases fail. With the strict signalRetrySlot check, the dev retry cases fail.
  • node benchmarks/bundle-size/run-minimal.mjs --budgets root-static-local root-chained-jsx hooks-state prop-attributes context passes.

Risk / follow-ups

  • Untested edge. The scopeSignalOwner reader change only matters for a lite scope mounted before signals were enabled. In that case it now behaves like an unstamped full component Block, and no test covers it.
  • Budget pressure. root-chained-jsx remains close to its budget on all three metrics, so the next runtime change on this path will likely need another step.

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. Autofix is disabled.


Note

Medium Risk
Touches core hydration signal-identity and retry-slot resolution in the client runtime; behavior is narrow but mistakes would corrupt resumed signal state across SSR/hydration.

Overview
Fixes server/client signal instance key mismatches for content rendered inside @if / @for arms of hookless (lite) .tsrx components, so hydration resumes the server’s signal cells instead of creating new ones.

Runtime (runtime.ts): stampSignalInstance now copies the lite scope’s parent/site onto the LiteBlockImpl DOM stand-in as well as the scope, because structural children key off the stand-in. forSlot is checked loosely in signalRetrySlot, structural key walks, and scopeSignalOwner so unstamped stand-ins are not treated as list rows (no bogus u: token) and lite siblings don’t collide on hydration retry paths after a suspended @try.

Tests: New hookless component signal instance identity coverage (dev + prod) for several arm/row shapes and for sibling owners after browser-only suspension + retry.

Release / CI: Octane patch changeset; root-chained-jsx minimal bundle gzip budget +32 B (28544 → 28576).

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

…ms and rows

A hookless (lite) component's arms, rows and value children hang off its
LiteBlockImpl DOM stand-in. The stand-in was never stamped and has no
forSlot field, so the signal instance key walk skipped the component's
level and pushed a stray 'u:' item token. The browser keyed those owners
differently from the server, and the retry-path walk let later hookless
siblings collide on one path, so they swapped owners on a hydration retry.

Stamp the stand-in with its lite scope's recipe and read forSlot loosely
in the signal walks, so a stand-in never counts as a list row. The
root-chained-jsx bundle is 21 B smaller raw and 1 B larger gzip; main sat
exactly on its gzip budget, so that budget moves up one 32 B step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 2, 2026
@github-actions
github-actions Bot marked this pull request as draft October 2, 2026 22:22
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 22:23
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 10 value(s) increased
  • 🔴 bundle-reachability: 19 value(s) increased

Compares 27c2a12da with 65755ec17 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 3.46 3.84 +11.0% ±10% ⚪ within noise
octane-tsrx replace 7.16 7.94 +10.9% ±12% ⚪ within noise
octane-tsrx add 3.52 3.53 +0.3% ±9% ⚪ within noise
octane-tsrx update 0.36 0.46 +27.8% ±35% ⚪ within noise
octane-tsrx select 0.18 0.19 +5.6% ±82% ⚪ within noise
octane-tsrx swap 0.32 0.42 +31.3% ±37% ⚪ within noise
octane-tsrx remove 0.35 0.42 +20.0% ±53% ⚪ within noise
octane-tsrx runlots 30.77 32.64 +6.1% ±14% ⚪ within noise
octane-tsrx select_lots 0.24 0.27 +12.5% ±55% ⚪ within noise
octane-tsrx clear 46.25 44.62 −3.5% ±7% ⚪ within noise
octane-jsx run 3.73 3.99 +7.0% ±9% ⚪ within noise
octane-jsx replace 7.44 7.36 −1.1% ±12% ⚪ within noise
octane-jsx add 3.30 3.24 −1.8% ±8% ⚪ within noise
octane-jsx update 0.66 0.55 −16.7% ±36% ⚪ within noise
octane-jsx select 0.39 0.44 +12.8% ±39% ⚪ within noise
octane-jsx swap 0.73 0.71 −2.7% ±38% ⚪ within noise
octane-jsx remove 0.73 0.62 −15.1% ±35% ⚪ within noise
octane-jsx runlots 29.96 30.60 +2.1% ±9% ⚪ within noise
octane-jsx select_lots 3.01 2.78 −7.6% ±42% ⚪ within noise
octane-jsx clear 47.31 46.11 −2.5% ±5% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 126,850 126,829 −21 (−0.0%) 🟢
octane-tsrx js_brotli 37,005 37,038 +33 (+0.1%) 🔴
octane-tsrx app_gzip 2,563 2,562 −1 (−0.0%) 🟢
octane-tsrx app_brotli 2,226 2,222 −4 (−0.2%) 🟢
octane-tsrx fw_raw 119,338 119,317 −21 (−0.0%) 🟢
octane-tsrx fw_gzip 39,415 39,416 +1 (+0.0%) 🔴
octane-tsrx fw_brotli 34,779 34,816 +37 (+0.1%) 🔴
octane-tsrx todo_js_raw 142,237 142,216 −21 (−0.0%) 🟢
octane-tsrx todo_js_gzip 46,993 46,992 −1 (−0.0%) 🟢
octane-tsrx todo_js_brotli 41,173 41,206 +33 (+0.1%) 🔴
octane-tsrx todo_app_gzip 2,478 2,477 −1 (−0.0%) 🟢
octane-tsrx todo_app_brotli 2,121 2,117 −4 (−0.2%) 🟢
octane-tsrx todo_fw_raw 137,127 137,106 −21 (−0.0%) 🟢
octane-tsrx todo_fw_brotli 39,052 39,089 +37 (+0.1%) 🔴
octane-tsrx chat_js_raw 141,446 141,425 −21 (−0.0%) 🟢
octane-tsrx chat_js_brotli 41,277 41,242 −35 (−0.1%) 🟢
octane-tsrx chat_app_gzip 2,978 2,979 +1 (+0.0%) 🔴
octane-tsrx chat_app_brotli 2,639 2,636 −3 (−0.1%) 🟢
octane-tsrx chat_fw_raw 134,793 134,772 −21 (−0.0%) 🟢
octane-tsrx chat_fw_gzip 43,959 43,958 −1 (−0.0%) 🟢
octane-tsrx chat_fw_brotli 38,638 38,606 −32 (−0.1%) 🟢
octane-tsrx weather_js_raw 178,412 178,391 −21 (−0.0%) 🟢
octane-tsrx weather_js_gzip 58,345 58,346 +1 (+0.0%) 🔴
octane-tsrx weather_js_brotli 50,794 50,755 −39 (−0.1%) 🟢
octane-tsrx weather_app_gzip 9,044 9,045 +1 (+0.0%) 🔴
octane-tsrx weather_app_brotli 7,580 7,559 −21 (−0.3%) 🟢
octane-tsrx weather_fw_raw 151,677 151,656 −21 (−0.0%) 🟢
octane-tsrx weather_fw_brotli 43,214 43,196 −18 (−0.0%) 🟢
octane-jsx js_raw 226,725 226,704 −21 (−0.0%) 🟢
octane-jsx js_gzip 72,362 72,361 −1 (−0.0%) 🟢
octane-jsx js_brotli 62,642 62,740 +98 (+0.2%) 🔴
octane-jsx app_gzip 2,936 2,935 −1 (−0.0%) 🟢
octane-jsx app_brotli 2,510 2,494 −16 (−0.6%) 🟢
octane-jsx fw_raw 218,266 218,245 −21 (−0.0%) 🟢
octane-jsx fw_brotli 60,132 60,246 +114 (+0.2%) 🔴

10 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 116,542 116,521 −21 (−0.0%) 🟢
cli-spa-starter gzip 39,358 39,359 +1 (+0.0%) 🔴
cli-spa-starter brotli 34,372 34,391 +19 (+0.1%) 🔴
root-static-specialized raw 77,087 77,066 −21 (−0.0%) 🟢
root-static-specialized gzip 25,584 25,582 −2 (−0.0%) 🟢
root-static-specialized brotli 22,770 22,826 +56 (+0.2%) 🔴
root-chained-jsx raw 86,002 85,981 −21 (−0.0%) 🟢
root-chained-jsx gzip 28,544 28,545 +1 (+0.0%) 🔴
root-static raw 203,053 203,032 −21 (−0.0%) 🟢
root-static gzip 64,558 64,555 −3 (−0.0%) 🟢
root-static brotli 55,909 56,005 +96 (+0.2%) 🔴
root-static-local raw 77,090 77,069 −21 (−0.0%) 🟢
root-static-local gzip 25,571 25,569 −2 (−0.0%) 🟢
root-static-local brotli 22,779 22,785 +6 (+0.0%) 🔴
hooks-state raw 89,251 89,230 −21 (−0.0%) 🟢
hooks-state gzip 29,643 29,641 −2 (−0.0%) 🟢
hooks-state brotli 26,350 26,413 +63 (+0.2%) 🔴
prop-attributes raw 97,454 97,433 −21 (−0.0%) 🟢
prop-attributes brotli 28,719 28,730 +11 (+0.0%) 🔴
context raw 110,859 110,838 −21 (−0.0%) 🟢
context gzip 36,710 36,709 −1 (−0.0%) 🟢
context brotli 32,483 32,487 +4 (+0.0%) 🔴
hydrate-root raw 171,116 171,095 −21 (−0.0%) 🟢
hydrate-root gzip 54,299 54,302 +3 (+0.0%) 🔴
hydrate-root brotli 47,409 47,389 −20 (−0.0%) 🟢
deferred-hydration raw 234,555 234,534 −21 (−0.0%) 🟢
deferred-hydration gzip 74,202 74,201 −1 (−0.0%) 🟢
deferred-hydration brotli 64,069 64,020 −49 (−0.1%) 🟢
suspense-transition raw 166,174 166,153 −21 (−0.0%) 🟢
suspense-transition gzip 53,406 53,405 −1 (−0.0%) 🟢
suspense-transition brotli 46,776 46,732 −44 (−0.1%) 🟢
component-owned-effects raw 81,699 81,678 −21 (−0.0%) 🟢
component-owned-effects gzip 26,938 26,939 +1 (+0.0%) 🔴
component-owned-effects brotli 23,984 23,990 +6 (+0.0%) 🔴
binding-hooks raw 87,764 87,743 −21 (−0.0%) 🟢
binding-hooks gzip 29,342 29,343 +1 (+0.0%) 🔴
binding-hooks brotli 26,174 26,141 −33 (−0.1%) 🟢
binding-base-ui-vite raw 213,244 213,223 −21 (−0.0%) 🟢
binding-base-ui-vite gzip 68,126 68,124 −2 (−0.0%) 🟢
binding-base-ui-vite brotli 59,074 59,047 −27 (−0.0%) 🟢
binding-base-ui-esbuild raw 211,201 211,180 −21 (−0.0%) 🟢
binding-base-ui-esbuild gzip 68,109 68,108 −1 (−0.0%) 🟢
binding-base-ui-esbuild brotli 59,025 59,048 +23 (+0.0%) 🔴
binding-radix-vite raw 215,174 215,153 −21 (−0.0%) 🟢
binding-radix-vite gzip 68,698 68,696 −2 (−0.0%) 🟢
binding-radix-vite brotli 59,547 59,513 −34 (−0.1%) 🟢
binding-radix-esbuild raw 213,091 213,070 −21 (−0.0%) 🟢
binding-radix-esbuild gzip 68,697 68,696 −1 (−0.0%) 🟢
binding-radix-esbuild brotli 59,585 59,640 +55 (+0.1%) 🔴
binding-mantine-hooks-vite raw 98,089 98,068 −21 (−0.0%) 🟢
binding-mantine-hooks-vite gzip 32,613 32,612 −1 (−0.0%) 🟢
binding-mantine-hooks-vite brotli 28,975 28,939 −36 (−0.1%) 🟢
binding-mantine-hooks-esbuild raw 97,683 97,662 −21 (−0.0%) 🟢
binding-mantine-hooks-esbuild brotli 29,107 29,079 −28 (−0.1%) 🟢
binding-apollo-client-vite raw 358,299 358,278 −21 (−0.0%) 🟢
binding-apollo-client-vite gzip 112,252 112,251 −1 (−0.0%) 🟢
binding-apollo-client-vite brotli 97,943 97,991 +48 (+0.0%) 🔴
binding-apollo-client-esbuild raw 361,248 361,227 −21 (−0.0%) 🟢
binding-apollo-client-esbuild gzip 114,463 114,461 −2 (−0.0%) 🟢
binding-apollo-client-esbuild brotli 99,622 99,685 +63 (+0.1%) 🔴
binding-usehooks-ts-vite raw 98,722 98,701 −21 (−0.0%) 🟢
binding-usehooks-ts-vite gzip 32,772 32,770 −2 (−0.0%) 🟢
binding-usehooks-ts-vite brotli 29,120 29,133 +13 (+0.0%) 🔴
binding-usehooks-ts-esbuild raw 98,305 98,284 −21 (−0.0%) 🟢
binding-usehooks-ts-esbuild brotli 29,268 29,293 +25 (+0.1%) 🔴

40 other measured values are unchanged.

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

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant