Repository navigation
fix(compiler): let Strong catch clauses run after an awaited call rejects - #1488
Merged
Merged
Conversation
…ects
Strong mode visited a try statement's catch clause, finally clause and
continuation with the phase in effect when the try began. Inside an async
function started by an effect, the canonical loading pattern
try { setData(await api.get(id)); } catch (error) { setError(error); }
reported OCTANE_STRONG_EFFECT_STATE_UPDATE on setError, even when nothing
before the await could throw (`await p` was rejected too).
A catch clause now keeps the starting phase only when the try block can throw
before its first guaranteed await. A finally clause, and code after the try,
keep it only when try or a synchronously entered catch can finish (throw,
return/break/continue, or complete) first. The same rule now drives
statementAlwaysAwaits and the do-while control analysis for try statements, so
the model stays consistent.
Calls, `new`, `throw`, iteration (spread, array patterns, for-of), classes and
unmodelled syntax count as throw points. Property reads, operators and object
destructuring do not, matching Strong's existing getter assumption. The
awaited call, and calls it chains from through then/catch/finally, are trusted
to report failure by rejecting; their callee and arguments still count, so
`await api.get(key(id))` and `await Promise.all([a(), b()])` keep the catch
synchronous.
Diagnostics only: emitted code, compatibility mode and Volar parity are
unchanged and pinned by tests. Two strong-mode tests that pinned the old
conservative behaviour with `await Promise.resolve()` now sit in the accepted
list, with synchronous-throw and early-exit variants pinning rejection.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 1, 2026 08:33
`await Promise.all([api.a(id), api.b(id)])` kept a catch clause synchronous because the element calls run before the combinator is awaited. Promise.all, allSettled, any and race consume each element of an array-literal first argument as a promise, so a call written there now gets the same trust as the awaited call: it is assumed to report failure by rejecting, including through then/catch/finally chains. The elements' own callees and arguments still count as throw points, as do spread elements, non-literal arguments such as `ids.map(load)`, later arguments, and `.all()` on any object other than Promise. A module that binds `Promise` anywhere (import, declaration, parameter, class, enum or catch binding) turns the combinator trust off. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…clauses # 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: This treated as throwing
- Added ThisExpression, Super, and MetaProperty to the inert-expression cases in throwsBeforeAwait so they return false instead of falling through to the default that returns true.
- ✅ Fixed: Promise binding walk incomplete
- Added TSImportEqualsDeclaration and TSModuleDeclaration to the bindsName switch so their id is recorded as a binding, correctly disabling Promise combinator trust.
Or push these changes by commenting:
@cursor push 18a4e2588c
Preview (18a4e2588c)
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
@@ -282,6 +282,8 @@
case 'ClassDeclaration':
case 'ClassExpression':
case 'TSEnumDeclaration':
+ case 'TSImportEqualsDeclaration':
+ case 'TSModuleDeclaration':
addPatternNames(node.id, bindings, true);
break;
case 'ImportSpecifier':
@@ -2333,6 +2335,9 @@
switch (node.type) {
case 'Literal':
case 'Identifier':
+ case 'ThisExpression':
+ case 'Super':
+ case 'MetaProperty':
case 'FunctionExpression':
case 'ArrowFunctionExpression':
return false;
diff --git a/packages/octane/tests/compiler/strong-effects.test.ts b/packages/octane/tests/compiler/strong-effects.test.ts
--- a/packages/octane/tests/compiler/strong-effects.test.ts
+++ b/packages/octane/tests/compiler/strong-effects.test.ts
@@ -507,6 +507,10 @@
'do-while exits from catch clauses entered only after yielding',
'do { try { setData(await api.get(props.id)); } catch (e) { break; } } while (props.retry); setLoading(false);',
],
+ [
+ 'awaited calls through this, super and import.meta receivers',
+ 'try { setData(await this.api.get(props.id)); } catch (e) { setError(e); }',
+ ],
])('allows updates in try clauses reached only after yielding: %s', (_label, body) => {
const source = load(body);
expect(compile(source, '/src/App.tsrx', { strong: true }).code).toBe(
@@ -644,6 +648,8 @@
['', 'function wrap(Promise) { return Promise; }'],
['', 'class Promise {}'],
['', 'try {} catch (Promise) {}'],
+ ['import Promise = Bluebird.Promise;', ''],
+ ['', 'namespace Promise { export const resolve = 1; }'],
])(
'does not trust Promise combinator elements when the module binds Promise: %s%s',
(imports, local) => {You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit dea2c33. Configure here.
…rong try analysis
`await this.api.get(id)` and `await api.get(import.meta.env.API)` kept a
catch clause synchronous because ThisExpression and MetaProperty fell through
to the unmodelled-syntax default. Reading them is no more able to throw than
reading an identifier, so they, and Super, are now inert like identifiers.
The Promise binding scan also skipped TypeScript namespaces and import-equals
declarations. `namespace Promise { ... }` compiles in .tsrx and .ts, and
`import Promise = require(...)` compiles in plain .ts hooks, so both now turn
the Promise combinator trust off.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…clauses # Conflicts: # packages/octane/src/compiler/strong-mode.js
…clauses # Conflicts: # packages/octane/src/compiler/strong-mode.js # packages/octane/tests/compiler/strong-effects.test.ts
Contributor
Benchmark reportNo benchmark report for this commit yet: PR bench is still running or skipped this change. CI job durations
Compares the CI run for
All 26 timed jobs
|
27 of 35 tasks
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
Strong mode rejected the standard effect loading pattern:
The analyzer gave the
catchclause, thefinallyclause, and the code after atrythe phase that was in effect when thetrybegan. Eventry { setD(await p); } catch (e) { setErr(e); }was rejected, though nothing in it can throw before the yield.The rule
Inside an async function whose
trystarts in the render or effect-setup phase:A
catchis synchronous only if something before thetryblock's first guaranteedawaitcan throw.A
finally, and the code after thetry, is synchronous only if thetry, or acatchentered synchronously, can finish before one.Settled awaits: in effect work, fix(compiler): require Strong effect cleanup to cancel or ignore async state updates #1482 on
mainno longer treats anawaitthat resumes without waiting (await null,await Promise.resolve()) as a yield. This analysis builds on the samealwaysAwaits, so such an await doesn't end the synchronous prefix. A settled await also counts as able to throw, soawait Promise.reject(err)keeps thecatchsynchronous. Finishing means throwing,return/break/continue, or falling through.Can throw: calls,
new,throw, iteration (spread, array destructuring,for…of), classes, and any syntax the analyzer doesn't model.Can't throw: reading an identifier,
this,superorimport.meta; property reads; operators; and object destructuring. This matches Strong's existing assumption that a property read runs no code.Trusted calls are assumed to fail by rejecting. Their callees and arguments are evaluated first and still count. Three kinds of call are trusted:
.then/.catch/.finally;Promise.all,allSettled,anyorrace.Async functions and web APIs such as
fetchguarantee this. The combinator trust is off if the module bindsPromiseanywhere: an import (including TypeScriptimport … = require), declaration, parameter, class,enum,namespaceor catch binding.await api.get(props.id)if (!id) throw …before theawaitawait fetch(url)thenawait res.json()const key = api.key(id); await api.get(key)await api.get(id).then((r) => r.data)await api.get(api.key(id))await Promise.all([api.a(id), api.b(id).then(parse)]), andallSettled/any/raceawait Promise.all(ids.map(load))orawait Promise.all([...requests])await import('./x'),await new Promise(…)await api.client().get(id), orapi.all([…])on a non-Promise objecttry/finallywhosefinallyruns only after its ownawaitPromise.all([…])in a module that declares its ownPromise(for exampleimport Promise from 'bluebird')if (!id) return;before theawaitfinallyreachable through an earlyreturnA
catchthat is now deferred is still checked like any other code after anawait. For example,setCount(count + 1)there reportsOCTANE_STRONG_STALE_STATE_UPDATE, added onmainby #1497, instead of the synchronous-update error.Changes
strong-mode.js:SYNC_THROW/SYNC_EXIT/SYNC_NORMAL) drives thecatchphase, thefinallyphase,statementAlwaysAwaits(TryStatement), and the do-while control analysis fortry, so the model stays consistent.Promise.Strong effect try clausesblock instrong-effects.test.ts..tscustom-hook output..tshook form also throws.Promise-shadowing cases, a stale-update case, and a fetch-continuation regression.main's newOCTANE_STRONG_WRITE_ONLY_STATEcheck.strong-mode.test.tscases pinned the old behaviour withawait Promise.resolve(). They move to the accepted list, and synchronous-throw and early-exit variants keep pinning rejection.docs/differences-from-react.mddocuments the rule, and a changeset is included (octanepatch).origin/mainup to 1c44df5 (fix(compiler): require Strong effect cleanup to cancel or ignore async state updates #1482).tryvisit now combines fix(compiler): require Strong effect cleanup to cancel or ignore async state updates #1482's abort-proof flow joins with this PR'scatch/finallyphases.awaitwith the cleanup'signoreflag, as fix(compiler): require Strong effect cleanup to cancel or ignore async state updates #1482 now requires.Validation
pnpm format:checkon the merged head.pnpm typecheckon the merged head.pnpm test, run as the four CI shards (vitest.ci-sharded.config.js --shard=N/4) on the first commit, e453e82. A single unsharded local run exhausts the main Vitest process's heap on this machine.octane-prodhmr.test.ts, which doesn't use Strong mode and passes when run alone.packages/octane/tests/compiler/plusstrong-state-runtime.test.tson the current merged head (74 files, 3,186 tests).Promisebinding kind), and each made at least one test fail.pnpm syncproduced no generated changes.Risk / follow-ups
switchand classes before the firstawaitare still treated conservatively and keep thecatchsynchronous.trystatements in async functions in Strong modules. ThePromisebinding scan walks the module at most once, and only when an awaited combinator appears in such atry. Emitted code doesn't change. I didn't benchmark compile time.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes compile-time effect-phase rules for async try/catch in Strong modules; trusted promise calls may miss synchronous throws, but runtime behavior is unchanged.
Overview
Strong mode no longer flags
OCTANE_STRONG_EFFECT_STATE_UPDATEon the usual async fetch pattern:try { setData(await api.get(id)); } catch (e) { setError(e); }. The compiler now decides whethercatch,finally, and code aftertryrun in the effect-setup phase or only after a yield.A
catchstays synchronous only if thetrycan throw (calls,new,throw, iteration, etc.) before its first guaranteedawait. Awaited calls—andthen/catch/finallychains andPromise.all/allSettled/any/racearray-literal elements (when the module does not bindPromise)—are treated as rejecting rather than throwing; callees and arguments still count.finallyand post-trycode use the same “can finish before yield” rule.Implementation adds sync-outcome analysis (
SYNC_THROW/SYNC_EXIT/SYNC_NORMAL),bindsNameforPromiseshadowing, and visitscatch/finallyindeferredphase when appropriate. Docs and a patch changeset document the rule; extensive compiler tests cover accept/reject cases. Emitted code is unchanged—only diagnostics.Reviewed by Cursor Bugbot for commit 2a35b23. Bugbot is set up for automated code reviews on this repo. Configure here.