Repository navigation
fix(octane): re-select component-local query$ when captured props change - #1550
Conversation
A query$ or derived$ declared in a component kept the closure from its first render: ScopeImpl's declared nodes were first-declaration-wins, so a selector that captured props never re-selected after its first settle. Each render's declaration is now staged with the renderer. An equal selection or value keeps the committed cell and adopts the new closure at commit. A changed one is presented through a private view node, which acceptance promotes and a newer selection or unmount releases. A held transition or discarded attempt never changes what committed readers see, and a retried render reuses the held request instead of refetching it. Asynchronous derived$ work is never presented by a render that may be discarded; captured render values alone do not restart it, so query$ stays the keyed async primitive. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tor-redeclaration # Conflicts: # packages/octane/src/signals/facade.ts
A cold compile under heavy load spent the first test's five-second budget. Collection has no test timeout. 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 prepared a fix for the issue found in the latest run.
- ✅ Fixed: Barrier redeclarations hide ready values
- Added early return in both DerivedBinding.presentDefinition and ScalarBinding.presentDefinition when frozen or under a read barrier, so the committed cell's ready state is preserved instead of creating a stateless view that yields pendingState.
Or push these changes by commenting:
@cursor push 34083ca941
Preview (34083ca941)
diff --git a/packages/octane/src/signals/computations.ts b/packages/octane/src/signals/computations.ts
--- a/packages/octane/src/signals/computations.ts
+++ b/packages/octane/src/signals/computations.ts
@@ -175,6 +175,7 @@
protected presentDefinition(compute: DerivedCompute<T>): ScopedNode | undefined {
if (this.asynchronous) return undefined;
+ if (this.frozen || this.owner.readBarrier !== undefined) return undefined;
// A zero-argument computation runs once here. An equal synchronous value
// needs no view; any other result seeds the view, so the closure never
// runs twice and asynchronous work never starts twice.
diff --git a/packages/octane/src/signals/scalar-computations.ts b/packages/octane/src/signals/scalar-computations.ts
--- a/packages/octane/src/signals/scalar-computations.ts
+++ b/packages/octane/src/signals/scalar-computations.ts
@@ -88,6 +88,7 @@
/** An equal value needs no view; a changed one is evaluated once, privately. */
protected presentDefinition(compute: DerivedCompute<T>): ScopedNode | undefined {
+ if (this.frozen || this.owner.readBarrier !== undefined) return undefined;
let probe: { value: T; reads: ScopedNode[] } | undefined;
if (!this.frozen && this.owner.readBarrier === undefined) {
try {You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 5007de8. Configure here.
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)
All 20 timed operations (19 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)
97 other measured values are unchanged. CI job durations
Compares the CI run for
All 26 timed jobs
|
…the render path A frozen document keeps presenting committed derived values. Redeclaring a derived$ while frozen created a private view whose first evaluation under the read barrier was pending, so the render hid the committed value. A frozen cell now presents its committed value, installs the new closure at acceptance, and evaluates it when reads resume. The per-invocation declaration stage moves from renderBlockInner onto the native read driver's render frame, which only signal-using applications load. Applications without signals no longer pay for it in bytes or per render. The render-phase selection test runs as its own dev/prod table instead of a runIf modifier, which the test-marker check rejects. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
…1553) * fix(octane): give each custom-hook call its own signal declarations 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]> * fix(compiler): key aliased `$` hook calls the same way in every module 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]> * test(octane): re-select only the changed call of a repeated query$ hook 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]> * fix(compiler): bound hook calls in plain modules that import only signals #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]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…re unchanged (#1635) * fix(signals): keep a local derived$ or query$ whose captured values are unchanged Since #1550 a component-local derived$ or query$ re-ran its closure on every render, so an object result changed identity on equal-prop renders and every redeclaring render allocated a declaration stage. The compiler now lists the render values each local declaration captures, with hook dependency inference, and RedeclarableBinding returns the committed cell without staging or evaluating when every value is Object.is-equal. A local signal$ handle with a static key names one cell and is not listed. A per-invocation serial from the native-read driver keeps the first declaration in a render winning when two declarations share a cell. HMR compiles add a per-module revision so an edited closure still replaces the old one. A capture declared after the call is not read eagerly. Custom-hook declaration paths now join sites with NUL, so an authored key that spells out a path no longer aliases it, and are cached per call stack. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(signals): present the first declaration of a shared cell during server rendering Only the browser's native-read driver numbered render invocations, so on the server a second declaration naming the same cell, such as a repeated explicit key, installed its computation mid-render. That changed the cell's revision and server rendering threw, and the browser presented the first declaration instead. The server read driver now numbers each body scope, and a declaration installed outside a render stage counts as its render's first. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>


Summary
query$whose selector captures props now re-selects when those props change. Previously it kept its first render's closure forever, apart from a narrow window while a pending@tryre-created its reader owner.derived$now recomputes from captured props for the same reason.Why
ScopeImpl.declaredNodewas first-declaration-wins. The compiler declares__queryAt/__derivedAtagain on every render, with closures that capture that render's props, but the existing node kept the firstdescribe/compute. Rebinding the closure in place during render would expose speculative state, which is the hazard thedocs/signals.mdlocal-derived note described.Changes
RedeclarableBinding(signals/redeclaration.ts) is the new base ofResourceBinding,DerivedBindingandScalarBinding. Each instance (i:) declaration carries a sequence number, so an older closure never rebinds a cell. Module (g:) sites and uncompiled explicit keys keep first-declaration-wins (pinned bysignals-unified).registerSignalDeclarationStage). The stage lives on the native read driver's render frame, so applications without signals pay nothing in bytes or per render. It settles on capture commit/discard, and on transition-journal rollback.readsDuring/readsMatch) skips a second evaluation.createDeclarationView). Acceptance promotes it: state, dependencies and subscribers move to the cell, and the view's native sources forward, so render witnesses stay valid. The previous request is released, and aborted when nothing else selects it. A newer selection or unmount releases an unaccepted view. Query views are reused by request identity, so a retried held render adopts its pending request instead of refetching.declarationViewFork).derived$. It has no selection identity to match a retried render against, so a render that may be discarded never presents its async work. The attempt is adopted on acceptance and released on discard. An already-asynchronous cell adopts a new closure for its next signal-driven restart without restarting. Documented: usequery$for async work keyed by render values.docs/signals.mdis updated, and anoctanepatch changeset is added.Validation
pnpm format:check(not run repo-wide;pnpm format:files:checkon every changed file passes)pnpm typecheck(not run repo-wide;tsgoonpackages/octane/tsconfig.json,typetests/tsconfig.jsonandtypetests/signals-engine-node, plustypecheck:fileson the changed files, all pass)pnpm test(not run end to end; see the targeted runs below)packages/octane/tests/signal-local-selectors.test.tsandhydration/signal-local-selectors.test.tspass in dev (octane), prod and strong (octane-prod). They cover mount/update, abort and dedupe, inline loaders, signal dependencies of an adopted closure, selector failure, effects, render-phase reruns,@trystrict reads, held/superseded/abandoned transitions, unmount during a hold, signal-write transitions, synchronous and asynchronousderived$, and SSR → hydrate.octane+octane-prod(1293 files, 35758 passed) and alloctane-signals*projects (57 files, 987 passed).pnpm ci:workflow:test(302 passed, including the signals bundle-boundary and minimal-size gates).facade.ts) and addressing review (bf6b50d): fulloctane+octane-prod(1305 files, 36179 passed) and alloctane-signals*projects (55 files, 984 passed).pnpm test:markers:check,format:files:check,typecheck:filesandpnpm syncare clean.benchmarks/bundle-size/run-minimal.mjsmatches the base raw sizes in the PR bench report (for exampledeferred-hydration218779,binding-hooks87175,binding-base-ui-vite210679). The first push's +36 bytes came from arenderBlockInnerchange that is now gone.Risk / follow-ups
Per-render cost. Components with local declarations now evaluate the new closure on each redeclaring render. Ad-hoc jsdom timing, 200 rows re-rendered by an unrelated parent update, same machine state:
query$derived$Most of the difference is work the old code wrongly skipped. No existing benchmark covers component-local redeclaration.
Async
derived$flip. An asynchronousderived$that becomes asynchronous through captured props (props.id ? load(props.id) : 'none') presents the committed value for one commit, then its fallback, then the result. It starts its work once.Abandoned held selection. A held selection that an urgent update abandons keeps loading until a newer selection replaces it or the component unmounts.
Hydration timing gap. Changing props before hydration adoption has released is untested.
Custom-hook aliasing. Two calls of one custom hook currently alias to one cell; the separate fix (
fix/custom-hook-signal-declarations) changes the same facade lines. Until then that case makes two extra requests over its first two renders before settling.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
High Risk
Touches core signal graph commit semantics, query request lifecycle, and transition/suspense staging; regressions would affect data loading and speculative renders across the runtime.
Overview
Fixes component-local
query$and synchronousderived$so each render’s selector/compute closure can update when props or state change, instead of staying pinned to the first render.Staging and commit. Repeated instance (
i:) declarations go throughRedeclarableBinding: the renderer’s per-invocation declaration stage settles on accept/discard (including transition rollback). Equal canonical selections keep the in-flight request and adopt new loader/selector closures without refetching; changed selections use private declaration view nodes until commit, then promote state and release obsolete requests. Discarded transitions and suspended attempts never change what committed readers see; heldquery$work can be reused on retry.Derived and queries.
DerivedBinding,ScalarBinding, andResourceBindingshare the same redeclaration path (probes viareadsDuring/readsMatch). Asyncderived$does not expose speculative async work; new closures apply on the next dependency-driven restart—docs steer keyed async work toquery$.Adds
docs/signals.mdupdates, an octane patch changeset, and broad client/hydration tests for selectors, transitions, render-phase reruns, and local derived behavior.Reviewed by Cursor Bugbot for commit bf6b50d. Bugbot is set up for automated code reviews on this repo. Configure here.