Repository navigation
fix(compiler): read only authored values in plain-hook use() dependencies - #1817
Merged
Merged
Conversation
…cies Plain `.ts`/`.js` hook modules memoize `use()` arguments through slot-hooks' `collectParallelUseDependencies`. It recorded every one-level `root.prop` read as an eager dependency, with no skip or defer policy. A dependency array runs on every render, so `use(load(run?.(options.label) ?? 'idle'))`, `use(load(() => options.label))` and `use(load(ready ? options.label : 'idle'))` all threw when `options` was undefined. A `typeof window !== 'undefined'` guard also emitted a bare `window` dependency, which throws during server rendering. The collector now delegates to the full compiler's `collectDepPaths`, so both paths share one dependency policy: - Deferred reads become `root?.prop` for bound roots and drop ambient globals. - Reads after an optional link become `__methodDep(root, 'prop', true)`. - typeof guards are replayed. Free names resolve through a module scope analysis that is built only for non-trivial arguments. The synthesized dependencies are printed back to text, and the names they read still decide whether a `use()` joins the current batch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 6, 2026 12:53
Contributor
Benchmark report🟢 No budget breaches, no added work, and no timing changes beyond ±3%. Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)No changes across 60 measured values. Public-import reachability bundles (bytes)No changes across 105 measured values. |
🚀 Deploying Preview to Cloudflare 🚀Preview Deployments by commit
|
🚀 Deploying Preview to Cloudflare 🚀Preview Deployments by commit
|
trueadm
added a commit
that referenced
this pull request
Oct 6, 2026
#1817 routes skipped `root.prop` reads in memoized use() arguments through the guarded `__methodDep` probe. That probe now treats a guarded call's own non-arrow function as receiver-dependent, so a skipped read of a stable ordinary function would reload whenever its container is rebuilt. The probe is a read, never a call, so it passes the `read` flag like the other guarded reads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 6, 2026
trueadm
added a commit
that referenced
this pull request
Oct 6, 2026
…pendencies (#1818) * fix(octane): track the receiver of a shared own method in inferred dependencies An inferred dependency for a one-level method call `source.read()` compared the own function `source.read` alone. When two objects share one own function, swapping the receiver kept that identity, so an inferred effect stayed subscribed to the old object and an inferred memo kept its old value (#1788). `__methodDep` now keeps an own function's identity only when it is an arrow, which cannot see `this`; any other own method tracks its receiver, as an inherited one already did and as React Compiler does for every method call. The arrow check reads the function's source text, skipping it for functions that own a `prototype`. Guarded plain reads pass a new `read` flag, so a guarded read of a function value still compares the value. Every emitter (component hooks, plain hooks, inline hook memos, Strong caches, signal captures, and binding-program refs) builds the flags from one helper. Closes #1788. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(octane): shrink the arrow check in method dependencies Classify every own function with the source pattern alone. The `prototype` pre-filter and the `(` fast path saved about 20 ns per call but cost 100 raw bytes in every bundle that ships the helper. A callable proxy's source reads as native code and fails the pattern before `name` is read, so the probe needs no exception guard. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(octane): keep a parenthesized arrow named async on its own identity Folding the leading-`(` check into the arrow pattern applied the `async` name guard to every arrow, so `{ async: () => … }` tracked its receiver. Only source that may be a method named `async` needs the guard; a parenthesized arrow cannot be one. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): mark use() dependency probes as reads #1817 routes skipped `root.prop` reads in memoized use() arguments through the guarded `__methodDep` probe. That probe now treats a guarded call's own non-arrow function as receiver-dependent, so a skipped read of a stable ordinary function would reload whenever its container is rebuilt. The probe is a read, never a call, so it passes the `read` flag like the other guarded reads. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(octane): fall back to the receiver when a method probe throws The unguarded own-property path classified a method without the fallback the guarded path has. A patched `Function.prototype.toString` or a throwing `name` getter then failed the whole inferred dependency array. A probe that throws now counts as a method, as a failed guarded probe already does, and the authored call keeps any exception. The bare-parameter arrow cases now build their source with the Function constructor: the test transform re-prints `v => v` as `(v) => v`, so those cases had not reached the identifier branch of the arrow pattern. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(evals): pass arrow callbacks in the inferred-hook-deps grader The reference solution calls `props.onTotal(total)` from an inferred effect. #1818 makes a call through an own non-arrow function track its receiver, as React Compiler does, and a `vi.fn()` is an ordinary function that records `this`. Passed directly, every rebuilt props object became a real dependency and the grader's "no unrelated repeat" step saw a second call. Each observer now reaches the component through a stable arrow, as a parent passes a callback; the assertions still read the spies, so a solution with a `null` or hand-written array still fails. The manifest's grader digest is regenerated. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 6, 2026
…endencies (#1821) * fix(octane): track the receiver of a shared own method in inferred dependencies An inferred dependency for a one-level method call `source.read()` compared the own function `source.read` alone. When two objects share one own function, swapping the receiver kept that identity, so an inferred effect stayed subscribed to the old object and an inferred memo kept its old value (#1788). `__methodDep` now keeps an own function's identity only when it is an arrow, which cannot see `this`; any other own method tracks its receiver, as an inherited one already did and as React Compiler does for every method call. The arrow check reads the function's source text, skipping it for functions that own a `prototype`. Guarded plain reads pass a new `read` flag, so a guarded read of a function value still compares the value. Every emitter (component hooks, plain hooks, inline hook memos, Strong caches, signal captures, and binding-program refs) builds the flags from one helper. Closes #1788. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(octane): shrink the arrow check in method dependencies Classify every own function with the source pattern alone. The `prototype` pre-filter and the `(` fast path saved about 20 ns per call but cost 100 raw bytes in every bundle that ships the helper. A callable proxy's source reads as native code and fails the pattern before `name` is read, so the probe needs no exception guard. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(octane): keep a parenthesized arrow named async on its own identity Folding the leading-`(` check into the arrow pattern applied the `async` name guard to every arrow, so `{ async: () => … }` tracked its receiver. Only source that may be a method named `async` needs the guard; a parenthesized arrow cannot be one. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): mark use() dependency probes as reads #1817 routes skipped `root.prop` reads in memoized use() arguments through the guarded `__methodDep` probe. That probe now treats a guarded call's own non-arrow function as receiver-dependent, so a skipped read of a stable ordinary function would reload whenever its container is rebuilt. The probe is a read, never a call, so it passes the `read` flag like the other guarded reads. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(octane): fall back to the receiver when a method probe throws The unguarded own-property path classified a method without the fallback the guarded path has. A patched `Function.prototype.toString` or a throwing `name` getter then failed the whole inferred dependency array. A probe that throws now counts as a method, as a failed guarded probe already does, and the authored call keeps any exception. The bare-parameter arrow cases now build their source with the Function constructor: the test transform re-prints `v => v` as `(v) => v`, so those cases had not reached the identifier branch of the arrow pattern. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(evals): pass arrow callbacks in the inferred-hook-deps grader The reference solution calls `props.onTotal(total)` from an inferred effect. #1818 makes a call through an own non-arrow function track its receiver, as React Compiler does, and a `vi.fn()` is an ordinary function that records `this`. Passed directly, every rebuilt props object became a real dependency and the grader's "no unrelated repeat" step saw a second call. Each observer now reaches the component through a stable arrow, as a parent passes a callback; the assertions still read the spies, so a solution with a `null` or hand-written array still fails. The manifest's grader digest is regenerated. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): track an inherited method's receiver in use() memo dependencies A batched use() argument recorded a called one-level member by its value, so `use(load(count.toFixed(1)))` depended on `Number.prototype.toFixed` and never refreshed when `count` changed. collectDepPaths now records a called member through the guarded `__methodDep` descriptor probe: an inherited method, accessor, or primitive receiver tracks the receiver, while an own function of any kind keeps its identity. Tracking the receiver of an own non-arrow function, as inferred hook dependencies do, would key `use(props.load(id))` on a rebuilt props object and start a fresh request on every parent render and boundary retry. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): read use() memo dependencies through erased TypeScript wrappers `props!.load(id)`, `(props as T).load(id)`, and `props['load' as const](id)` call the same member as `props.load(id)`, but collectDepPaths only unwrapped the callee, so a wrapped receiver or key fell back to the whole `props` object. A `function` loader then restarted on every parent render and boundary retry. Unwrap the receiver and a computed key for reads and calls. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
5 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
use()arguments in plain.ts/.jshook modules now use the same dependency rules as.tsrxcomponents. Their dependency arrays no longer read values the authored argument skips.optionsundefined,use(load(run?.(options.label) ?? 'idle')),use(load(() => options.label))anduse(load(ready ? options.label : 'idle'))now render instead of throwing. Atypeof window !== 'undefined' ? window.location : …argument no longer reads a barewindowduring SSR.Follow-up to #1813 (issue #1799). That PR fixed
collectDependenciesandcollectDepPaths, and listed this collector as out of scope.Why
slotHooksmemoizes a plain module'suse()argument as_$useMemo(() => (arg), [deps], slot)on the client and_$puMemo(...)on the server. Its collector,collectParallelUseDependencies, recorded every one-levelroot.propread as an eager dependency, with no skip or defer policy. The array evaluates on every render, so it read values the argument never reads. Onmain:main.tsrx)load(run?.(options.label) ?? 'idle')[load, run, options.label][load, run, __methodDep(options, "label", true)]load(() => options.label)[load, options.label][load, options?.label]load(ready ? options.label : 'idle')[load, ready, options.label][load, ready, options?.label]load(options.a ?? window.x)[load, options.a, window.x][load, options.a]load(typeof window !== 'undefined' ? window.location : options.label)[load, window, window.location, options.label][load, typeof window, (typeof window !== 'undefined') ? window.location : void 0, !(typeof window !== 'undefined') ? options.label : void 0]Changes
slot-hooks.js:collectParallelUseDependenciesnow calls the full compiler'scollectDepPaths, so the two paths cannot drift apart again. It replaces about 260 lines of separate scope tracking.createLexicalAnalysisof the module. It is built lazily, on the first non-trivialuse()argument.printParallelUseDependencyprints the closed set of dependency shapescollectDepPathssynthesizes back to text, keeping this pass on its text-edit path. That set is identifiers, one-level members,typeofwitnesses,__methodDepprobes, and replayed typeof-guard conditionals.use()that reads an earlier result starts a new batch. Trivial arguments compute their root directly and never build the scope analysis.compile.js:collectDepPathsis now exported. No other change.docs/differences-from-react.md: the optional-chain paragraph now names plain.ts/.jshook modules.Validation
pnpm format:check: not run repo-wide.pnpm format:files:checkpasses on every changed file.pnpm typecheck: not run repo-wide.pnpm typecheck:filesonslot-hooks.js,compile.jsand the test file passes.pnpm test: not run in full; CI runs it.creation-dependencies.test.ts(--project octane): 894/894 pass.use()suites:compile-profile,plain-hook-memo-codegen,strong-effects,external-hook-slot,ssr-parallel-useandstrong-hook-cachepass, 709/709.main, all 24 new plain-hook shape tests fail withTypeError: Cannot read properties of undefined (reading 'label'). The extended matrix adds another 128ts-dialect failures, such ascreationAbsentGlobal is not defined. Notsrx/tsxcase changes.Cannot access 'first' before initialization.creationAbsentGlobal is not defined.slotHooksran over all 1,601 tracked plain modules that importoctane, in client and server withhmron and off. All 6,404 outputs are byte-identical tomain. The 4 errors are the deliberateContext.Providertypetest, which fails identically onmain.use()statements,slotHooksnew/old median is 1.004 (range 0.98–1.07, machine load about 5). This PR makes no performance claim.New coverage in
creation-dependencies.test.ts:.tsdialect for the whole creation matrix. That covers every case, the guarded-global, getter, missing-global, readiness, hydration-adoption, constructor and skipped-plus-read getter tests, in client and server, dev and prod.plain hook use() dependencies, covering six reported shapes:||right side??right sideoptionsundefined and null, a throwing getter in skipped positions, and a field change on the same object.typeofread of an earlieruse()result keeps the lateruse()out of its batch.Risk / follow-ups
root?.prop, which still invokes a getter, as in.tsrx.(options).label, the dependency coarsens tooptions. The full compiler does the same for a parenthesis-preserving AST.use()arguments containing a deferred, skipped or typeof-guarded read.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Compiler-only change to generated memo dependency arrays for plain modules with non-trivial
use()arguments; behavior shifts for optional chains, guards, and SSR globals, though corpus checks report byte-identical output when arguments lack those patterns.Overview
Plain
.ts/.jshook modules now infer memoizeduse()dependency arrays with the same rules as.tsrxcomponents, instead of a separate collector that treated every one-level member read as eager.slot-hooks.jsroutescollectParallelUseDependenciesthrough the sharedcollectDepPathshelper (exported fromcompile.js), with module lexical scope fromcreateLexicalAnalysis. Dependency evaluation on each render therefore defers reads inside callbacks and short-circuit branches (options?.label), skips optional-chain argument/key reads via guarded__methodDepprobes, and replaystypeofguards so SSR does not touch bare globals likewindow. A small printer turns synthesized dep nodes back to source text; root name tracking still splits paralleluse()batches when a later argument depends on an earlier result.Docs note that plain hook modules follow the same optional-chain dependency rules. Tests extend the creation-dependency matrix to the
tsdialect and addplain hook use() dependenciescoverage for optional calls, conditionals, batch ordering, and throwing getters in skipped positions.Reviewed by Cursor Bugbot for commit 0524dbf. Bugbot is set up for automated code reviews on this repo. Configure here.