Repository navigation
feat: trust pure renders in Strong mode - #866
Conversation
domgan-oai
left a comment
There was a problem hiding this comment.
I would not merge the current implementation yet. I found five reproducible regressions below, using the current head f748ff3 and exact base d5175ca. These involve pure immutable inputs or supported setup hooks, not the deliberately unsupported hidden-ref/live-accessor cases.
Direction
The opt-in pure-projection contract is defensible, and the benchmark demonstrates a real reduction in evaluated work. The problem is applying that assertion more broadly than the existing dependency and lifecycle machinery supports. Purity cannot substitute for complete receiver/callee dependencies, valid dependency expressions, or hook/context/effect semantics.
I would keep the ordinary pure-call optimization, but retain semantic boundaries around actual setup hooks and leave unsupported expression shapes on the existing path until their dependency handling is complete. The same-module component proof currently analyzes setup and render output together, so the documented promise that actual hooks retain their setup behavior is not yet enforced.
Verification and missing coverage
- The existing
for,auto-memo,automemo-render-calls, and compilerstrong-modesuites pass: 828 tests through a focused production configuration. - The new input-replacement/chained-expression probes pass 18/18 on the base; 8 fail on this head (five stale values and three mount errors). All nine
autoMemo: falsecontrols pass. - Custom-hook context and Suspense layout-effect probes pass all four Strong/compatibility controls on the base. On this head, both Strong cases fail and both compatibility controls pass.
- The aliased built-in keyed-row probe passes Strong on the base and fails Strong on this head. Its compatibility failure already exists on the base, so that part is not attributed to this PR.
- All 13 applicable benchmark ratio guards pass. With the same new fixture on both commits, stable call work falls from 3,584 to 0, while changed-argument work remains 126. Eight additional server-to-dev/prod hydration checks pass.
The new benchmark exercises keyed rows, but misses the newly admitted component-prop boundaries, replacement of callable/receiver identities, context changes through setup hooks, and Suspense effect reconnection. Add those semantic cases to the regular runtime suite and keep operation-count assertions in the benchmark. The benchmark workflow is weekly/manual, so green ordinary PR CI does not cover the seven-shape guards.
Local verification used Node 26.4.0 and the repository's existing fixture/runtime harness. The configured npm registry denied part of installation; the missing TSRX source was taken from the official @tsrx/[email protected] release commit tsrx-org/tsrx@7cb01278, with the checked-in patch applied. The base tests explicitly alias Octane exports to base source, avoiding accidental use of the head compiler through shared dependency links. I did not rerun the full monorepo suite; current-head CI is green.
No earlier review comments were present. This is a comment-only review; no approval is submitted, and the PR does not have the codex-approvable label.
|
Addressed all five review findings in 8447074: chained member results no longer emit property tokens as dependencies; guards include callable and receiver identity; compiler-proven built-ins and transitive same-module setup hooks retain lifecycle semantics without a use-name heuristic; Suspense reveals reconnect cached-child layout effects; and aliased built-ins block keyed-row setup skipping. Validation: 1,056 focused compiler/runtime tests, 158 Strong mount/hydration tests, 43 docs/search tests, full repository typecheck, repository-wide formatting, pnpm sync, and template-call-memo ratio guards all pass. |
domgan-oai
left a comment
There was a problem hiding this comment.
Revalidated 8447074. All five original reproduction cases are fixed, including the compatibility-mode hook-alias case that previously failed on the base. The unchanged original probe suite now passes 26/26, and the new permanent tests cover those failures.
The direction is improved: retaining actual setup operations separately from ordinary projections is the right boundary. I found two remaining holes in the new hook proof, plus an existing equality weakness exposed by the newly memoized constructor path; details are inline. I would address those before calling the broadened contract safe.
Validation:
- 839 relevant compiler/runtime tests pass.
- 24 additional ordinary expression checks pass, covering receiver replacement, callbacks, computed methods/tags, spread arguments, and optional/conditional evaluation.
- 8 server-to-dev/prod hydration probes and all 13 applicable benchmark guards pass; benchmark counts and output sizes are unchanged from the original PR head.
- The new hook edge-case matrix passes 12/12 on the exact base
d5175ca, but fails two Strong cases on this head. Compatibility and source-local controls pass. - The signed-zero constructor case passes on the base and with memoization disabled, but fails here. The arithmetic control already fails on the base: the underlying
!==weakness predates this repair, so I am not attributing its introduction to the new dependency walker.
Base runs explicitly resolve Octane exports to base source. I used the same focused harness and dependencies as the original review, not a full local monorepo run. At the last check there were no failing CI checks; the React parity aggregate and Bugbot Autofix were still running.
Submitting a comment-only follow-up, not approval. The original examples are addressed, but the remaining findings below need attention; codex-approvable is still absent.
The setup-hook veto in containsRenderCall, autoMemoBuiltinHookName, and the recursive walk in autoMemoCallExecutesSetupHook only matched CallExpression nodes. Since the enclosing branch already handles OptionalCallExpression, an optional hook call like useContext?.(Theme) bypassed the veto and was admitted by plainCalleeIsMemoizable as a pure projection under Strong mode. This could cause keyed rows and child caches to skip context, state, and effect setup. Extend the type checks in all three locations to also match OptionalCallExpression. For autoMemoBuiltinHookName, also accept OptionalCallExpression in the callee-name branch since these nodes lack the _octaneUnboundCallee annotation from hook-deps analysis.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Optional hook aliases skip setup detection
- Extended hook-deps.js to annotate OptionalCallExpression nodes with _octaneImportedHook/_octaneUnboundCallee/_octaneHookRuntimeImportedHook provenance, and extended containsAutoMemoContextRead to check both CallExpression and OptionalCallExpression, so aliased optional hook calls are now correctly identified as setup hooks.
Or push these changes by commenting:
@cursor push 2bd751b1be
Preview (2bd751b1be)
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
@@ -4178,7 +4178,10 @@
) {
return;
}
- if (node.type === 'CallExpression' && node.callee?.type === 'Identifier') {
+ if (
+ (node.type === 'CallExpression' || node.type === 'OptionalCallExpression') &&
+ node.callee?.type === 'Identifier'
+ ) {
const name =
node._octaneImportedHook ??
node._octaneHookRuntimeImportedHook ??
diff --git a/packages/octane/src/compiler/hook-deps.js b/packages/octane/src/compiler/hook-deps.js
--- a/packages/octane/src/compiler/hook-deps.js
+++ b/packages/octane/src/compiler/hook-deps.js
@@ -605,6 +605,21 @@
if (trustedConfig && node.arguments.length === trustedConfig.deps) {
candidates.push({ call: node, scope, name: trustedName, config: trustedConfig });
}
+ } else if (node.type === 'OptionalCallExpression') {
+ const octaneImportedName = canonicalOctaneHookName(node, scope);
+ const callee = unwrapValue(node.callee);
+ const unboundCallee =
+ callee?.type === 'Identifier' && resolveBinding(scope, callee.name) === null;
+ const hookRuntimeImportedName = canonicalHookName(node, scope, true);
+ if (octaneImportedName !== null || unboundCallee || hookRuntimeImportedName !== null) {
+ const props = {};
+ if (octaneImportedName !== null) props._octaneImportedHook = octaneImportedName;
+ if (unboundCallee) props._octaneUnboundCallee = true;
+ if (octaneImportedName === null && hookRuntimeImportedName !== null) {
+ props._octaneHookRuntimeImportedHook = hookRuntimeImportedName;
+ }
+ callAnnotations.set(node, props);
+ }
}
if (node.type?.startsWith('TS') && !TS_VALUE_WRAPPERS.has(node.type)) return;You can send follow-ups to the cloud agent here.
…nto codex/use-strong-pure-renders # Conflicts: # packages/octane/src/compiler/compile.js
|
Follow-up review feedback is addressed in b48309b/cc5ca4861: setup-hook reachability is now an order-independent lexical fixed point, shadowed assignments no longer demote the real module hook, memo guards use SameValue semantics for signed zero, and optional direct/aliased built-ins retain lifecycle behavior without a name-only Rules-of-Hooks heuristic. The existing project-wide configuration is also documented explicitly: Vite/Rsbuild read |
|
CI follow-up: Node 24 shard 3 exposed that the initial SameValue change was too broad for keyed selection, whose authored comparison intentionally treats 0 and -0 as equal. Commit 44e1d29 scopes Object.is to component-projection inputs (preserving the reviewed constructor fix) and keeps strict equality for keyed list/selection guards. The exact failed CI test now passes in both dev/prod projects; the final focused matrix is 1,205 tests, all 13 ratio guards pass, and benchmark output returns to 4408 compiled / 47576 gzip bytes. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
Autofix Details
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Missing scope treats hooks as pure
- Changed three sites (autoMemoBuiltinHookName identifier path, autoMemoSetupHookFunctions call-graph edges, and autoMemoCallExecutesSetupHook) to fall back to lexical.rootScope when nodeScopes has no entry, matching the existing conservative fallback already used by the namespace/member path.
- ✅ Fixed: Namespace optional hooks skip TS peels
- Applied unwrapTsExpr to callee.object and callee.property in the namespace optional-call branch so parenthesized or assertion-wrapped receivers like (Octane as any).useContext?.() are correctly identified as hook calls.
Or push these changes by commenting:
@cursor push c26522ca16
Preview (c26522ca16)
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
@@ -4229,8 +4229,9 @@
ctx.activityLexical ??= lexical;
const callee = unwrapTsExpr(call.callee);
if (callee?.type === 'Identifier') {
- const scope = lexical.nodeScopes.get(callee) ?? lexical.nodeScopes.get(call);
- const binding = scope === undefined ? null : lexical.resolveBinding(scope, callee.name);
+ const scope =
+ lexical.nodeScopes.get(callee) ?? lexical.nodeScopes.get(call) ?? lexical.rootScope;
+ const binding = lexical.resolveBinding(scope, callee.name);
const importedName = ctx.octaneImportLocals?.get(callee.name);
if (
importedName !== undefined &&
@@ -4242,21 +4243,19 @@
if (binding === null && AUTO_MEMO_SETUP_HOOK_NAMES.has(callee.name)) return callee.name;
return null;
}
- if (
- (callee?.type === 'MemberExpression' || callee?.type === 'OptionalMemberExpression') &&
- callee.object?.type === 'Identifier'
- ) {
- const property = callee.computed ? callee.property?.value : callee.property?.name;
+ if (callee?.type === 'MemberExpression' || callee?.type === 'OptionalMemberExpression') {
+ const object = unwrapTsExpr(callee.object);
+ if (object?.type !== 'Identifier') return null;
+ const prop = unwrapTsExpr(callee.property);
+ const property = callee.computed ? prop?.value : prop?.name;
if (
typeof property === 'string' &&
AUTO_MEMO_SETUP_HOOK_NAMES.has(property) &&
- ctx.octaneImportNamespaces?.has(callee.object.name)
+ ctx.octaneImportNamespaces?.has(object.name)
) {
const scope =
- lexical.nodeScopes.get(callee.object) ??
- lexical.nodeScopes.get(callee) ??
- lexical.rootScope;
- if (lexical.resolveBinding(scope, callee.object.name)?.scope === lexical.rootScope) {
+ lexical.nodeScopes.get(object) ?? lexical.nodeScopes.get(callee) ?? lexical.rootScope;
+ if (lexical.resolveBinding(scope, object.name)?.scope === lexical.rootScope) {
return property;
}
}
@@ -4380,11 +4379,9 @@
} else {
const callee = unwrapTsExpr(node.callee);
if (callee?.type === 'Identifier' && declarations.has(callee.name)) {
- const scope = lexical.nodeScopes.get(callee) ?? lexical.nodeScopes.get(node);
- if (
- scope !== undefined &&
- lexical.resolveBinding(scope, callee.name)?.scope === lexical.rootScope
- ) {
+ const scope =
+ lexical.nodeScopes.get(callee) ?? lexical.nodeScopes.get(node) ?? lexical.rootScope;
+ if (lexical.resolveBinding(scope, callee.name)?.scope === lexical.rootScope) {
outgoing.add(callee.name);
}
}
@@ -4440,8 +4437,8 @@
// the same name. The summary graph uses this same binding resolution for its
// transitive edges, so cycles reach a fixed point independent of source order.
const lexical = ctx.autoMemoHookLexical;
- const scope = lexical.nodeScopes.get(callee) ?? lexical.nodeScopes.get(call);
- const binding = scope === undefined ? null : lexical.resolveBinding(scope, name);
+ const scope = lexical.nodeScopes.get(callee) ?? lexical.nodeScopes.get(call) ?? lexical.rootScope;
+ const binding = lexical.resolveBinding(scope, name);
return binding?.scope === lexical.rootScope;
}You can send follow-ups to the cloud agent here.
|
Latest Bugbot feedback is addressed in a215fe2: missing lexical scope now fails closed to module-root setup classification at every hook checkpoint, and optional namespace recovery peels TypeScript wrappers on both receiver and property. Permanent production/dev regressions cover an optional same-module custom-hook chain, an aliased optional useContext call, and a TypeScript-wrapped namespace/computed-property call. The focused matrix remains 1,205/1,205 with all 13 performance guards passing. |
domgan-oai
left a comment
There was a problem hiding this comment.
Revalidated the current head a215fe2a7c93d213245de1444f1f147d574db157. The earlier reproduction cases are fixed, including cyclic/shadowed hook reachability and the direct constructor signed-zero case, but I still would not merge this head: two isolated cases show incomplete fixes, detailed inline.
- Optional computed namespace hook: when tested alone in a keyed row,
(Hooks as any)['useContext' as string]?.(Theme)still freezes a context update. The new permanent fixture groups this with a recognized direct hook, which keeps the entire row live and masks the failure. - Signed-zero input through a list: component guards now distinguish
0and-0, but an ordinary enclosing list cache still drops that change before the row or child component can run. No authored selection comparison is involved.
Verification
- 917/917 tests pass across the four existing focused compiler/runtime suites plus all five earlier review probe files, including server-to-dev/prod hydration.
- 20 additional isolated probes: 16 pass, 4 fail on this head. The failures are two namespace-key forms and two list-row forms. All four failing cases pass on exact pre-PR base
d5175ca; current compatibility orautoMemo:falsecontrols also pass. The full base probe run has one unrelated, pre-existing compatibility failure for an optional named-import alias, which is fixed on the current head and is not a new finding. - 13/13 applicable template-call-memo benchmark guards pass; measured operation counts, output sizes, and semantic traces match
8447074. That benchmark does not cover these two isolated failures or establish component-guard latency. - Current-head CI is green: 28 successful checks and one skipped optional check. The CI workflow reports
a215fe2as its head.
The remaining work is to handle the parser's optional CallExpression form and to preserve numeric projection dependencies through every enclosing cache, while keeping specialized selection semantics separate. Please retain independent regression cases so one safe sibling cannot mask another form.
Two P2 inline findings are included. This is a comment-only review; approval is withheld because these regressions remain. The PR also does not have the codex-approvable label.
|
Latest review feedback is addressed in 2bcc38a. Optional imported-hook recovery now covers both optional-call AST encodings, and whole-list projection guards use SameValue while preserving strict equality only for the certified keyed-selection operand. The isolated reproductions failed on the reviewed production head before the fix; permanent coverage includes namespace-only optional context rows, child and inline signed-zero list projections, mixed selection/non-selection comparator policy, and the existing selection-only no-reread case. Validation: 1,162 focused compiler/list/hydration tests, 26,223 full tests with an 8 GB Node heap (the first default-heap run exhausted its 4 GB coordinator limit without an assertion failure), full monorepo typecheck, repository-wide formatting, pnpm sync, 17 docs tests, and all 13 template-call-memo ratio guards pass. Benchmark counters are unchanged; Strong output moves from 4,408 to 4,447 minified bytes and 47,576 to 47,585 gzip bytes. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
|
Additional design context from the #846 discussion, reviewed against I think the central concern supports the compatibility/Strong split already described in the latest docs; it does not require reversing that direction. The useful follow-up is to make the boundaries more explicit:
I have not reproduced the discussion's specific This is additional contract/documentation/test feedback, not a new correctness revalidation of the latest fixes. |
|
Addressed the additional contract feedback in 6f6f5bb (with current
The new diagnostic reproduction failed before the compiler change, and a deliberately broken snapshot handoff failed both development and production integration cases before restoration. Current validation: 1,129 focused compiler/list/hydration/TanStack/docs tests pass; full monorepo typecheck, repository formatting, |
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: Const custom hooks become projections
- Extended autoMemoModuleFunctionDeclarations to collect VariableDeclaration statements with ArrowFunctionExpression/FunctionExpression initializers, so const/let-declared hooks are now tracked in the Strong setup-hook dependency graph and their calls correctly prevent caching.
Or push these changes by commenting:
@cursor push 9fa49630b2
Preview (9fa49630b2)
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
@@ -4280,6 +4280,16 @@
if (declaration?.type === 'FunctionDeclaration' && declaration.id?.type === 'Identifier') {
declarations.set(declaration.id.name, declaration);
}
+ if (declaration?.type === 'VariableDeclaration') {
+ for (const declarator of declaration.declarations) {
+ if (declarator.id?.type === 'Identifier') {
+ const init = unwrapTsExpr(declarator.init);
+ if (init?.type === 'ArrowFunctionExpression' || init?.type === 'FunctionExpression') {
+ declarations.set(declarator.id.name, init);
+ }
+ }
+ }
+ }
}
ctx.autoMemoModuleFunctionDeclarations = declarations;
return declarations;
diff --git a/packages/octane/tests/_fixtures/for-strong.tsrx b/packages/octane/tests/_fixtures/for-strong.tsrx
--- a/packages/octane/tests/_fixtures/for-strong.tsrx
+++ b/packages/octane/tests/_fixtures/for-strong.tsrx
@@ -264,6 +264,24 @@
</div>
}
+const useConstTheme = (context: typeof StrongTheme): string => useContext(context);
+
+export function StrongConstHookContextRows() @{
+ const [theme, setTheme] = useState('first');
+ const [items] = useState([{ id: 1 }, { id: 2 }]);
+ <div>
+ <button id="strong-const-hook-context-update" onClick={() => setTheme('second')}>
+ update
+ </button>
+ <StrongTheme.Provider value={theme}>
+ @for (const item of items.slice(); key item.id) {
+ const value = useConstTheme(StrongTheme);
+ <span class="strong-const-hook-context-row">{value as string}</span>
+ }
+ </StrongTheme.Provider>
+ </div>
+}
+
function useShadowedTheme(context: typeof StrongTheme): string {
return useContext(context);
}
diff --git a/packages/octane/tests/for.test.ts b/packages/octane/tests/for.test.ts
--- a/packages/octane/tests/for.test.ts
+++ b/packages/octane/tests/for.test.ts
@@ -48,6 +48,7 @@
CapturedSnapshotList,
StrongAliasedContextRows,
StrongCallableDependencies,
+ StrongConstHookContextRows,
StrongConstructedResultProp,
StrongCustomHookContext,
StrongCyclicContextReaders,
@@ -687,6 +688,20 @@
r.unmount();
});
+ it('tracks const-declared function-expression hooks as setup-bearing in keyed rows', () => {
+ const r = mount(StrongConstHookContextRows);
+ expect(r.findAll('.strong-const-hook-context-row').map((row) => row.textContent)).toEqual([
+ 'first',
+ 'first',
+ ]);
+ r.click('#strong-const-hook-context-update');
+ expect(r.findAll('.strong-const-hook-context-row').map((row) => row.textContent)).toEqual([
+ 'second',
+ 'second',
+ ]);
+ r.unmount();
+ });
+
it('uses SameValue semantics for newly cached constructor inputs', () => {
const Projector = class {
result: string;You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 7a8ab83. Configure here.
This reverts commit 7a8ab83.
This comment has been minimized.
This comment has been minimized.
|
Final-head follow-up: CI is green on The latest Bugbot finding was valid despite being auto-resolved. A Strong keyed-row reproduction using a module arrow binding that called a later function-expression binding and reached Final validation includes 1,102 focused compiler/list/hydration tests, full monorepo typecheck, repository formatting, docs tests, |


Summary
"use strong"as an author assertion that user-authored render operations are pure projections of immutable snapshots and witnessed inputs.use*-shaped ordinary calls can participate in production region memoization.This finishes the purity-contract follow-up to #862. Hidden ref contents, state getters, mutable globals, live stores, clocks/randomness, mutations, or hook state behind a stable user call now violate the Strong assertion instead of silently forcing compatibility behavior. Bounded diagnostics still reject violations they can prove.
Validation
pnpm syncpnpm format:checkpnpm typecheckpnpm typecheck:files ...node benchmarks/bench.mjs --ratios template-call-memo(13/13 applicable guards pass)Performance evidence
0calls.7calls per new or replaced row.18 × 7 = 126calls.3,584stable and126reorder calls in the fixed workload).Risk
Provenance
agent-authored)Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
High Risk
Strong production memoization now trusts author purity across all call shapes; code that hid live refs, getters, or stores behind stable calls can render stale output without falling back to compatibility behavior.
Overview
Strong mode is reframed as an author assertion that user-authored render work is a pure function of immutable snapshots and witnessed inputs (callable, receiver, and arguments), not a narrow fast path for static member calls.
The production memoizer stops using
use*naming, callback guards, and hook-alias graphs to block Strong regions. Instead it lexically distinguishes real hook setup (built-in import provenance, optional calls, same-module custom hooks, cycles, and reassignment conservatism) from ordinary calls—including hook-shaped helpers, computed/call-produced callees,new, tagged templates, and callbacks—so those shapes can memoize when inputs are unchanged. Compatibility mode stays conservative on member calls. Memo miss tests at component and list boundaries move toObject.is, with a carve-out so certified keyedselected === row.idkeeps strict equality.Diagnostics add
OCTANE_STRONG_RETAINED_ROW_MUTATIONfor writes from a keyed@forbody to outer bindings. Docs, plugin types, TanStack Table boundary guidance, and the template-call-memo benchmark (seven-shapeAssumedPureRowsfixture + ratio guards) document and lock the contract. Tests and fixtures are reshaped around the new semantics (including removal of cases that expected Strong to keep ref/context reads live behind stable calls).Reviewed by Cursor Bugbot for commit 563ce46. Bugbot is set up for automated code reviews on this repo. Configure here.