Repository navigation
feat(compiler): admit host-only conditional item bodies to forBlock PURE - #1213
Merged
Merged
Conversation
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: Imported member gate misses TS wrappers
- containsImportedMemberRead now unwraps TS/paren receivers so wrapped imported members fail closed and cannot take the identity-only skip.
Or push these changes by commenting:
@cursor push 6a22de103b
Preview (6a22de103b)
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
@@ -6504,7 +6504,8 @@
// A JSX member chain bottoms out at a JSXIdentifier, so the base test below
// never matches one. Do not reintroduce a JSX-awareness flag: it cannot change
-// the answer.
+// the answer. Unwrap TS/paren wrappers on the receiver so `mod!.flag` and
+// `(mod as T).flag` still count as live imported member reads.
function containsImportedMemberRead(root, importedNames) {
let found = false;
const seen = new WeakSet();
@@ -6517,9 +6518,9 @@
if (typeof n !== 'object' || seen.has(n)) return;
seen.add(n);
if (n.type === 'MemberExpression' || n.type === 'JSXMemberExpression') {
- let object = n;
+ let object = unwrapTsExpr(n.object);
while (object?.type === 'MemberExpression' || object?.type === 'JSXMemberExpression') {
- object = object.object;
+ object = unwrapTsExpr(object.object);
}
if (object?.type === 'Identifier' && importedNames.has(object.name)) {
found = true;
diff --git a/packages/octane/tests/compiler/for-item-purity.test.ts b/packages/octane/tests/compiler/for-item-purity.test.ts
--- a/packages/octane/tests/compiler/for-item-purity.test.ts
+++ b/packages/octane/tests/compiler/for-item-purity.test.ts
@@ -169,6 +169,45 @@
expect(flags[0]! & PURE).toBe(0);
});
+ it.each<[string, string, string]>([
+ ['a non-null assertion', "import { flags } from './flags';", 'flags!.enabled'],
+ [
+ 'a type assertion',
+ "import { flags } from './flags';",
+ '(flags as { enabled: boolean }).enabled',
+ ],
+ [
+ 'a satisfies assertion',
+ "import { flags } from './flags';",
+ '(flags satisfies { enabled: boolean }).enabled',
+ ],
+ [
+ 'a type assertion before a further member',
+ "import { flags } from './flags';",
+ '(flags as { nested: { enabled: boolean } }).nested.enabled',
+ ],
+ ['a namespace non-null assertion', "import * as flags from './flags';", 'flags!.enabled'],
+ ])('declines when the imported member read uses %s', (_name, prelude, test) => {
+ // TS wrappers must not hide a live import: the identity-only skip still
+ // cannot witness `flags.enabled` flipping while `flags` stays fixed.
+ const flags = appListFlags(
+ compile(
+ `
+ ${prelude}
+ export function App(props) @{
+ <ul>@for (const item of props.items; key item.id) {
+ <li>@if (${test}) {<span class="x" />}</li>
+ }</ul>
+ }
+ `,
+ 'App.tsrx',
+ { hmr: false, dev: false },
+ ).code,
+ );
+ expect(flags).toHaveLength(1);
+ expect(flags[0]! & PURE).toBe(0);
+ });
+
it.each<[string, string, string?]>([
[
'@try',You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 0c15b59. Configure here.
1 task done
jonkwheeler
marked this pull request as ready for review
September 21, 2026 13:54
6 of 7 tasks
Contributor
Author
This was referenced Sep 21, 2026
5 of 6 tasks
domgan-oai
pushed a commit
that referenced
this pull request
Sep 23, 2026
…bal state (#1265) * fix(compiler): keep keyed @for rows live when they read module or global state forBlock PURE and DEP-PURE skip a survivor row on item identity plus the deps tuple. A module `let`/`var`, a reassigned module function, or a mutable global (`location`, `window`, `globalThis.x`) can change with neither moving, so such rows stayed stale. #1213 extended the gap to rows whose only control flow is a host-only @if (e.g. `@if (location.pathname === item.href)` never moved the active nav row). Rows whose render output reads one of those names now fail closed, as the item-memo, whole-list, and component autoMemo proofs already do. Module consts, unreassigned functions, imports, standard ECMAScript globals, and reads confined to inline onXxx handlers keep the fast path. Compiled output across all 3,047 repo .tsrx modules and the codegen-size corpus is unchanged apart from two test fixtures. Skip-probe tests that observed a survivor skip through a mutated module `let` now use a counting getter on the item instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): classify ambient globals by top-level module bindings isUnwitnessedAmbientRead treated any name bound anywhere in the module as non-global, so an unrelated parameter or local named `location` or `window` hid the real global a keyed row reads, keeping PURE/DEP-PURE. Globals are now names outside the top-level module declarations (imports, variables, functions, classes, enums) and outside the enclosing local chain the caller already checks; a missed enclosing binding fails closed. Destructured @for header fields are excluded explicitly, and TS enum reads no longer lose the fast path. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): analyze destructured @for header defaults as row reads A destructured header's defaults and computed keys run in the item helper's synthesized prologue, but purity analysis only walked the authored body. `@for (const { label = mode } of …)` with a module `let` or global stayed PURE, and a default reading a component local (`label = fallback`) was also PURE despite the env tuple capturing it, so survivors kept a stale default. The prologue is now analyzed with the body for free names and render calls, which also binds header fields in scope and replaces the explicit header-binding exclusion. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(compiler): pin the whole-list cache off for destructured header reads The whole-list forBlock cache walks the authored body, where destructured header fields read as unclassified free names, so any destructured header already fails its proof closed and a default or computed key cannot feed a stale list skip. Pin that for module-let and global defaults and a module-let computed key, with a plain-header control that does cache. A list proof that bound the fields without walking their defaults turns these red. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Merged
2 of 5 tasks
trueadm
pushed a commit
that referenced
this pull request
Nov 2, 2026
…2310) containsImportedMemberRead walked a member chain's receivers with `object.object` and stopped at the first node that was not a member expression. A receiver wrapped in `!`, `as`, or `satisfies` ended the walk before the imported identifier, so a read like `flags!.enabled` looked free of live imports. In production builds a keyed @for row reading one could take the identity-only survivor skip, and the whole list could be cached on `[props.items, flags]`, so the row kept a stale @if branch after the member changed. The walk now unwraps each receiver with unwrapValueExpression. Reported by Cursor Bugbot on #1213: #1213 (comment) Co-authored-by: Claude Opus 5.5 <[email protected]>
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
@foritem-body shape check (hasOnlyHostConditionalItemBodies) so a body whose only nested structure is host-only conditional content — an@ifover host output, including a narrowly proven nested keyed@for— is admitted to theforBlockPURE fast path.functionBodyContainsComponentso the admission fails closed: a component tag hidden behind a function boundary (e.g. a memoizable call'st => <Tag />callback argument) still disqualifies the body, since the shape walk deliberately skips function internals.containsAutoMemoUnsafeStructurerejects render-time hazards like an assignment in the@iftest, andcontainsImportedMemberReadrejects live imported member reads (@if (mod.flag)) whose value can mutate while the import's identity stays fixed.Why
forBlockPURE bit letsupdateSurvivorskip a surviving row's body entirely when the item identity is unchanged. Until now any nested component-shaped structure — including a plain host-only@if, which the shape classifier counts ashasNestedComp— disqualified the body.Changes
packages/octane/src/compiler/compile.js:hasOnlyHostConditionalItemBodiesconsultsfunctionBodyContainsComponentat function boundaries; newfunctionBodyContainsComponenthelper;makeForCallcomputeshostConditionalPure(hasNestedComp && hasOnlyHostConditionalItemBodies && !containsAutoMemoUnsafeStructure && !containsImportedMemberRead) and folds it into thehostPureadmission.packages/octane/tests/compiler/for-item-purity.test.ts(new): pins the emittedforBlockflags bit — admission for host-only@ifand a proven nested keyed@for; fail-closed cases for component arms, function-boundary-hidden components, parent captures, assignment-in-test, imported member reads,@try,@switch, portals, and index-binding/keyless nested@for.packages/octane/tests/for.test.ts+packages/octane/tests/_fixtures/for.tsrx:PureConditionalListend-to-end coverage — identical-identity survivors skip re-reading a mutated module binding on sibling change and on keyed reorder while DOM moves correctly.Validation
pnpm format:files:checkon touched paths — clean.pnpm typecheck:fileson touched paths — clean.vitest run packages/octane/tests/compiler/for-item-purity.test.ts packages/octane/tests/for.test.ts— 196 tests pass across theoctaneandoctane-prodprojects (compiler test runs underoctaneonly, per config).pnpm syncleaves the tree clean (no generated output).pnpm format:check,pnpm typecheck,pnpm test— deferred to CI per repo convention.main@8a4a2e087(20 iters, same harness; <1 = faster) — drag_nodes 10.1→4.3 ms (0.42x), label_churn 2.5→1.5 (0.59x), style_spread_pulse 4.9→3.5 (0.72x), topology_churn 2.7→2.4 (0.89x); mount/tick/pan flat. vs react fixture: 1.02x geomean (select_toggle, style_spread_pulse remain write-path ops owned by the changed-commit-write-path child)run-minimal.mjscaptured all listed scenario sizes before stopping at the pre-existingbinding-aria-esbuildfailure (known unrelated esbuild issue flagged on perf(runtime): beat React 19 + Compiler across the timing benchmark portfolio #1188).Risk / follow-ups
@foradmission is narrow — keyed, no index binding — because the identity skip has no index witness; index-bound and keyless nested loops stay out.Part of #1202. Split from #1188.
Provenance
agent-authored)Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes compiler proofs for keyed-list survivor skipping; mis-admission could leave stale DOM, though the design fails closed and is heavily tested.
Overview
Extends keyed
@forPURE admission so item bodies whose only extra structure is host-only@ifcontent (optional spans, flags, etc.) can skip re-render when the item identity is unchanged—previously any nested “component-shaped” control flow blocked the fast path.The compiler now treats
hostConditionalPureas an alternate to a flat host body:hasOnlyHostConditionalItemBodiesplus existing safety checks (containsAutoMemoUnsafeStructure,containsImportedMemberRead), andfunctionBodyContainsComponentso components hidden in callback arguments (e.g.t => <Tag />) still fail closed. Parent captures, component arms, live imports, and broader control flow stay on the ordinary survivor path.New
for-item-puritytests assert the emittedforBlockflags bit;PureConditionalListfixture and runtime tests confirm unchanged-identity rows skip body work on sibling updates and keyed reorders while DOM moves correctly.Reviewed by Cursor Bugbot for commit 0c15b59. Bugbot is set up for automated code reviews on this repo. Configure here.