Repository navigation
feat(compiler): reject write-only state in Strong mode - #1497
Merged
Merged
Conversation
Strong mode only rejected snapshot mutation while rendering. Mutating state in an event handler, effect, cleanup, or deferred callback compiled cleanly, even though passing the same array back to its setter is an Object.is no-op and copying only the outer object leaves identity-based consumers stale and rewrites the value transitions and useOptimistic revert to. Add OCTANE_STRONG_SNAPSHOT_MUTATION for mutations outside render; render-time mutations keep OCTANE_STRONG_RENDER_SNAPSHOT_MUTATION, following the existing RENDER_/EFFECT_STATE_UPDATE split. Literal state initializers now act as a structural proof for nested array properties, lazy and useReducer initial state, Map/Set created with new, and Object.assign/Reflect targets. Local helpers that receive a state value are followed. The check is read-only and lives in a new strong-state.js policy next to strong-mode.js. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Octane evaluates queued updaters and reducers while their owner renders and can call one function more than once: a transition update is evaluated when it is staged and again when the transition renders, an urgent functional update made while a transition is held is applied to the committed value and rebased onto the held value, and useOptimistic re-applies its reducer on each pending render. An updater that fetches or reads the clock therefore repeats its side effect. Add OCTANE_STRONG_IMPURE_UPDATER. useState/useLinkedState updaters, useReducer reducers, and useOptimistic reducers (inline, local, or same-module) are visited with the existing render checks: impure calls, ambient and module reads, state updates, getter and Effect Event calls, and ref reads/writes are reported under the new code, as are fetch and scheduled timer, microtask, or promise callbacks. Mutating the state an updater or reducer receives reports OCTANE_STRONG_SNAPSHOT_MUTATION. Runtime tests pin the replay. Co-Authored-By: Claude Opus 5.5 <[email protected]>
After an await, or in a timer or promise callback, setCount(count + 1) reads the render snapshot of the state it writes, so overlapping events overwrite each other's updates. Strong mode accepted this even though the updater form and the state getter read the latest value. Add OCTANE_STRONG_STALE_STATE_UPDATE. The Strong visitor now distinguishes an `event` phase (a callback body whose invocation time is unknown) from a provably `deferred` one: code after an await every path reaches, and callbacks passed to unshadowed setTimeout/setInterval/requestAnimationFrame/ requestIdleCallback/queueMicrotask or to .then/.catch/.finally. A deferred setter or dispatch whose argument reads the same state's snapshot, including through a local computed before the await, a copied alias, or a closure, is an error. Synchronous handlers stay legal. Existing diagnostics are unchanged by the phase split; fixtures that relied on stale deferred updates now use the updater form. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A state tuple whose value and getter are never read exists only to force renders for an external source (`const [, force] = useState(0)`, or useReducer((x) => x + 1, 0)). It reads that source during render and subscribes afterwards, so a change in between is never rendered, and it has no server snapshot. Add OCTANE_STRONG_WRITE_ONLY_STATE in a standalone strong-write-only-state.js built on the shared Strong hook graph, so aliases, namespace imports, and shadowing agree with the other Strong analyses. A tuple is reported when its value is elided, unused, or read only inside its own setter's arguments, its getter is absent or unused, and its setter is referenced. The message names useSyncExternalStore. Existing fixtures that used write-only tuples as scaffolding now read their value. Co-Authored-By: Claude Opus 5.5 <[email protected]>
7 tasks done
8 tasks done
trueadm
marked this pull request as ready for review
October 1, 2026 08:49
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
Resolve conflicts with the Strong state checks (#1497): keep both the effect and state policies, visit non-zero-delay synchronous callbacks in the event phase, and render the state in effect fixtures so they are not write-only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
Brings in #1497 (Strong state values, updaters, and write-only state) and resolves the same conflicts as #1489 in strong-mode.js and the Strong docs, keeping the DOM ownership and query additions from #1491 and #1492. The workaround ledger records that #1497 now rejects five workarounds that previously compiled and kept the bug: both force-update click tallies, setN(n + 1) after await, mutate-then-set, and the mutating updater (27 → 22 compiler gaps). Prompts, references, and the recorded alternative are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 of 6 tasks
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
…ong-effect-async-cleanup Keep fetch identity for the Strong updater-purity check from #1497, drop the removed fetch-control save in pure callbacks, keep the instance-field ownership toggle with the new event phase, and render the state written by async-effect fixtures. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
6 tasks done
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
The original #1494–#1497 content landed in main through the squash of #1497. Resolve against main so this branch carries only the snapshot-mutation review fixes: tuple and Effect Event helper arguments, defaulted parameters, and useLinkedState literal shapes. The fix gets its own patch changeset instead of editing the released-pending one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
The original updater check landed in main through the squash of #1497. This branch now carries the #1494 follow-ups plus its own regression tests for a destructured updater parameter with a default and a defaulted reducer state parameter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
The original stale-update check landed in main through the squash of #1497, without its Effect Event follow-ups. Resolve against main so this branch carries the #1494/#1495 follow-ups plus the Effect Event rule: state an Effect Event captures is current in its own body, while arguments and nested deferred callbacks are still checked. The fix gets its own patch changeset. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
main now contains #1494–#1497 and the benchmark fix (#1499). Resolve against the updated #1496 branch so this PR carries the uncached useSyncExternalStore snapshot check on top of the open review follow-ups. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 1, 2026
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
…aters A module-level Intl formatter without a locale or time zone, rebound to a local const and used during render, went unreported: the use site required the name to resolve at module scope. Formatter records now remember whether they were built at module scope, and aliases carry that through. Updaters and reducers are visited as render code since #1497, so OCTANE_STRONG_RENDER_LOCALE_FORMAT fired inside them with a hydration message. They run on the client after an event and a replay formats the same way, so the locale check is skipped there; randomness inside them still reports as OCTANE_STRONG_IMPURE_UPDATER. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
…aters A module-level Intl formatter without a locale or time zone, rebound to a local const and used during render, went unreported: the use site required the name to resolve at module scope. Formatter records now remember whether they were built at module scope, and aliases carry that through. Updaters and reducers are visited as render code since #1497, so OCTANE_STRONG_RENDER_LOCALE_FORMAT fired inside them with a hydration message. They run on the client after an event and a replay formats the same way, so the locale check is skipped there; randomness inside them still reports as OCTANE_STRONG_IMPURE_UPDATER. Co-Authored-By: Claude Opus 5.5 <[email protected]>
27 of 35 tasks
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
* feat(compiler): close Strong render determinism gaps
Strong mode treated callbacks passed to known synchronous array methods as
deferred, so `items.map(i => <li key={Math.random()} />)` and random children
inside `.map` compiled. Those callbacks now run in the caller's phase, so every
render rule applies inside them (impure calls, ref reads, state updates).
`crypto.randomUUID()` and `crypto.getRandomValues()` join
OCTANE_STRONG_RENDER_IMPURE_CALL with a message that names `useId()`, and an
impure call that computes a `key` or `@for` key gets a message that names a
stable item ID.
New OCTANE_STRONG_RENDER_LOCALE_FORMAT rejects locale- and time-zone-dependent
formatting during render when the receiver is provably a Date or the
constructor is an Intl service, including module-level formatters used in
render.
The analysis lives in strong-render-policy.js; strong-mode.js only gains hook
points. Diagnostics only: compatibility mode and emitted code are unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* fix(compiler): keep spread locale arguments opaque in Strong formatting
A spread in the locale or options position, such as `toLocaleString(...args)`
or `new Intl.DateTimeFormat(...args)`, can supply both the locale and the
options. OCTANE_STRONG_RENDER_LOCALE_FORMAT treated the following position as
absent and reported a missing time zone it could not prove. A spread in either
of the first two positions now leaves the call unreported, like other options
the compiler cannot see.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* fix(compiler): follow formatter aliases and skip locale checks in updaters
A module-level Intl formatter without a locale or time zone, rebound to a local
const and used during render, went unreported: the use site required the name
to resolve at module scope. Formatter records now remember whether they were
built at module scope, and aliases carry that through.
Updaters and reducers are visited as render code since #1497, so
OCTANE_STRONG_RENDER_LOCALE_FORMAT fired inside them with a hydration message.
They run on the client after an event and a replay formats the same way, so the
locale check is skipped there; randomness inside them still reports as
OCTANE_STRONG_IMPURE_UPDATER.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
* feat(compiler): reject Strong writes to DOM the template renders When a useRef provably names exactly one intrinsic element in the same component (or keyed @for row), Strong mode now rejects imperative writes to what the template owns on that element: - OCTANE_STRONG_MANAGED_DOM_WRITE: textContent, innerText, or the child-list methods on an element with rendered children; className, classList mutators, or classList.value when the template sets a class; setAttribute, removeAttribute, or toggleAttribute for an attribute the template sets; and style, style.cssText, or a style property the template sets. - OCTANE_STRONG_RAW_HTML_WRITE: innerHTML, outerHTML, insertAdjacentHTML, or setHTMLUnsafe on a rendered element; the message names dangerouslySetInnerHTML={trustHTML(html)}. The proof follows .current reads, `const { current } = ref`, unreassigned local aliases, ref lists, and inline callback refs. Any other use of the ref (a component ref prop, a helper argument, a .current write, a second element) withdraws it. Writes to DOM the template does not own, such as mounting a widget into an empty container, stay valid. The analysis is a standalone pass in strong-dom.js that reuses Strong's hook scope analysis and is skipped for top-level statements without a ref prop and a DOM write spelling. Diagnostics only: compatibility mode and emitted code are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(compiler): reject Strong document queries for a component's own markup New OCTANE_STRONG_OWN_MARKUP_QUERY rejects document.getElementById(), querySelector(), querySelectorAll(), and getElementsByClassName() when a literal selector matches a literal id or class rendered by the same component. The message names a ref as the replacement. Only a single compound selector (#id, .class, tag.class, …) is matched, against literal id and class values, including string elements of a class array. Portal targets, markup rendered by other components, dynamic selectors, combinators, element-scoped queries, and a shadowed document stay valid. window.document, globalThis.document, and const aliases of document are followed. Builds on the DOM ownership pass in strong-dom.js. Diagnostics only: compatibility mode and emitted code are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(compiler): close Strong render determinism gaps Strong mode treated callbacks passed to known synchronous array methods as deferred, so `items.map(i => <li key={Math.random()} />)` and random children inside `.map` compiled. Those callbacks now run in the caller's phase, so every render rule applies inside them (impure calls, ref reads, state updates). `crypto.randomUUID()` and `crypto.getRandomValues()` join OCTANE_STRONG_RENDER_IMPURE_CALL with a message that names `useId()`, and an impure call that computes a `key` or `@for` key gets a message that names a stable item ID. New OCTANE_STRONG_RENDER_LOCALE_FORMAT rejects locale- and time-zone-dependent formatting during render when the receiver is provably a Date or the constructor is an Intl service, including module-level formatters used in render. The analysis lives in strong-render-policy.js; strong-mode.js only gains hook points. Diagnostics only: compatibility mode and emitted code are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(evals): add the Strong mode repair task family Fourteen octane.strong-* tasks in user-apps-v1 share familyId octane.strong-repair and the repair capability. Each starter opts into Strong mode and fails to compile; its prompt quotes the compiler's exact error. A grader passes an answer only when it compiles in Strong mode (the grader passes strong: true, so deleting the directive does not help) and the behavior the diagnostic predicts is gone: server-rendered HTML, prop updates, fetch races, cleanup on unmount, and stable identity. Graders import the submission inside each test so a Strong-failing starter still records a failed assertion. Each task records the workarounds agents reach for under negatives/. The new scripts/verify-strong-repair-corpus.mjs checks that every prompt quotes its starter's current error, every reference compiles, and every workaround fails its grader, then writes strong-repair-negatives.json. 27 of 37 workarounds still compile in Strong mode while keeping the bug; that ledger is the compiler-fixture backlog, and a check that closes one makes the ledger stale. The generator honours the catalog familyId, uses a repair-specific training system prompt for repair tasks, and adds the shared strong-repair.ts helper to those tasks' grader digests. The corpus test requires the new strongRepairs coverage group and runs the verifier in check mode. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): treat normalized empty JSX text as no rendered child Literal normalization rewrites text removed by JSX whitespace rules to '', which renders nothing. rendersChild now honours that, so an empty host never counts as owning children. Today's parsers drop line-break-only text before normalization, so this guards the contract rather than a reachable case; the new fixture pins a formatted empty container as a valid mount target. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(evals): evaluate Strong repair server builds without browser globals The server checks ran server-compiled submissions inside the jsdom test realm, so `window` was defined. A Strong-valid lazy initializer guarded by `typeof window === 'undefined'` (the pattern the ambient-read diagnostic recommends) reported jsdom's width and failed the viewport task, although real SSR takes the guard's server branch. serverModule now shadows window, self, document, navigator, location, localStorage, sessionStorage, and matchMedia as undefined, as on a real server. The verifier also grades recorded valid answers under alternatives/ and fails when a grader rejects one; the viewport task records the lazy-initializer answer that exposed this. The workaround ledger is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(evals): run Strong repair server builds in a browser-free realm Shadowing browser names as undefined parameters did not match a real server. `globalThis.window` still reached jsdom, so a valid `globalThis.window` guard failed the viewport task, and `window?.innerWidth ?? 1024` passed although a real server throws a ReferenceError on the undeclared `window` binding. serverModule now evaluates the server build in a separate node:vm realm that carries only Node's server globals (timers, console, URL, fetch, crypto, and similar), so browser names are undeclared exactly as in production. The viewport task records the `globalThis.window` guard as a valid alternative and the optional-chained `window` read as a workaround; the latter compiles in Strong mode and is now a recorded compiler gap (23 of 38). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): keep spread locale arguments opaque in Strong formatting A spread in the locale or options position, such as `toLocaleString(...args)` or `new Intl.DateTimeFormat(...args)`, can supply both the locale and the options. OCTANE_STRONG_RENDER_LOCALE_FORMAT treated the following position as absent and reported a missing time zone it could not prove. A spread in either of the first two positions now leaves the call unreported, like other options the compiler cannot see. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(evals): accept abort-based repairs in the Strong user-fetch grader The grader asserted that fetch received only the URL, so passing an AbortSignal failed the load test, and its stub ignored aborts, so a cleanup that calls controller.abort() still let the stale response land. The stub now rejects with an AbortError when the request's signal aborts, like a real fetch, and the load test checks only the requested URL. The task records the AbortController repair as an alternative that must pass; the recorded workarounds are still rejected. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): follow formatter aliases and skip locale checks in updaters A module-level Intl formatter without a locale or time zone, rebound to a local const and used during render, went unreported: the use site required the name to resolve at module scope. Formatter records now remember whether they were built at module scope, and aliases carry that through. Updaters and reducers are visited as render code since #1497, so OCTANE_STRONG_RENDER_LOCALE_FORMAT fired inside them with a hydration message. They run on the client after an event and a replay formats the same way, so the locale check is skipped there; randomness inside them still reports as OCTANE_STRONG_IMPURE_UPDATER. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): ignore scoped style blocks when proving rendered children A TSRX sibling-scoped <style> block is extracted from the template rather than rendered into its host, so a host whose only child is a style block is empty. rendersChild treated the JSXStyleElement as rendered content, and Strong rejected valid widget mounts such as appendChild into that host. Hosts with a style block and real rendered children are still checked. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(evals): require the save counter to count only resolved saves The save-counter grader read the label only after every pending save settled, so counting on click before `await save()` reached the same final totals and passed. The grader now checks that the count stays at 0 while both overlapping saves are pending, rises by one as each resolves, and holds while a third save is pending. Record that rewrite as the count-on-click negative (it compiles in Strong mode, so the ledger marks it compiles-keeps-bug) and add a reducer-then alternative so the stricter grader stays checked against a second valid answer. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(evals): resolve a real Response in the user-fetch grader The fetch stub resolved a plain object with only json(), so `response.ok` was undefined and a correct repair that checks it before reading JSON never showed the user. Resolve a real JSON Response, so `ok`, `status`, and the body behave as they do in a browser. Add the ok-guard alternative (an async effect body that checks response.ok and ignores a superseded result) so the grader stays checked against that shape. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- 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
Adds
OCTANE_STRONG_WRITE_ONLY_STATE: a state tuple whose value and getter are never read exists only to force renders. This is the force-update hack.Why: it reads the external source during render and subscribes afterwards, so a change in between is never rendered, and it has no server snapshot. The runtime tests show a store change made in a layout effect before the passive subscription stays unrendered, while
useSyncExternalStorerenders it. The message namesuseSyncExternalStore(subscribe, getSnapshot, getServerSnapshot).Changes
strong-write-only-state.json the shared Strong hook graph, so aliases, namespace imports, and shadowing agree with the other Strong analyses. It is called once at the end ofanalyzeStrongMode.force(tick + 1));useState(0)[1],{ 1: force },useReducer,useLinkedState.const [data, setData] = useState(null)with<div />,const [, setCount]). They now render the value; one plain-JS hook fixture returns[current, …].octane, minor).Validation
At this commit:
tests/compiler/strong-*.test.tsandbundler-compiler.test.ts(1,369 passed), andtests/strong-state-runtime.test.tsinoctaneandoctane-prod(28 passed). Coverage includes shorthand{value}attributes,<Value />component reads, destructured values, shadowed hooks, optional namespace access,.tsrx, and a plain.tsuseForceUpdatehook.Whole-stack validation, run on the top of the stack (all five families) plus the harness fix:
pnpm format:checkpnpm typecheckpnpm test: run as the 4 CI shards (vitest.ci-sharded.config.js, CI's excludes), because an unsharded local run OOMs the Vitest main process on this machine. 42,527 tests passed. Two load timeouts (website-mcp/tests/mcp-plumbing.test.ts,packages/testing-library/tests/octane-peer-minimum.test.ts) pass in isolation; no unhandled errors.Risk / follow-ups
typeof value) do not count as reads.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Adds several new Strong-mode compile errors across common state patterns; misclassification could block valid code, though analysis is explicitly bounded and compatibility mode is unchanged.
Overview
Strong mode gains four compile-time state checks (compatibility mode unchanged), wired through new
strong-state.jspolicy logic and a post-pass instrong-write-only-state.js, plus docs/changesets and broad compiler/runtime tests.Updater/reducer purity (
OCTANE_STRONG_IMPURE_UPDATER):useState/useLinkedStateupdaters,useReducer, anduseOptimisticreducers are analyzed like render code because Octane can replay them during transitions. Side effects, ambient reads, nested setters,fetch, and timer/promise scheduling inside those callbacks become errors.Immutability outside render (
OCTANE_STRONG_SNAPSHOT_MUTATION): mutating state snapshots in handlers, effects, deferred callbacks, or inside updaters/reducers is rejected, with richer shape tracking (nested literal arrays,Map/Set,Object.assigntargets). Render-time mutation still usesOCTANE_STRONG_RENDER_SNAPSHOT_MUTATION.Stale deferred writes (
OCTANE_STRONG_STALE_STATE_UPDATE): afterawaitor timer/promise callbacks, setters/dispatches that close over the same state's render snapshot are rejected; synchronousonClickupdates stay allowed.Write-only tuples (
OCTANE_STRONG_WRITE_ONLY_STATE): force-update patterns where only the setter is used (e.g.useReducer((x) => x + 1, 0),useState(0)[1]) must move touseSyncExternalStore.Existing Strong tests were updated to use functional updaters where deferred code would now fail, and fixtures that used write-only state now render the value so they remain valid.
Reviewed by Cursor Bugbot for commit 3d5e95b. Bugbot is set up for automated code reviews on this repo. Configure here.