Skip to content

fix(compiler): allow ref access and state getters in Strong effect setup - #1849

Merged
trueadm merged 1 commit into
mainfrom
fix/strong-effect-ref-access
Oct 7, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/strong-effect-ref-access

Conversation

@trueadm

@trueadm trueadm commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes a Strong mode bug: OCTANE_STRONG_EFFECT_HIDDEN_DEPENDENCY rejected effect setup that read or wrote a ref's current, or called a state getter. Neither is an effect dependency. A ref holds a value the effect uses without re-running, and a getter reads the latest state without subscribing; the inferred dependency arrays already exclude both. Ordinary React patterns failed to compile in useEffect, useLayoutEffect, and useInsertionEffect setup as a result:

const last = useRef(0);
useEffect(() => { log(last.current); last.current = count; }); // previous value
const runs = useRef(0);
useEffect(() => { runs.current++; });                           // ref counter
const items = useRef(new Map());
useEffect(() => { items.current.get(id)?.focus(); });           // callback-ref map
useEffect(() => { log(getCount()); });                          // state getter

Changes

  • strong-mode.js: removed the value-ref reports (member reads, destructured current, and compound updates) and the getter-call report in effect setup.
  • strong-effects.js: removed the value-ref classification (escaped, isValueRef, the use classifier, and the dependency-list table) that fed only this rule. Host-element classification stays, including callback-ref attachment validity, because the resource-leak check uses it to require cleanup for listeners on attached elements.
  • The diagnostic still reports a reassigned module let/var read in effect setup. Render-time ref reads and writes and render-time getter calls (OCTANE_STRONG_RENDER_REF_READ, _REF_WRITE, _STATE_GETTER_CALL) are unchanged.
  • Emitted code is unchanged; this only affects diagnostics.
  • Catalog entry, docs/strong-compiler-checks.md, docs/tsrx-basics.md, the MCP react-divergences skill, and the Strong guide are updated; the website reference, llms.txt, MCP catalog, and CLI data are regenerated by pnpm sync.
  • Patch changeset for octane and @octanejs/mcp-server. main already carries the 0.11.0 bump, so this releases as 0.11.1.

Tests

  • Value-ref and getter cases in effect setup moved from rejected to accepted, including TSX components, plain hook modules, custom-hook getters, and useLazyRef stores. They failed before the fix.
  • The callback-ref attachment cases, which guarded value-ref classification, now assert host-element classification through the leak rule. Dropping the invalid-attachment guard turns 13 of them red.
  • The TSX/hook enforcement test and the editor-integration test now use a reassigned module variable for the remaining diagnostic.
  • Removed a workaround in strong-hook-policy.test.ts that attached a ref to a <div> only to get past the old rule.

Validation

  • pnpm format:files:check on changed files (not the repo-wide pnpm format:check)
  • pnpm typecheck:files on the changed compiler and test files (not the full pnpm typecheck)
  • pnpm test (not run locally; left to CI)
  • targeted tests: strong-effects, lazy-ref-strong, strong-hook-policy, strong-diagnostics-catalog, strong-mode (1,633 passed, --project octane)
  • pnpm sync, pnpm strong:diagnostics:check

Risk / follow-ups

  • Bindings or apps that worked around the old rule, for example by routing a ref read through useEffectEvent or attaching a ref only to make it readable, still compile; they were not swept.

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. Autofix is disabled.


Note

Medium Risk
Narrows a core Strong diagnostic and ref classification used by resource-leak proofs; behavior change is intentional but could affect teams that relied on the old hidden-dependency errors or workarounds.

Overview
Strong mode no longer treats ref current access or state getter calls in effect setup as hidden dependencies, aligning with React: those reads are intentional non-reactive escapes and are not inferred effect dependencies.

OCTANE_STRONG_EFFECT_HIDDEN_DEPENDENCY now applies only to reassigned module let/var reads in synchronous useEffect / useLayoutEffect / useInsertionEffect setup. Compiler changes drop the old “value ref” escape analysis (isValueRef, escaped, getter/ref reports in strong-mode.js) while keeping host-ref attachment tracking for OCTANE_STRONG_EFFECT_RESOURCE_LEAK (callback-ref attachment cases now assert leak behavior instead of hidden-dependency).

Emitted code is unchanged—diagnostics and docs/catalogs (strong-diagnostics, MCP, CLI data, website) are updated accordingly; tests flip previously rejected patterns (previous-value refs, ref counters, getCount(), useLazyRef stores) to accepted.

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

Strong mode reported OCTANE_STRONG_EFFECT_HIDDEN_DEPENDENCY when effect
setup read a ref's `current` (unless the ref was attached or passed
somewhere) or called a state getter. Neither is an effect dependency: a
ref holds a value the effect uses without re-running, and a getter reads
the latest state without subscribing. Previous-value refs, ref counters,
callback-ref element maps, useLazyRef stores, and getter calls therefore
failed to compile in useEffect, useLayoutEffect, and useInsertionEffect.

Both report paths are removed. The value-ref classification that fed
only this rule goes with them; host-element classification, which the
resource-leak check uses, stays. The diagnostic still reports a
reassigned module variable read in effect setup, and render-time ref
access and getter calls stay errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 7, 2026 15:21
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 1 timed operation(s) slower beyond ±3%

Compares aaac26ce4, the merge commit's first parent with 792c496be 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-jsx clear 72.967 71.608 +7.9% +3.3% … +13.8% 🟡 slower
All 20 timed operations (19 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.417 2.333 −0.0% −4.0% … ±0.0% ⚪ within noise
octane-tsrx replace 5.442 5.192 −1.8% −3.0% … ±0.0% ⚪ within noise
octane-tsrx add 2.242 2.350 ±0.0% −3.7% … +3.3% ⚪ within noise
octane-tsrx update 0.119 0.122 +0.4% −0.9% … +2.5% ⚪ within noise
octane-tsrx select 0.005 0.005 +0.8% +0.5% … +1.5% ⚪ within noise
octane-tsrx swap 0.028 0.027 −1.7% −2.0% … −1.1% ⚪ within noise
octane-tsrx remove 0.014 0.013 −0.5% −3.3% … +0.5% ⚪ within noise
octane-tsrx runlots 22.433 22.633 −0.0% −1.8% … +2.7% ⚪ within noise
octane-tsrx select_lots 0.005 0.006 +0.6% ±0.0% … +1.8% ⚪ within noise
octane-tsrx clear 39.567 39.917 +1.3% −1.8% … +2.1% ⚪ within noise
octane-jsx run 3.092 3.092 −1.6% −4.9% … +2.2% ⚪ within noise
octane-jsx replace 5.958 5.858 −1.5% −2.5% … +1.8% ⚪ within noise
octane-jsx add 3.008 3.000 ±0.0% −3.1% … +3.5% ⚪ within noise
octane-jsx update 0.266 0.258 −2.6% −7.0% … +0.7% ⚪ within noise
octane-jsx select 0.155 0.153 −1.6% −5.3% … +11.8% ⚪ within noise
octane-jsx swap 0.262 0.242 −3.0% −5.8% … +5.0% ⚪ within noise
octane-jsx remove 0.200 0.198 −0.3% −4.8% … +4.8% ⚪ within noise
octane-jsx runlots 33.058 33.700 +5.1% −2.2% … +9.3% ⚪ within noise
octane-jsx select_lots 2.586 2.479 −6.4% −26.8% … +17.5% ⚪ within noise
octane-jsx clear 72.967 71.608 +7.9% +3.3% … +13.8% 🟡 slower

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 60 measured values.

Public-import reachability bundles (bytes)

No changes across 108 measured values.

@trueadm
trueadm merged commit 62e6448 into main Oct 7, 2026
43 of 49 checks passed
@trueadm
trueadm deleted the fix/strong-effect-ref-access branch October 7, 2026 15:39
trueadm added a commit that referenced this pull request Oct 7, 2026
Conflict: the user-apps-v1 manifest.jsonl, regenerated by pnpm sync for
the 0.11.1 package versions. The merge takes #1849 and the Version
Packages release (#1850); the Lynx-lanes changeset with the 0.18.0
parser pin stays unreleased. #1849's three Strong test files pass on
this branch (683 tests).

Co-Authored-By: Claude Opus 5.5 <[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.

1 participant