Skip to content

fix: respect template bindings in effect analysis - #1671

Merged
trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/strong-template-shadowing
Oct 3, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/strong-template-shadowing

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Resolve template loop rows and catch reset parameters in their lexical scopes during hook dependency and Strong effect analysis.

Why

A template binding can shadow a callback or constant in an outer scope. Resolving the outer binding instead can accept or reject the wrong Strong effect and omit a changing row value from inferred effect dependencies. This addresses the shadowed callback alias review on #1669, including transitive aliases.

Changes

  • Reuse the existing lexical binding graph for loop headers, row bodies, empty arms, and catch reset parameters.
  • Identify callback-ref use by binding identity instead of name-based template ancestry checks.
  • Cover shadowed and unshadowed aliases, closer JavaScript bindings, callback reuse, loop header forms, and effect behavior when keyed rows change.

Validation

  • Scoped formatting, changeset validation, pnpm sync, and tsc -p packages/octane/tsconfig.json.
  • 3,771 compiler tests across 77 files with source-location assertions enabled.
  • 48 hook-dependency behavior tests each under development and production compilation, including Strong and compatibility keyed-row regressions. The new behavior tests failed against the base as expected.
  • Additional template-root and Volar checks: 39 passed; one StyleX type-check case could not resolve its workspace dependency in the partial installation.
  • Full pnpm test and workspace pnpm typecheck: a complete workspace install was blocked by a registry rejection for @tanstack/[email protected].
  • Paired compiler-only timing with alternating baseline and candidate runs: observed ranges overlapped. The unaffected control fixtures produced identical compiled output and diagnostics; this is not a runtime performance claim.

Risk / follow-ups

The compiler now tracks row-local values in inferred dependencies when an outer name is shadowed. Both Strong and compatibility-mode runtime regressions exercise that change; full browser hydration coverage was not run locally. The current-head benchmark job fails on 18 size and 39 reachability values already over budget on the base; all 45 size and 105 reachability measurements are unchanged. #1638 addresses the existing baseline budgets. The paired timing report flags select_lots at 0.005 to 0.006 ms (+7.2%), while all 64 work counters are unchanged; timing is informational and did not cause this failure.

Provenance

  • An agent produced this diff (agent-authored)

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


Note

Medium Risk
Changes compiler hook dependency inference and Strong static analysis for all TSRX template loops and catch handlers; broad test coverage but behavior shifts when outer names are shadowed.

Overview
Fixes incorrect hook dependency inference and Strong effect/ref proofs when TSRX @for row names or @catch reset parameters shadow outer bindings.

The compiler’s scope walk now treats JSXForExpression and catch resetParam like ordinary lexical scopes in all analysis modes—not only the bindings-only pass— including bare row headers, row index bindings, and @empty arms. Inferred useEffect deps therefore track the row-local item where appropriate while @empty still depends on the outer binding.

Strong ref/callback attachment no longer uses name-and-ancestor templateShadowed heuristics; it relies on the same binding graph, so row-shadowed abort helpers and ref aliases are classified correctly without false accepts/rejects.

New compiler and runtime behavior tests cover nested destructured rows, multiple loop header forms, catch reset bindings, and Strong fetch/ref edge cases.

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

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 3, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review October 3, 2026 15:39
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • ❌ bundle-size: 18 value(s) exceed their committed budget
  • ❌ bundle-reachability: 39 value(s) exceed their committed budget
  • 🟡 js-framework: 1 timed operation(s) slower beyond ±3%

Compares 39cf3827f, the merge commit's first parent with b8bbc33d0 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

target operation base ms head ms head/base 95% CI
octane-tsrx select_lots 0.005 0.006 +7.2% +6.5% … +7.8% 🟡 slower
All 20 timed operations (19 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.708 2.733 ±0.0% −3.3% … +0.0% ⚪ within noise
octane-tsrx replace 5.600 5.533 −0.9% −3.5% … +1.7% ⚪ within noise
octane-tsrx add 2.442 2.442 ±0.0% −2.0% … ±0.0% ⚪ within noise
octane-tsrx update 0.125 0.124 −0.8% −2.4% … ±0.0% ⚪ within noise
octane-tsrx select 0.005 0.005 −0.6% −1.3% … ±0.0% ⚪ within noise
octane-tsrx swap 0.035 0.034 −1.4% −2.1% … −0.4% ⚪ within noise
octane-tsrx remove 0.018 0.018 +0.0% −1.8% … +2.5% ⚪ within noise
octane-tsrx runlots 24.150 24.375 +2.5% −1.5% … +4.6% ⚪ within noise
octane-tsrx select_lots 0.005 0.006 +7.2% +6.5% … +7.8% 🟡 slower
octane-tsrx clear 42.475 42.417 −0.0% −1.6% … +2.8% ⚪ within noise
octane-jsx run 3.408 3.592 ±0.0% −0.0% … +2.8% ⚪ within noise
octane-jsx replace 7.025 7.117 +1.5% −2.2% … +4.3% ⚪ within noise
octane-jsx add 3.050 3.117 +1.2% ±0.0% … +3.2% ⚪ within noise
octane-jsx update 0.254 0.257 +0.3% −1.4% … +2.0% ⚪ within noise
octane-jsx select 0.134 0.132 −0.0% −1.0% … +0.8% ⚪ within noise
octane-jsx swap 0.235 0.236 −0.3% −1.1% … +0.8% ⚪ within noise
octane-jsx remove 0.174 0.175 +1.3% −0.7% … +1.9% ⚪ within noise
octane-jsx runlots 30.175 30.167 −0.2% −3.6% … +3.8% ⚪ within noise
octane-jsx select_lots 1.432 1.490 +1.7% −0.3% … +2.9% ⚪ within noise
octane-jsx clear 43.392 43.858 ±0.0% −0.7% … +1.0% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

❌ 18 value(s) exceed their committed budget. Reduce the growth, or raise the budget in a separate pull request that names the bytes and the reason (CONTRIBUTING.md, "Size budgets").

target metric head budget over
octane-tsrx todo_fw_raw 135,618 134,272 +1,346
octane-tsrx todo_fw_gzip 43,964 43,712 +252
octane-tsrx todo_fw_brotli 38,698 38,464 +234
octane-tsrx todo_js_raw 140,728 139,616 +1,112
octane-tsrx todo_js_gzip 46,441 46,304 +137
octane-tsrx todo_js_brotli 40,816 40,704 +112
octane-tsrx chat_fw_raw 133,195 131,744 +1,451
octane-tsrx chat_fw_gzip 43,362 43,136 +226
octane-tsrx chat_fw_brotli 38,058 37,888 +170
octane-tsrx chat_js_raw 139,848 138,656 +1,192
octane-tsrx chat_js_gzip 46,341 46,240 +101
octane-tsrx chat_js_brotli 40,693 40,640 +53
octane-jsx fw_raw 218,605 216,064 +2,541
octane-jsx fw_gzip 69,521 68,800 +721
octane-jsx fw_brotli 60,223 59,584 +639
octane-jsx js_raw 227,064 224,800 +2,264
octane-jsx js_gzip 72,457 71,872 +585
octane-jsx js_brotli 62,728 62,176 +552

No changes across 45 measured values.

Public-import reachability bundles (bytes)

❌ 39 value(s) exceed their committed budget. Reduce the growth, or raise the budget in a separate pull request that names the bytes and the reason (CONTRIBUTING.md, "Size budgets").

target metric head budget over
capture-only raw 11,406 10,688 +718
capture-only gzip 4,388 4,000 +388
capture-only brotli 3,924 3,616 +308
root-static-specialized raw 76,977 76,352 +625
root-static-specialized gzip 25,537 25,504 +33
root-static-specialized brotli 22,763 22,752 +11
root-static raw 203,303 201,472 +1,831
root-static gzip 64,638 64,032 +606
root-static brotli 56,047 55,488 +559
hydrate-root raw 173,265 148,352 +24,913
hydrate-root gzip 54,916 48,096 +6,820
hydrate-root brotli 47,933 42,048 +5,885
deferred-hydration raw 236,613 209,504 +27,109
deferred-hydration gzip 74,795 67,264 +7,531
deferred-hydration brotli 64,567 58,112 +6,455
suspense-transition raw 165,071 162,944 +2,127
suspense-transition gzip 52,970 52,672 +298
suspense-transition brotli 46,374 46,016 +358
server-render raw 65,075 54,048 +11,027
server-render gzip 22,431 18,912 +3,519
server-render brotli 20,248 17,056 +3,192
binding-base-ui-vite raw 213,534 211,968 +1,566
binding-base-ui-vite gzip 68,212 67,680 +532
binding-base-ui-vite brotli 59,093 58,720 +373
binding-base-ui-esbuild raw 211,479 209,984 +1,495
binding-base-ui-esbuild gzip 68,170 67,680 +490
binding-base-ui-esbuild brotli 59,089 58,624 +465
binding-radix-vite raw 215,466 213,952 +1,514
binding-radix-vite gzip 68,752 68,288 +464
binding-radix-vite brotli 59,634 59,200 +434
binding-radix-esbuild raw 213,370 211,904 +1,466
binding-radix-esbuild gzip 68,744 68,288 +456
binding-radix-esbuild brotli 59,653 59,104 +549
binding-apollo-client-vite raw 358,526 354,304 +4,222
binding-apollo-client-vite gzip 112,298 110,592 +1,706
binding-apollo-client-vite brotli 98,049 97,280 +769
binding-apollo-client-esbuild raw 361,463 357,376 +4,087
binding-apollo-client-esbuild gzip 114,493 113,664 +829
binding-apollo-client-esbuild brotli 99,731 99,328 +403

No changes across 105 measured values.

@trueadm
trueadm merged commit 949894d into octanejs:main Oct 3, 2026
53 of 54 checks passed
leonidaz added a commit that referenced this pull request Oct 4, 2026
main's #1671 tests shadow a component binding with a `var` row
(`@for (var item of …)`). Under @tsrx/core 0.5 and @tsrx/oxc 0.18 a `var`
row belongs to the component function, as in JavaScript, so both parsers
report it as a redeclaration instead of a row-scoped shadow. The shadowing
case now pins that error in client and server modes, and the two Strong
effect cases that relied on it are dropped; their `const`, `let`, bare and
destructured row variants keep the shadowing coverage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 7, 2026
#1399)

* fix: update the TSRX toolchain to @tsrx/core 0.5

Update @tsrx/core, @tsrx/prettier-plugin and @tsrx/typescript-plugin to
0.5.0, @tsrx/react to 0.4.0, @tsrx/solid to 0.3.0, the Vite plugins,
@tsrx/oxc to 0.17.0 and Prettier to 3.9.9.

@tsrx/core 0.5 gives template markup TSX's exact tree: layout whitespace
between children is its own JSXText and each @case arm is one
BlockStatement. Octane now adopts that tree once at the parse boundary,
copy-on-write, so compiled output is unchanged; the editor parse keeps the
line breaks around a comment child so a template @ts-expect-error stays on
the line before the child it is about.

Also fix enum member initializers being invisible to the client-only
server check and to universal renderer validation (TSEnumBody), let
plain-module memo printing accept TSEnumBody, move tests to the new
diagnostic codes, and fix binding types the new editor output surfaced.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style: format with the @tsrx/prettier-plugin 0.5 formatter

Reformat every .tsrx and .mdx file with @tsrx/prettier-plugin 0.5.0, whose
new architecture prints ordinary JavaScript, TypeScript and JSX with
Prettier itself. Compiled output is unchanged apart from position-derived
ids, scoped-style hashes of reindented CSS, and merged `{' '}` text.

Refresh what the reformat invalidates: the source-ledger hashes of copied
binding files, the Streamdown TSRX declarations, and the evals dataset
manifests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style: format fixtures merged from main with the 0.5 formatter

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: re-pin reformatted evidence and fix CI after the TSRX 0.5 update

- Re-pin the integrity hashes that parity, closure, and adapted-evidence
  manifests record for fixtures the formatter rewrote. The parity lanes
  re-run the evidence against the new bytes.
- Update the alien-signals mutation test to the reformatted fixture text.
- Give three's Canvas wrapper a spread type without `ref`, which the strict
  packed-source consumer reported under the new editor output.
- Pre-declare `octane > entities` for the website's dev optimizer: the
  in-browser compiler reaches it only at request time, and the late
  optimize pass now rehashes the playground's chunks and reloads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* chore(shadcn): rebuild the registry from the reformatted sources

The registry embeds each component's source, so the 0.5 reformat left it
stale for registry.test.ts's build --check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: update to @tsrx/core 0.5.1 and keep `@{ … }` directives

@tsrx/core 0.5.1 (tsrx-org/tsrx#967, released in #969) reads the strings
that start a `@{ … }` function body as its directive prologue, so the
formatter no longer wraps `'use dom bindings'` in parentheses. Restore the
authored directives the 0.5.0 formatter had parenthesized.

Declare Octane's TSRX compiler for @octanejs/colorful: without it the
TypeScript plugin type-checked the package through the React target's
virtual code, whose composed refs its sources don't use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Merge origin/main into chore/tsrx-0.5

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: address the TSRX 0.5 upgrade issues

- Decode a JSX attribute string once, from its text as written (#1327).
  `@tsrx/core` gives `value` already decoded, so the browser compiler and
  Node's core fallback decoded `&amp;lt;` twice.
- Read a type parameter's name as the Identifier both parsers now give
  (#1354).
- Give the client-only check's enum walk its members' scope, so a later
  initializer reading a member is not a use of a same-named import.
- Test that the Node and browser parsers compile the same sources to the
  same output: attribute and text references, comments between template
  texts, `//` that touches text, `>` in text, layout text, an empty `@case`
  arm, type parameters, and the dynamic-tag rule (#1328, #1329, #1330,
  #1338, #1353, #1355).
- Pin the nested-`var` redeclaration in both compile modes and the editor,
  and keep a var of its own name covering hoisting (#1330).
- Count a comment child out of `Children.count`, as React does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(website): pre-declare @octanejs/three's zustand/vanilla for dev

The home page's 3D section reaches @octanejs/three's raw store source
through a deferred chunk, so Vite discovered zustand/vanilla mid-session.
With the new TSRX packages in the dev bundle, that late optimize pass
changes chunk hashes and reloads every open page, which reloaded the
playground under the website e2e suite's concurrent tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: update to @tsrx/core 0.5.2 and read JSX text as written

@tsrx/core 0.5.2 (tsrx-org/tsrx#972, released in #973) gives a JSXText's
`value` decoded, and `raw` as written. Octane decoded `value` again, so
the browser compiler and Node's core fallback rendered `&amp;lt;` as `<`.

- normalizeAuthoredJsxLiterals cleans up and decodes text from `raw`, once,
  as it now does for attribute strings; both parsers leave comments out of
  `raw`, so the result doesn't depend on which one parsed (#1330).
- Layout and emptiness checks on parser trees (hydrate and renderer
  boundaries, Valdi, DOM bindings) test JSX whitespace in `raw` instead of
  `\s` or `.trim()` on `value`, where a decoded `&nbsp;` looks like space.
- The parser-parity test covers a double-encoded reference in text, text
  that is only `&nbsp;`, an encoded line break at the end of a line, and
  CRLF line breaks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(compiler): take decoded JSX text and attributes from the parser

@tsrx/oxc 0.18.0 decodes character references in JSX text and attribute
values as @tsrx/core 0.5.2 does, so both parsers give `value` decoded and
`raw` as written. normalizeAuthoredJsxLiterals no longer decodes: it applies
JSX's whitespace rule to the parser's value, as Babel does, and prints an
attribute from its value when that differs from the string as written.

Octane drops its `entities` dependency, the website's pre-bundle entry for
it, and the benchmark scripts' evidence lookups of it. Decoding now follows
JSX, as in React: a later HTML name such as `&check;` stays text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(markdown): restore main's crosswalk integrity pin lost in the merge

#1448 changed packages/markdown/audit/adapted-case-crosswalk.json and
re-pinned it in react-parity.json. The merge took this branch's side of
that manifest for its lockfile hash and dropped the new pin, so the React
parity audit rejected the manifest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* chore: update the TSRX toolchain to @tsrx/core 0.5.4

Adopt the TSRX releases from tsrx-org/tsrx#1014: @tsrx/core 0.5.4,
@tsrx/prettier-plugin and @tsrx/typescript-plugin 0.6.2, @tsrx/react 0.4.4,
@tsrx/solid 0.3.4, @tsrx/vite-plugin-react 0.0.119, @tsrx/vite-plugin-solid
0.0.116, and @tsrx/content-mapper 0.1.2, which moves into the default catalog.

octane-tsc's TypeScript moves to a new `native` catalog. It stays on
7.1.0-dev.20260921.1: later nightlies, through 7.1.0-dev.20261004.1, report
false TS7031 errors for a `{ ... } = {}` parameter default
(microsoft/TypeScript#64431) in puck, redux-toolkit and an rspeedy test.

Neither @tsrx/core patch is fixed upstream in 0.5.4, so the patch moves to
the new version unchanged. Every tracked .tsrx file compiles to identical
client, server and Volar output on 0.5.2 and 0.5.4, the formatter leaves the
repository unchanged, and the parity pins record the new lockfile hash.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test: pin the var row redeclaration from main's template binding tests

main's #1671 tests shadow a component binding with a `var` row
(`@for (var item of …)`). Under @tsrx/core 0.5 and @tsrx/oxc 0.18 a `var`
row belongs to the component function, as in JavaScript, so both parsers
report it as a redeclaration instead of a row-scoped shadow. The shadowing
case now pins that error in client and server modes, and the two Strong
effect cases that relied on it are dropped; their `const`, `let`, bare and
destructured row variants keep the shadowing coverage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci(bench): raise two brotli budgets for the TSRX 0.5 reformat

PR #1399 reformats Octane's .tsrx sources with the new TSRX formatter. The compiled code is byte-identical in size, but position-derived binding ids change, and brotli compresses binding-apollo-client-vite 151 bytes and suspense-transition 64 bytes worse. That puts them 9 and 2 bytes over budget. Raise each to the #1399 measurement plus the usual 256 bytes of brotli headroom.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* chore: update the TSRX toolchain to @tsrx/core 0.5.5 and drop its patch

Adopt the TSRX releases from tsrx-org/tsrx#1042: @tsrx/core 0.5.5,
@tsrx/prettier-plugin and @tsrx/typescript-plugin 0.6.3, @tsrx/react 0.4.5,
@tsrx/solid 0.3.5, @tsrx/vite-plugin-react 0.0.120 and
@tsrx/vite-plugin-solid 0.0.117.

@tsrx/core 0.5.5 ships both fixes the repository patched in: a parenthesized
`<style>` block resolves as an `apply` target in the editor parse
(tsrx-org/tsrx#1045), and the printer keeps source-phase imports
(tsrx-org/tsrx#1048). The patch is removed; volar.test.ts and
module-import-phases.test.ts, which guarded it, pass without it, and every
tracked .tsrx file compiles to the same client, server and Volar output as on
the patched 0.5.4.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: patch @tsrx/core 0.5.5's quadratic comment attachment

The website integration suite failed: the production build ran past its
420 s limit in Nitro's environment build. Nitro re-bundles each SSR chunk
through Octane's Vite plugin, and its preflight parses each one with
@tsrx/core. For every node, core 0.5's comment attachment copied all the
code up to the next comment through a line-break replace, so the 5 MB
docs chunk, which has few comments, took minutes. Core 0.4 tested a regex
in place and was only just fast enough.

The blank-line result is read only when that text is whitespace, so test
`onlyWhitespace` first; the result is unchanged. Locally the Nitro phase
drops from 8 m 9 s to 5.5 s, and the whole website build from 543 s to
41 s. A compiler-vite-options case transforms a 650 kB generated server
chunk in 1.4 s, against 12.6 s unpatched.

Also drop the @pnpm/exe lockfile entries that installing through
`npx [email protected]` added in the previous merge, and regenerate the parity
manifests' and evals corpus' lockfile hashes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: pin the @tsrx/oxc parser peer at 0.18.0 in Lynx lanes and docs

Main's #1835 made @tsrx/oxc an optional peer of octane and pinned
0.16.0, main's catalog version, in both Lynx toolchain lanes (35eb3c7)
and in every install instruction. This branch's catalog is on 0.18.0, so
octane declares that peer, and installing the lanes failed with an unmet
@tsrx/oxc peer (installed 0.16.0, wanted 0.18.0) in Lynx compatibility,
the packed rspeedy consumer test, and validate publishable packages.

Pin 0.18.0 in the lanes and their README row, and in the READMEs, docs,
website pages and the two unreleased changesets that tell projects which
version to install.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Leonidas <[email protected]>
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