Repository navigation
fix(hydration): key signal owners below returned JSX by authored invocations only - #1601
Conversation
…cations only The client gave every compiled `_frag$N` fragment renderer and every host descriptor Block its own signal instance level, while the server renders the same returned JSX inline. A signal component below `.tsx` returned-JSX components therefore had a different owner instance key on each side, so hydration missed the server's cells and seeds. Compiler-synthesized renderers (client `_frag$N`, server `__sfragment` and `_sfrag$N`) now carry a renderer invocation site. Both runtimes give such renderers, host descriptors and dynamic tags that resolve to a host no key segment: keys below them continue from the scope they were stamped under, keeping pending list keys, and their Blocks borrow the enclosing owner. Server discovery jobs for a renderer frame retain the list keys it continued. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)
All 20 timed operations (19 within noise)
Application bundle size (bytes)
13 other measured values are unchanged. Public-import reachability bundles (bytes)
65 other measured values are unchanged. |
The first version taught structuralSignalInstanceKey and scopeSignalOwner to see through renderer Blocks. Both are reachable in every bundle, so even signal-free apps paid about 320 bytes and root-chained-jsx exceeded its committed budget. A renderer now takes its parent scope's stamp when it is created: it resolves to the parent's key, adds no segment, and stays unstamped below an unstamped parent so keys walk on through it. The key walk and owner lookup are unchanged from main, so the minimal bundles are byte-identical to it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wn cell Read the Leaf's signal in its body as well as in its returned JSX, and assert that a click in the returned JSX updates both. A renderer Block keeps its own owner (carrying the component's instance key), so this guards that handlers and reads inside it still resolve the component's cell. 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 1 potential issue.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue. You can view the agent here.
Reviewed by Cursor Bugbot for commit 259c79c. Configure here.
Each `.map` row that returns a keyed host element renders through its own host renderer inside the row. Assert that both rows keep separate, server-equal signal owners, so a renderer never hides its row's item key. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Bugbot Autofix prepared a fix for the issue found in the latest run.
Or push these changes by commenting: Preview (b948375229)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
@@ -913,6 +913,11 @@
scope.signalInstanceValue = renderer ? parent.signalInstanceValue : key.key;
scope.signalInstanceHasKey = renderer ? parent.signalInstanceHasKey : key.hasKey;
scope.signalInstanceResolved = renderer ? parent.signalInstanceResolved : undefined;
+ // A renderer's identity is its parent's: scopeSignalOwner must borrow the
+ // enclosing scope's owner rather than mint a duplicate with the same
+ // instanceKey. Pre-mark false so it enters the borrowed-identity path and
+ // deletion does not retire the parent's cells.
+ if (renderer) SCOPE_SIGNAL_OWNERS.set(scope, false);
}
function structuralSignalInstanceKey(
@@ -1017,6 +1022,25 @@
parent = parent.parent ?? parent.block.parentBlock;
}
}
+ // A renderer carries its enclosing scope's signal instance recipe
+ // (stampSignalInstanceKey, RENDERER_INVOCATION_SITE) and is pre-marked
+ // false. Borrow the enclosing scope's owner so the renderer does not mint
+ // a duplicate with the same instanceKey: the server keeps one owner per
+ // key, and retiring a duplicate on unmount would dispose the parent's cells.
+ if (
+ owner === false &&
+ (scope.signalInstanceParent !== null || scope.signalInstanceResolved !== undefined)
+ ) {
+ const enclosing: Scope | null = scope.parent ?? scope.block.parentBlock;
+ if (
+ enclosing !== null &&
+ !(enclosing instanceof LiteBlockImpl) &&
+ scope.signalInstanceParent === enclosing.signalInstanceParent &&
+ scope.signalInstanceSite === enclosing.signalInstanceSite
+ ) {
+ return scopeSignalOwner(enclosing);
+ }
+ }
const retired = owner === null;
if (!owner || owner.documentOwner !== documentOwner) {
const ids = scope.block.idState;You can send follow-ups to the cloud agent here. |
|
Not adopting the Bugbot Autofix branch (
🤖 Addressed by Claude Code |
…another request (#1618) A hydration frame rejected a resource seed whose request no longer matched the client's selection with a hard SignalFrameError ("The presented query definition does not match"), even under the native adoption resolver. The live binding already treats a seed for another request as no seed and starts the client load, so only the historical read failed. The frame now leaves such a read to the live graph during hydration, exactly like a request the server never seeded: the client loads its own selection once, the boundary (or root) waits for it, and adoption keeps the server's nodes while reporting changed text as a recoverable hydration mismatch. An explicit `beginAdoption` frame keeps the error, since it has no live fallback. The defect predates #1601: a `.tsrx` app whose props select another request than the server's already failed. #1601 gave `.tsx` returned-JSX components the server's owner key, which exposed it to #1607's tests, whose browser-only selection previously landed under an unseeded owner. Co-authored-by: Claude Opus 5.5 <[email protected]>


Summary
A signal component rendered below
.tsxreturned-JSX components got a different owner instance key on the server than in the browser, so hydration could not match the server-seeded owners. This happens on main.["","root"]["c:Wrap"]["c:Mid"]["c:Leaf"]._frag$Nrenderer, e.g.[root][c:frag][c:Wrap][c:frag][c:Mid][c:frag][c:Leaf]. In a module that importsoctane/signals, every value-position host descriptor block added a"legacy"level instead.The server side is authoritative. Renderers and host bodies are how the client represents a component's JSX; they are not authored invocations. The server renders the same JSX inline, a
.tsrxbody has no renderer, and identity must not depend on the representation. On main the client keys even changed when a module began importingoctane/signals.Changes
compile.js): synthesized fragment renderers now carry a renderer invocation site ('r:') in place of a hashedc:site. That covers the client_frag$N(lowerHostFragment) and the server__sfragmentand_sfrag$Nwrappers (ssrEmitTsrxExpression,serverValueDirectiveFold). The shorter literal also saves bytes in every returned-JSX component.runtime.ts): Blocks with that site, value-position host descriptor Blocks (hostElementBody), and dynamic tags that resolve to a host string now add no key segment. All the work happens when the Block is stamped (stampSignalInstanceKey):@for/list item tokens.structuralSignalInstanceKeyandscopeSignalOwnerare unchanged from main. The first push changed them, which put the fix on every bundle's path and failed theroot-chained-jsxbudget.runtime.server.ts):ssrComponentwith the renderer site keeps the enclosingSIGNAL_COMPONENT_INSTANCE_KEY. Its frame inherits the pendingSIGNAL_LIST_KEYSinstead of resetting them. A discovery job for such a frame retains those list keys, so a suspended renderer replay doesn't create an owner the final pass and the browser never use.docs/signals.mdnow states that only authored component invocations shape instance identity. Changeset (octanepatch).A temporary probe compared server and client keys for 23 returned-JSX shapes in both lowerings (plain and signals-importing) with
.tsx/.tsrxleaves. On main, 20 of the 23 shapes diverge in at least one variant: return chains, host values in props and children,.maprows, direct calls, dynamic host tags, a host value inside a hookless.tsrxcomponent, and@forrows of returned-JSX components. With this change all 92 of those variants agree. The.tsrx{props.children}render-function level ("legacy") was already the same on both sides and is unchanged. One related shape still diverges: a host or component value rendered under an@ifarm inside a hookless (lite).tsrxcomponent. That is a separate pre-existing bug on main: the Block chain under a lite scope skips the lite level and adds a strayu:token. It is not caused by renderers, so it's left out of this PR (see follow-ups).Validation
pnpm format:check: not run repo-wide.pnpm format:files:checkpasses on every changed file.pnpm typecheck: not run repo-wide.pnpm typecheck:filesis clean forruntime.ts,runtime.server.tsand the test file.pnpm test: not run locally, to keep load off the shared machine. CI runs it.vitest run --project octane packages/octane/tests/hydration/signal-instance-identity.test.tspasses 153/153 on the current head. With the renderer stamp disabled, all 40 new cases fail. The new cases:.maprows among them, plain and signals-importing app modules, dev and prod. It asserts that server and client owner instance keys are equal, that the<output>nodes are adopted, and and that an edit through the returned JSX'sonClickupdates both that JSX's output and the component body's own read. All 32 fail on main at the key assertion.pnpm syncleaves the tree clean.node benchmarks/bundle-size/run-minimal.mjs --budgets root-static-local root-chained-jsx hooks-state prop-attributes contextpasses.root-chained-jsx,root-static-local,hooks-state,prop-attributes,cli-spa-starterandhydrate-rootare byte-identical to base. Bundles that reach the genericcomponentSlot/childSlotpaths grow by about 165–195 raw bytes (context: +166 raw, +76 brotli).server-rendergrows by +198 raw.Risk / follow-ups
typeofcheck inchildSlot/componentSlot, and one comparison when a Block is stamped while signals are enabled. Key resolution stays lazy. ServerssrComponentgains one string compare. Compiled returned-JSX output shrinks slightly ('r:'replaces an 8-hex-digit site). Timing lanes are within noise.@ifarm inside a lite component lose the lite level (pre-existing walk bug at the lite Block stand-in, described above)..tsxcomponent that callsquery$(...).get()during render re-renders without end after hydrating a resumed query. The test therefore uses a.tsrxquery component with a bound{value$}child.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes signal instance key computation across compiler, client, and SSR runtimes for all trees under returned JSX; server and client move together but any external state keyed by old instance IDs would break.
Overview
Fixes signal owner / instance key mismatches between SSR and hydration when signals or queries sit under returned JSX (
.tsxreturns, host value props, dynamic host tags, keyed rows, etc.). The client used to add extra identity levels for compiled fragment renderers (_frag$N) and host descriptors; the server inlined that markup, so keys diverged and hydration could not resume server cells or query seeds.The compiler now tags those renderers with a shared
'r:'renderer invocation site instead of a per-locationc:hash. ClientstampSignalInstanceKeytreats that site as transparent (inherits the enclosing component’s key; dynamic host tags get the same treatment). ServerssrComponentskips a new instance segment for renderers, continues pending list keys, and discovery replays retain those keys for suspended rows.Docs state that only authored component invocations shape instance identity (importing
octane/signalsno longer shifts keys). New hydration tests cover many returned-JSX shapes plus streamed query resume.Reviewed by Cursor Bugbot for commit da36212. Bugbot is set up for automated code reviews on this repo. Configure here.