Skip to content

fix(compiler): see imported member reads through TypeScript wrappers - #2310

Merged
trueadm merged 1 commit into
mainfrom
fix/imported-member-ts-wrappers
Nov 2, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/imported-member-ts-wrappers

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

In production builds, an imported object's member read through a TypeScript wrapper could be missed by the live-import check. flags!.enabled, (flags as Flags).enabled and (flags satisfies Flags).enabled all slipped past it. A keyed @for row that reads one could then keep showing a stale branch after the member changed. The plain flags.enabled form was already handled.

Cursor Bugbot reported this on #1213 (#1213 (comment)), and the finding was never addressed. The code it points at is unchanged on main.

Why

containsImportedMemberRead in packages/octane/src/compiler/compile.js walks a member chain down to its base identifier, following object.object. It stopped at the first node that wasn't a member expression, so in flags!.enabled it reached the TSNonNullExpression and never saw flags.

Every gate that guards against live imports calls this function. Compiled on main with dev: false, this row is wrong in two ways:

import { flags } from './flags';
export function App(props) @{
	<ul>@for (const item of props.items; key item.id) {
		<li>@if (flags!.enabled) {<span class="x" />}</li>
	}</ul>
}
  • Row skip: the forBlock flags argument is 27, which sets the PURE bit. A surviving row with the same identity skips its body.
  • List cache: the whole list is wrapped in a compilerMemoRegion whose dependencies are [props.items, flags]. flags never changes identity, so re-rendering with the same items skips the list entirely.

With flags.enabled, the same component gets flags 26 and no memo region.

Changes

  • containsImportedMemberRead: unwraps each receiver with the existing unwrapValueExpression, which strips as, !, satisfies, <T>x, parentheses and optional chains, before it continues the walk.
  • Changeset: patch for octane.

I also checked the compiler's other member-chain walks. One walks JSX tag names, which can't contain these wrappers. The other, hydrationLayoutReadCapture, returns null for any shape it doesn't recognize. isDeferredRefRead keys on the .current property, so ref!.current is still caught.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files leaves all four changed files unchanged.
  • pnpm typecheck: not run. The change is plain JS in the compiler plus tests.
  • pnpm test: not run in full locally.
  • targeted tests:
    • for-item-purity.test.ts: the imported-member case becomes an it.each over the bare form and five wrapped forms: !, as, satisfies, as with ?., and a wrapper in the middle of the chain. Each must leave the PURE bit clear.
    • auto-memo.test.ts: a runtime case for each of !, as and satisfies. It mounts a dev: false build of a keyed list whose rows read flags from an injected ./flags module, then:
      • sets flags.enabled = true and re-renders with the same list, expecting two <b> elements;
      • sets it back to false and re-renders with a new array of the same rows, expecting zero.
    • Against main's compiler: the bare case passes and all eight new cases fail. The runtime failure is the stale DOM: zero <b> elements render where two are expected.
    • vitest run --project octane --project octane-prod packages/octane/tests/compiler packages/octane/tests/auto-memo.test.ts packages/octane/tests/for.test.ts: 5,260 passed and 6 failed.
      • The six were TypeScript-program tests that took 5 to 26 s while the machine's load average was about 19, in css-module-vite, strong-html, volar and web-typescript-output.
      • Rerun on their own, those four files pass: 99 of 99.
    • pnpm sync: generated nothing.

Risk / follow-ups

  • The fix only declines more. Compiled output changes only for components that read an imported member through one of these wrappers, and those now render live where they were wrongly cached. Code without such reads compiles exactly as before.
  • Compile-time cost is one wrapper check per member level.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


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


Note

Low Risk
Compiler-only change that disables over-aggressive memoization for a narrow pattern; behavior becomes more correct without touching auth, data, or runtime APIs.

Overview
Production keyed @for rows could stay memoized/skipped when an @if test read an imported object through a TypeScript wrapper (flags!.enabled, (flags as Flags).enabled, (flags satisfies Flags).enabled, etc.), even though the underlying member could change while the import binding’s identity stayed the same. Plain flags.enabled was already detected.

containsImportedMemberRead now peels those wrappers via unwrapValueExpression while walking each member chain’s receiver, so the same live-import gates apply and those rows/lists re-render when the member updates.

Compiler tests cover more wrapped read shapes in for-item-purity, and auto-memo adds dev: false runtime cases for !, as, and satisfies. Patch changeset for octane.

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

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]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 29, 2026
@jonkwheeler
jonkwheeler marked this pull request as ready for review October 29, 2026 20:55
@cloudflare-workers-and-pages

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 08f2608 Commit Preview URL

Branch Preview URL
Oct 29 2026, 08:56 PM

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No byte growth, no added work, and no timing changes beyond ±3%.

Compares 33b90dfd9, the merge commit's first parent with c57beaa24 on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. 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 3.050 2.925 −4.6% −12.5% … +3.6% ⚪ within noise
octane-tsrx replace 5.900 6.025 +0.0% −1.6% … +3.6% ⚪ within noise
octane-tsrx add 2.167 2.150 −0.0% −4.5% … ±0.0% ⚪ within noise
octane-tsrx update 0.081 0.083 +1.4% ±0.0% … +3.4% ⚪ within noise
octane-tsrx select 0.005 0.005 +0.3% −0.3% … +0.5% ⚪ within noise
octane-tsrx swap 0.015 0.015 −0.6% −1.1% … ±0.0% ⚪ within noise
octane-tsrx remove 0.012 0.012 −1.1% −2.1% … −0.0% ⚪ within noise
octane-tsrx runlots 19.042 20.083 −0.3% −5.3% … +6.5% ⚪ within noise
octane-tsrx select_lots 0.005 0.005 +0.0% −0.0% … +0.6% ⚪ within noise
octane-tsrx clear 39.592 38.550 −1.5% −2.7% … −0.1% ⚪ within noise
octane-jsx run 3.042 2.950 ±0.0% −3.3% … ±0.0% ⚪ within noise
octane-jsx replace 4.817 4.833 ±0.0% −1.9% … +1.0% ⚪ within noise
octane-jsx add 2.667 2.600 −1.3% −3.7% … ±0.0% ⚪ within noise
octane-jsx update 0.146 0.149 +0.3% −0.0% … +1.2% ⚪ within noise
octane-jsx select 0.072 0.072 +0.6% +0.3% … +1.3% ⚪ within noise
octane-jsx swap 0.110 0.110 +0.6% −0.0% … +0.6% ⚪ within noise
octane-jsx remove 0.099 0.101 +1.5% −0.3% … +3.7% ⚪ within noise
octane-jsx runlots 25.058 26.833 +2.6% −6.0% … +7.1% ⚪ within noise
octane-jsx select_lots 1.060 1.004 −2.6% −9.1% … +4.8% ⚪ within noise
octane-jsx clear 52.775 53.950 +9.2% −5.2% … +26.2% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 111 measured values.

Public-import reachability bundles (bytes)

No changes across 141 measured values.

@cloudflare-workers-and-pages

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 08f2608 Commit Preview URL

Branch Preview URL
Oct 29 2026, 08:56 PM

@trueadm
trueadm merged commit 6112c89 into main Nov 2, 2026
79 of 82 checks passed
@trueadm
trueadm deleted the fix/imported-member-ts-wrappers branch November 2, 2026 21:28
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.

2 participants