Repository navigation
feat(compiler): close Strong render determinism gaps - #1489
Conversation
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]>
…5c5da # Conflicts: # docs/differences-from-react.md # docs/strong-compiler-checks.md # packages/octane/src/compiler/strong-mode.js
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]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Spread first arg false positive
- Added a guard (
args[0]?.type !== 'SpreadElement') before themissingTimeZone(args[1])check in bothintlServiceandcall, so a leading spread — which could supply both locale and options — fails open instead of being falsely reported as missing a timeZone.
- Added a guard (
Or push these changes by commenting:
@cursor push 88296b923a
Preview (88296b923a)
diff --git a/packages/octane/src/compiler/strong-render-policy.js b/packages/octane/src/compiler/strong-render-policy.js
--- a/packages/octane/src/compiler/strong-render-policy.js
+++ b/packages/octane/src/compiler/strong-render-policy.js
@@ -139,7 +139,9 @@
name,
implicit:
missingValue(args[0], scope) ||
- (name === 'DateTimeFormat' && missingTimeZone(args[1], scope)),
+ (name === 'DateTimeFormat' &&
+ args[0]?.type !== 'SpreadElement' &&
+ missingTimeZone(args[1], scope)),
};
}
@@ -253,7 +255,11 @@
const locale = DATE_LOCALE_METHODS.has(name);
if ((!locale && !DATE_ZONE_METHODS.has(name)) || !isDate(member.object, scope)) return;
const args = node.arguments ?? [];
- if (locale && (missingValue(args[0], scope) || missingTimeZone(args[1], scope))) {
+ if (
+ locale &&
+ (missingValue(args[0], scope) ||
+ (args[0]?.type !== 'SpreadElement' && missingTimeZone(args[1], scope)))
+ ) {
report(
STRONG_RENDER_LOCALE_FORMAT,
member,
diff --git a/packages/octane/tests/compiler/strong-render-determinism.test.ts b/packages/octane/tests/compiler/strong-render-determinism.test.ts
--- a/packages/octane/tests/compiler/strong-render-determinism.test.ts
+++ b/packages/octane/tests/compiler/strong-render-determinism.test.ts
@@ -307,6 +307,8 @@
{new Date(t).toISOString()}{new Date(t).toUTCString()}{new Date(t).getTime()}
{new Date(2024, 0, 1).toDateString()}
{new Intl.DateTimeFormat(locale, { timeZone, month: 'long' }).format(t)}
+ {new Intl.DateTimeFormat(...options).format(t)}
+ {new Date(t).toLocaleString(...options)}
{utc.format(t)}{count.format(n)}{date.toLocaleString()}{n.toLocaleString()}
{label}{clicked}
</button>You can send follow-ups to the cloud agent here.
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]>
…5c5da # Conflicts: # packages/octane/src/compiler/strong-mode.js
…5c5da # Conflicts: # packages/octane/src/compiler/strong-mode.js
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Local aliases skip module formatter checks
- Replaced the resolveScope === moduleScope gate with a moduleLevel flag set on the value object when first recorded at module scope, so local aliases inherit the flag through the same object reference and are correctly reported during render.
- ✅ Fixed: Locale checks misfire in state updaters
- Added early return in pureDiagnostic for OCTANE_STRONG_RENDER_LOCALE_FORMAT (returning false) and a corresponding check in report() to suppress the diagnostic entirely in updaters/reducers, since locale/timezone are stable across replays on the same runtime.
Or push these changes by commenting:
@cursor push 2290cc3f2a
Preview (2290cc3f2a)
diff --git a/packages/octane/src/compiler/strong-mode.js b/packages/octane/src/compiler/strong-mode.js
--- a/packages/octane/src/compiler/strong-mode.js
+++ b/packages/octane/src/compiler/strong-mode.js
@@ -1636,6 +1636,7 @@
function report(code, node, message, suggestions = []) {
if (insidePureCallback) {
const pure = statePolicy.pureDiagnostic(code);
+ if (pure === false) return;
if (pure !== null) {
code = pure.code;
message = pure.message;
diff --git a/packages/octane/src/compiler/strong-render-policy.js b/packages/octane/src/compiler/strong-render-policy.js
--- a/packages/octane/src/compiler/strong-render-policy.js
+++ b/packages/octane/src/compiler/strong-render-policy.js
@@ -172,6 +172,8 @@
recorded++;
if (scope === moduleScope && value.kind === 'intl' && value.implicit) moduleFormatters++;
}
+ if (scope === moduleScope && value.kind === 'intl' && value.implicit)
+ value.moduleLevel = true;
names.set(id.name, value);
}
}
@@ -248,11 +250,7 @@
}
if (moduleFormatters !== 0) {
const alias = aliasValue(member.object, scope);
- if (
- alias?.kind === 'intl' &&
- alias.implicit &&
- resolveScope(scope, unwrap(member.object).name) === moduleScope
- ) {
+ if (alias?.kind === 'intl' && alias.implicit && alias.moduleLevel) {
reportIntl(member, alias, true);
return;
}
diff --git a/packages/octane/src/compiler/strong-state.js b/packages/octane/src/compiler/strong-state.js
--- a/packages/octane/src/compiler/strong-state.js
+++ b/packages/octane/src/compiler/strong-state.js
@@ -220,6 +220,7 @@
/** The Strong diagnostic that replaces a render diagnostic inside an updater or reducer. */
pureDiagnostic(code) {
+ if (code === 'OCTANE_STRONG_RENDER_LOCALE_FORMAT') return false;
if (code === 'OCTANE_STRONG_RENDER_SNAPSHOT_MUTATION') {
return { code: STRONG_SNAPSHOT_MUTATION, message: UPDATER_MUTATION_MESSAGE };
}You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit ca328ef. Configure here.
…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]>
Benchmark report🟢 No size increases and no timing regressions outside noise. Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)No changes across 105 measured values. CI job durations
Compares the CI run for
All 26 timed jobs
|
…5c5da # Conflicts: # packages/octane/src/compiler/strong-mode.js


Summary
Closes three gaps in Strong mode's render determinism checks (issue #1027). Each pattern below used to compile in Strong mode and now fails as an error. Compatibility mode is unchanged.
Array-method callbacks run as render. Callbacks passed to
map,filter,forEach,reduce,reduceRight,flatMap,some,every,find,findIndex,findLast,findLastIndex,sort,toSorted, and the mapping function ofArray.fromwere treated as deferred. Every render rule now applies inside them, for exampleitems.map(i => <li key={Math.random()}>…)anditems.forEach(setSelected).crypto.randomUUID()andcrypto.getRandomValues()joinOCTANE_STRONG_RENDER_IMPURE_CALL, with a message that namesuseId(). Any impure call that computes akey=or an@forkey gets a message that names a stable item ID instead.New
OCTANE_STRONG_RENDER_LOCALE_FORMATcovers:toLocaleString,toLocaleDateString, andtoLocaleTimeStringwithout both a locale and a visibletimeZone;toStringandtoTimeStringon a provableDate;Intlservice constructed without a locale (DateTimeFormatalso needs atimeZone);It reports only when the receiver is provably a
Datebuilt withnew Date(...), or the constructor is an unshadowedIntl.*.Why
A probe on main @ 85cb387 found that
.mapcallbacks were not checked as render, thatcryptocalls were missing from the impure-call list, and that locale-dependent formatting compiled cleanly. Locale-dependent formatting is a hydration mismatch in any SSR app.Changes
packages/octane/src/compiler/strong-render-policy.js: new module containing all of this analysis.strong-mode.jsgains only hook points (about 45 lines), to keep merge conflicts small with the parallel Strong sessions that also edit it.packages/octane/tests/compiler/strong-render-determinism.test.ts. It covers aliases, shadowed globals, optional chains, computed members,.tsrx(including@forrows and@forkey headers), plain.tscustom hooks, Volar parity, every compile mode, and pinned unchanged output.strong-mode.test.tshad a test from fix: memoize snapshot method calls in Strong mode #862 that pinnedcrypto.randomUUID()in render as legal. It now pins the new error, plus legal non-randomcryptouse.docs/strong-compiler-checks.md, plustsrx-basics.md,differences-from-react.md,llms.txt, andbuild-tools.mdx. Changeset added.Deliberately not reported, because the bug can't be proven:
getHours(), andtoDateString(): both are time-zone independent on dates built from local parts;Datepassed as a prop;Validation
pnpm format:files:checkon the diffpnpm typecheck(full run passed on the combined local work), pluspnpm typecheck:fileson this diffpnpm test: a full local run with a 12 GB heap passed 82,876 tests with 2 failures. Both pass in isolation: one is a load-sensitive browser timeout, the other a pristine upstream Base UI test. The machine was running other sessions at load average ~40, and with the default heap the root Vitest process ran out of memory. CI is the authority here.strong-*compiler suites plusvolar.test.ts, 1,262 tests passing.Dateshadowing) turns at least one test red..tsx/.tsrxfiles in the repo under Strong and diffed against main. Every new render diagnostic is a true positive:Math.random/Date.nowinside map callbacks,toLocaleDateString()in TanStack.com components, andcrypto.randomUUID()passed to auseRefinitializer.benchmarks/strong-compiler-checksaudit stays within noise (median ratios 0.95–1.03). Compatibility-mode compiles skip the analyzer entirely.Risk / follow-ups
.mapon a non-array would now be checked as render.octane analyze --strictcoverage ratchet is awaiting a design decision.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Strong mode becomes stricter for common patterns (map callbacks, crypto IDs, date formatting), which can break existing
"use strong"modules until fixed; runtime behavior and compatibility mode are unchanged.Overview
Strong mode now enforces three additional render-determinism rules; compatibility mode and emitted code are unchanged.
Callbacks passed to synchronous array methods (
map,filter,forEach,reduce,sort,Array.from, and related APIs) are analyzed as render, so impure calls, state updates, and ref reads inside those callbacks are rejected the same as in the component body.crypto.randomUUID()andcrypto.getRandomValues()are treated asOCTANE_STRONG_RENDER_IMPURE_CALL, with diagnostics that point touseId()for element IDs and stable item IDs for list keys when the impure expression feeds akeyor@forkey.A new
OCTANE_STRONG_RENDER_LOCALE_FORMATdiagnostic flags locale- or time-zone-dependent formatting during render on provableDatevalues and implicit-localeIntlconstruction (including module-level formatters used from render). Implementation lives in newstrong-render-policy.js, wired fromstrong-mode.jsvia focused hook points.Docs and a large
strong-render-determinism.test.tssuite document and lock in the behavior.Reviewed by Cursor Bugbot for commit 4d698ac. Bugbot is set up for automated code reviews on this repo. Configure here.