Repository navigation
fix(octane): give each custom-hook call its own signal declarations - #1553
Conversation
A `signal$`, `derived$` or `query$` declared inside a custom hook was keyed only by its component instance and declaration site, so two calls of one hook in one component aliased a single cell: `useUser$(a)`/`useUser$(b)` rendered `X|X` and ran one loader. Instance declarations now fold in the compiler-assigned call sites of the enclosing custom-hook calls. Runtime hook-slot numbers follow module evaluation order and differ between server and browser, while declaration keys are wire identity for seeds, streamed results and early values, so each signal-aware custom-hook call gets a position-hashed `h:` site registered on its slot Symbol (tsrx, plain-module surgical and inline-memo paths). Sites are emitted only for DOM targets, in modules with a runtime signals import or for `$` hooks. 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 (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)
102 other measured values are unchanged. CI job durations
Compares the CI run for
All 26 timed jobs
|
|
On the 🔴 |
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: Aliased dollar hooks drop sites
- Changed compile.js to use
n._octaneCustomHookCall ?? localNameinstead of justlocalNamewhen callingcustomHookSignalSite, matching the slot-hooks.js path that correctly uses the original imported name for the$suffix check.
- Changed compile.js to use
Or push these changes by commenting:
@cursor push 502c867ecd
Preview (502c867ecd)
diff --git a/packages/octane/src/compiler/compile.js b/packages/octane/src/compiler/compile.js
--- a/packages/octane/src/compiler/compile.js
+++ b/packages/octane/src/compiler/compile.js
@@ -20181,7 +20181,7 @@
},
forceSymbol,
null,
- isCustom ? customHookSignalSite(ctx, n, localName) : null,
+ isCustom ? customHookSignalSite(ctx, n, n._octaneCustomHookCall ?? localName) : null,
);
slot = symVar;
}You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 05aa67c. Configure here.
…e kind
A `.tsrx` module checked only the local callee for a trailing `$`, while
plain modules checked only the imported name. `import { useUser$ as
useUser }` in a component module without a signals import therefore still
shared one cell across calls. All three emitters now register a call site
when either the local or the imported hook name ends in `$`; the `.tsrx`
path reads the exported name from the authored imports that its server
and client compiles share.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l-declarations # Conflicts: # packages/octane/src/signals/derived-facade.ts # packages/octane/src/signals/facade.ts # packages/octane/src/signals/query-facade.ts
Pins the combination with #1550: each custom-hook call owns its own query, so a new captured argument re-selects that call's query and leaves the other call's result in place. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nals #1546 gave module-local custom-hook calls a withSlot boundary, but the plain pass still walks only modules that import from `octane`. A `hooks.ts` that imports `query$` from `octane/signals` and composes its own hooks (`useUsers$` calling `useUser$` twice) therefore got no boundary, and both calls shared one cell. A runtime signals import makes the module Octane's, so its imported or declared `use*` hooks are now walked too. A module that only declares signals is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>


Summary
signal$,derived$orquery$declared inside a custom hook now belongs to each call of that hook. Two calls in one component (useUser$(a),useUser$(b)) previously shared one cell: the second call rendered the first call's data (X|X) and never ran its own loader.Why
i:) declarations were keyed by (component instance, declaration site) only, soScopeImpl.declaredNodereturned one node for every call of the hook. Octane keys hooks by compiler-assigned call site, so the declaration's identity should include the enclosing custom-hook calls rather than become a compile-time diagnostic. A diagnostic also cannot see calls that cross modules.hookSlots()numbers follow module evaluation order and differ between server and browser, while declaration keys are wire identity (native seeds, streamed frames, early values). S8 indocs/async-signals-implementation.mdrequires compiler IDs that never depend on process counters.Changes
compile.js,slot-hooks.js,plain-hook-memo.js): each custom-hook call's slot Symbol is registered with a position-hashedh:site (signalHookCallSiteinsignal-declarations.js). It applies in modules with a runtime signals import, and for hooks whose local or imported name ends in$. It is limited to DOM targets: universal/valdi output and universal runtime units get nothing, so native bundles never import the DOM runtime.slot-hooks.js): a runtimeoctane/signalsimport now makes the plain pass walk the module's imported or declareduse*hooks. Ahooks.tscomposing its own declaring hooks otherwise got no call boundary at all. Modules that only declare signals are byte-identical; no current workspace module is affected.signals/declaration-path.ts; client and server runtimes export an internalsignalHookSitebound to their own slot stack. The publicoctaneentry is unchanged.declarationKey()appends the enclosing call sites toi:keys (explicit{ key }too) insignal$,derived$andquery$.docs/signals.md; patch changeset.Validation
pnpm format:checkpnpm typecheckpnpm sync(no generated changes)pnpm test: not run in full. The machine was running ~150 concurrent vitest processes from other sessions; the targeted runs are below.signals-hook-declarations.test.ts(81 cases: dev, prod and strong compiles, each in theoctane-signals,-prodand-strongprojects). It covers query/signal/derived per call, nested hooks, conditional skip, hooks composed in plain.ts(surgical and inline-memo paths, including a type-wrapped callee) and in.tsrxwithout a signals import, plus SSR→hydrate adoption with shifted server slot numbering, including the project's HMR client build.compiler/signal-declarations.test.ts(universal output stays offoctane/internal/client).hmr.test.tstimes out on basemainunder the same load. After rebasing onto currentmain,hydration/signal-instance-identity.test.tsfailed only at load average ~60 (re-imports per test); its failing groups pass when run alone.node --testscoped-signals bundle-boundaries, bundle-size minimal gates, initial-document-signals: 37/37.$gate, the HMR branch, the DOM-target gate) each turn the matching tests red.Performance
Minified esbuild client bundles, same script before and after:
Per render: one prefix check per instance declaration, plus an O(hook depth) path join only for declarations inside custom hooks. Wall-clock was not measured: machine load made timings untrustworthy.
Risk / follow-ups
$keeps the previous shared cell; it adds no path segment..tsmodules do not slot calls to locally declared custom hooks, so evenuseStatecollides across two calls.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches instance signal identity, compiler hook lowering, and SSR/hydration key agreement—core reactive state paths—but behavior is gated to DOM signal-aware/
$hooks with broad targeted test coverage.Overview
Fixes per-call isolation for
signal$/derived$/query$declared inside custom hooks. Two invocations of the same hook in one component (e.g.useUser$(a)anduseUser$(b)) no longer share one instance cell, so loaders and state stay independent; conditionally skipped calls keep their own cells for the instance lifetime.The compiler (TSRX
compile.js, plain-moduleslot-hooks.js/plain-hook-memo.js) registers DOM-only, position-hashedh:sites viasignalHookCallSiteand wraps eligible custom-hook slot symbols with runtimesignalHookSite. That applies in signal-importing modules and for hooks whose local or imported name ends in$; universal/non-DOM builds skip it.Runtime adds
declaration-path.tsand client/serversignalHookSitehelpers that fold the enclosing custom-hook path into keys.declarationKey()appends that path to instance (i:) identities in the signal facades so SSR seeds, hydration, and streamed results match across server and client without relying on hook slot numbering.Docs and a patch changeset describe the behavior; new integration tests cover queries, cells, composition across modules, and SSR→hydrate adoption.
Reviewed by Cursor Bugbot for commit 07371d9. Bugbot is set up for automated code reviews on this repo. Configure here.