Skip to content

fix(compiler): track an inherited method's receiver in use() memo dependencies - #1821

Merged
trueadm merged 12 commits into
mainfrom
fix/use-memo-method-receiver
Oct 6, 2026
Merged

trueadm merged 12 commits into
mainfrom
fix/use-memo-method-receiver

Conversation

@trueadm

@trueadm trueadm commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Builds on #1818, which has merged; main is merged in, so the diff is only this change.

A batched use() argument memo recorded a called one-level member by its value, so it missed receiver changes:

export function Page({ count, load }) @{
  const first = use(load('first'));
  const label = use(load(count.toFixed(1)));   // deps were [load, count.toFixed]
  <p>{(first + ':' + label) as string}</p>
}

Number.prototype.toFixed never changes, so after count went from 1 to 2 the text stayed first:1.0. This is the bug class of #542, in a different code path. The cause is collectDepPaths in compile.js, which builds .tsrx _$puPub/_$warmMemo creation dependencies, server prop-creation memos, and plain-hook use() memos (slot-hooks.js, via #1817).

collectDepPaths now records root.m(...) as __methodDep(root, 'm', true, true). That is the guarded own-descriptor probe the runtime already provides, so there is no runtime change:

  • inherited method, accessor, or primitive receiver: tracks the receiver (count.toFixed(1) now tracks count);
  • own function, arrow or not: tracks only itself;
  • absent property: undefined; nullish receiver: a stable marker, with no throw and no getter call.

Why not #1818's receiver rule

Inferred hook dependencies (#1818) track the receiver of every own non-arrow function. Applying that rule to use() memos turns use(props.load(id)) with a function load() loader into a request that restarts on every parent render and every boundary retry. A @try retry rebuilds the child's props, the memo misses, a fresh promise suspends again, and the cycle never ends.

benchmarks/recursive-context's WarmPlanControl has exactly this shape, and its verify asserts one child load. On #1818's head it loads the child once. With the receiver rule, the child loaded 51 times before the probe's guard stopped it. With this PR it loads once.

The cost: an own non-arrow function shared by several objects (#1788's case), called as source.read() inside a use() argument, is not witnessed when only source changes. docs/differences-from-react.md documents this and recommends passing the value it reads as an argument instead.

Changes

  • compile.js collectDepPaths: a CallExpression whose callee is a free one-level static member (including TS-wrapped, optional, and string-computed forms) pushes a guarded descriptor probe under its own …() key. A plain read of the same member elsewhere keeps its own value dependency. Arguments after an optional link are still skipped, and render-local roots are still coarsened.
  • compile.js depPathRoot/staticDepMemberName (Bugbot follow-up, 506ba1d): reads and calls see through erased TS wrappers on the receiver and on a computed key, so props!.load(id), (props as T).load(id) and props['load' as const](id) get the same probe as props.load(id) instead of falling back to the whole props object. Repo corpus: 0 further compiles changed.
  • slot-hooks.js: comment only.
  • docs/differences-from-react.md: a parallel-use() bullet on method-call dependencies and how they differ from inferred hook deps.
  • Changeset: octane patch.

Validation

  • pnpm format:check (scoped format:files:check on the changed files passes)
  • pnpm typecheck (scoped typecheck:files on the changed files passes)
  • pnpm test (not run locally because of the machine-load rule; CI runs it)
  • targeted tests: packages/octane/tests/creation-dependencies.test.ts, 990 passed on octane and 1,968 on octane + octane-prod at the earlier iteration.

New tests in creation-dependencies.test.ts (use() method-call dependencies):

  • Receiver changes: inherited, class, string-computed key, optional receiver, optional call, skipped optional-call argument, and callback body. Each runs under tsrx, tsx and ts, client and server, dev and prod.
  • Neighbor (own function): a rebuilt receiver that carries the same own arrow or function keeps the memo, with no reload, under tsrx and ts.
  • Retried boundary: a function loader prop under a retried @try starts once.
  • TS spellings: both tests above also run with x!.m(), (x as any).m() and x['m' as const](); those 30 cases failed before 506ba1d.
  • Mutation: switching calls to fix(octane): track the receiver of a shared own method in inferred dependencies #1818's receiver rule fails exactly these 6 neighbor and retried-boundary cases.

Compiled output corpus (base #1818 head vs this PR, client/server × dev/prod, with OCTANE_COMPILE_ASSERT_LOC=1):

  • Bundle-size fixtures: js-framework, todomvc, chat-stream, weather-app, bundle-size apps and fixtures. 392 compiles, 0 changed, so app and minimal budgets cannot move.
  • Whole repo: 24,992 compiles, 166 changed, 0 throw. Every change is a called member in a memoized creation, for example:
    • following.includes(…), a.slice(…) and answer$.get() previously keyed on a prototype method;
    • props.load(…) now keys on the own value via the probe.
  • codegen-size (compiled/source gzip, guard ≤ 1.3): 32,392 → 32,416 bytes, ratio 1.1963 → 1.1972.

Per-render cost (Node microbenchmark, ns per dependency evaluation):

Dependency ns per evaluation
Plain read (old) ~2
Guarded probe, own value ~11.6
Guarded probe, inherited method ~7.5
Primitive receiver ~2.2
#1818's unguarded __methodDep ~40

Risk / follow-ups

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


Note

Medium Risk
Compiler-only change that alters memo invalidation for every creation that calls a one-level method, with a small per-render descriptor-probe cost; behavior is heavily tested but touches parallel use() and Suspense retry paths.

Overview
Memoized use() arguments (and the same dependency policy for plain .ts hooks and server prop creations) now treat one-level method calls via a guarded __methodDep probe instead of depending on the callee value alone.

Inherited or accessor methods (e.g. use(load(count.toFixed(1)))) invalidate when the receiver changes, fixing stale labels when count updates but Number.prototype.toFixed does not. Own functions (arrow or function, including props.load(id)) still key only on the function identity so rebuilt props or @try boundary retries do not restart requests in a suspend loop.

depPathRoot / staticDepMemberName peel erased TypeScript wrappers on receivers and computed keys so props!.load, casts, and as const string keys match plain props.load for both reads and calls. Docs describe how this differs from inferred hook deps (where own non-arrow methods track the receiver). New matrix tests cover receiver refresh, stable own methods, retried boundaries, and TS spellings.

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


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

trueadm and others added 9 commits October 6, 2026 14:09
…pendencies

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]>
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]>
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]>
#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]>
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]>
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]>
…endencies

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]>
@trueadm
trueadm marked this pull request as ready for review October 6, 2026 14:36
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 6, 2026
@trueadm trueadm added the agent-authored Diff or issue body substantially produced by an AI agent label Oct 6, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Method-call deps skip TS receivers
    • Applied unwrapTsExpr to callee.object in the CallExpression handler and to member.property in staticDepMemberName so that TS-wrapped receivers (props!, props as T, etc.) and computed keys ('load' as const) are correctly peeled to their underlying Identifier/Literal, matching the unwrapValue already used by staticMemberInfo in hook-deps.js.

Create PR

Or push these changes by commenting:

@cursor push 1d78a83229
Preview (1d78a83229)
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
@@ -18077,12 +18077,9 @@
 	const member = depPathMember(node);
 	if (member === null) return null;
 	if (!member.computed && member.property.type === 'Identifier') return member.property.name;
-	if (
-		member.computed &&
-		member.property.type === 'Literal' &&
-		typeof member.property.value === 'string'
-	) {
-		return member.property.value;
+	if (member.computed) {
+		const prop = unwrapTsExpr(member.property);
+		if (prop?.type === 'Literal' && typeof prop.value === 'string') return prop.value;
 	}
 	return null;
 }
@@ -18342,10 +18339,11 @@
 			case 'CallExpression': {
 				const callee = depPathMember(unwrapTsExpr(n.callee));
 				const name = staticDepMemberName(callee);
-				if (callee?.object.type === 'Identifier' && name !== null) {
-					if (isFree(callee.object, callee, 'object') && !deferredAmbient(callee.object.name)) {
+				const obj = callee ? unwrapTsExpr(callee.object) : undefined;
+				if (obj?.type === 'Identifier' && name !== null) {
+					if (isFree(obj, callee, 'object') && !deferredAmbient(obj.name)) {
 						const member = b.member(
-							b.id(callee.object.name),
+							b.id(obj.name),
 							callee.computed ? b.literal(name, JSON.stringify(name)) : b.id(name),
 							callee.computed,
 						);

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 0f03a0d. Configure here.

Comment thread packages/octane/src/compiler/compile.js Resolved
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No budget breaches, no added work, and no timing changes beyond ±3%.

Compares c15aa5ae0, the merge commit's first parent with d96398ea7 on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.717 2.725 ±0.0% −3.2% … +1.8% ⚪ within noise
octane-tsrx replace 5.433 5.475 ±0.0% −3.3% … +2.2% ⚪ within noise
octane-tsrx add 2.333 2.325 −1.9% −4.2% … ±0.0% ⚪ within noise
octane-tsrx update 0.119 0.118 −0.5% −2.9% … +1.1% ⚪ within noise
octane-tsrx select 0.005 0.005 −0.5% −1.0% … +0.5% ⚪ within noise
octane-tsrx swap 0.038 0.038 +0.9% −0.3% … +1.8% ⚪ within noise
octane-tsrx remove 0.018 0.018 +0.5% −2.0% … +3.3% ⚪ within noise
octane-tsrx runlots 24.767 24.250 +0.8% −2.2% … +2.1% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 +0.6% +0.0% … +1.3% ⚪ within noise
octane-tsrx clear 40.658 42.375 +2.5% +0.9% … +4.6% ⚪ within noise
octane-jsx run 3.325 3.208 −0.0% −5.2% … +1.5% ⚪ within noise
octane-jsx replace 5.967 5.958 +1.7% ±0.0% … +6.7% ⚪ within noise
octane-jsx add 3.108 3.017 ±0.0% −4.6% … +1.6% ⚪ within noise
octane-jsx update 0.248 0.247 −0.7% −2.3% … +0.7% ⚪ within noise
octane-jsx select 0.129 0.124 −3.0% −7.3% … −2.0% ⚪ within noise
octane-jsx swap 0.233 0.228 −2.1% −4.7% … −0.7% ⚪ within noise
octane-jsx remove 0.178 0.178 ±0.0% −2.3% … +1.4% ⚪ within noise
octane-jsx runlots 27.642 28.158 −1.1% −2.8% … +1.1% ⚪ within noise
octane-jsx select_lots 1.438 1.443 −0.0% −2.4% … +1.2% ⚪ within noise
octane-jsx clear 43.767 44.333 +0.4% −2.0% … +2.6% ⚪ within noise

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.

trueadm and others added 2 commits October 6, 2026 15:52
… 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]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website 8cdd375 Commit Preview URL

Branch Preview URL
Oct 06 2026, 07:43 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp 8cdd375 Commit Preview URL

Branch Preview URL
Oct 06 2026, 07:45 PM

@trueadm
trueadm merged commit 1744e83 into main Oct 6, 2026
55 of 58 checks passed
@trueadm
trueadm deleted the fix/use-memo-method-receiver branch October 6, 2026 19:51
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