Repository navigation
perf(octane): compile a catch-only @try to the error boundary - #2271
Merged
Merged
Conversation
A `@try` without `@pending` passes suspension on, so it is the same boundary as `<ErrorBoundary>`. The compiler only sent the imported `<ErrorBoundary>` lowering to `errorBlock`; an authored catch-only `@try` went through `tryBlock`, whose module-load `rollbackEntry` and Suspense machinery kept the root render journal and hidden-primary code in every app that used it (+10.1 kB gzip on the weather app's migrated port). Lower every catch-only `@try` to `errorBlock`, except in a presentation- binding view, whose server render owns that suspension and whose client must still claim a streamed arm. `errorBlock` committed the work a failed body queued when the body threw during an update: its attribute writes, new structure and stylesheet resources reached the page before the catch arm replaced it (#2043). It now drops them with `dropBodyOps`, as `tryBlock` does. This also fixes `<ErrorBoundary>`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | 5286285 | Commit Preview URL Branch Preview URL |
Oct 28 2026, 10:47 PM |
trueadm
marked this pull request as ready for review
October 28, 2026 22:21
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | 5286285 | Commit Preview URL Branch Preview URL |
Oct 28 2026, 10:45 PM |
Contributor
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
98 other measured values are unchanged. Public-import reachability bundles (bytes)
138 other measured values are unchanged. |
… arm included A boundary the server left to the client (its body threw on the server) rendered its body with hydration suspended, but switched to its catch arm after hydration resumed. The catch switch then treated the failed body's client-built DOM as adopted server DOM and left it in place: a nested pending-only @Try that threw left its `<section>` beside the catch arm. Run the whole fresh render inside `suspend`, as tryBlock's clientRenderDehydratedTry does. This also fixes `<ErrorBoundary>`. same-file-void-root suspended its root with a raw `throw gate` in a bundle whose only boundaries are catch-only @Try. That bundle no longer ships suspension, as an ErrorBoundary-only one never did, so the test now suspends through use(). 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
@trywithout@pendingnow compiles toerrorBlock, the catch-only boundary<ErrorBoundary>already lowers to, instead oftryBlock. An app whose boundaries only catch errors no longer ships the Suspense runtime or the root render rollback.errorBlocknow matchestryBlockin two places it fell short, which also fixes<ErrorBoundary>on main:Why
@octanejs/codemod(#2264) turns React class error boundaries into@try/@catch. On the weather benchmark's migrated React port, that idiomatic form cost 10.1 kB gzip more than<ErrorBoundary fallback>: 63,868 B against 53,742 B.The runtime already treated the two forms the same.
tryBlockImplsetspropagateSuspense ||= pendingBody === null(since #833), so a catch-onlytryBlockpasses suspension on exactly aserrorBlockdoes. The compiler gatederrorBlockontc.propagateSuspense, though, and only the<ErrorBoundary>lowering sets that. Every authored catch-only@trytherefore went throughtryBlock, andtryBlock = rollbackEntry(tryBlockImpl)installs the render rollback at module load. That retains the root journal, its replay, suspension, the hidden-primary and transition-hold code, and the visibility driver.The fix belongs in the compiler, not in the codemod choosing
<ErrorBoundary>to dodge the cost.Changes
compile.js,planJsx):catchOnlyis any@trywith a catch arm and no@pending. The one exception is a presentation-binding view's catch-only@try, which stays ontryBlock. There,ssrTryreceivespropagateSuspense: falseand owns the suspension, so the client must still be able to claim a streamed arm, which onlytryBlock'sclaimClientArmdoes. The rule is now:errorBlockexactly where the server passes suspension on.makeTryCallrecordsbindingSite, asmakeIfCallalready does.suspense.ts,switchErrorToCatchInner): calls the existingdropBodyOps(transaction, previous)before unmounting the failed body, mirroringswitchToCatchInner. Without it,errorBlockcommitted the failed body's attribute writes, new@ifarm and stylesheet<link>before the catch arm replaced it. Routing@trythrougherrorBlockturned this up: 4 cases intry-failed-body-ops.test.tswent red. The same leak exists today for<ErrorBoundary>.suspense.ts,mountErrorBoundary): a boundary the server left to the client (its body threw on the server) now renders on the client in full, catch switch included, insidehydration.suspend, astryBlock'sclientRenderDehydratedTrydoes. Before,errorBlocksuspended hydration only for the body render, so when that body threw, the catch switch treated the body's client-built DOM as adopted server DOM and left it in place. CI found this inhydration/try-clone-thrower.test.ts: a nested pending-only@tryleft its<section>beside the catch arm. It is also a main bug for<ErrorBoundary>, now covered by anUncaughtBoundarytwin.same-file-void-root.test.ts): the fixture suspended its root with a rawthrow gatein a production bundle whose only boundaries are catch-only@try. Under the behavior change below, that bundle no longer ships suspension, as anErrorBoundary-only one never did. The test's subject is when error callbacks are read, so it now suspends throughuse(gate).differences-from-react.md): the client suspension-entry list now says@trywith@pending, and a bundle whose only boundaries areErrorBoundaryor catch-only@tryships no rollback.Behavior change to review
In a bundle with no entry that can suspend (
use,lazy,Suspense,@try … @pending,Hydrate/hydration, native signal reads,ViewTransition, renderer regions), a thenable thrown during render inside a catch-only@tryis now an ordinary render error that the@catcharm catches. Before, the root suspended. This is the documentedErrorBoundarybehavior, and the brief asked for catch-only@tryto take the ErrorBoundary path. It is a pay-for-what-you-use divergence from React, which suspends on that thenable. An app with any suspending entry is unaffected.benchmarks/bundle-sizerender-errorsnow pins it:WaitsGuardedis a catch-only@try.Validation
pnpm format:check: not run repo-wide;pnpm format:files:checkon every changed file passespnpm typecheck: not run repo-wide;pnpm typecheck:filesreports no error on changed lines (suspense.tsclean; the test files carry pre-existing TS4111/TS7006 errors on untouched lines)pnpm test: not run locally; left to CItargeted tests,
--project octane:try-catch,boundary,boundary-unwind,try-failed-body-ops,root-error-callbacks,replayed-try-slots,compiled-boundaries,hydration/{try-catch-arm,trycatch-client-error,catch-destructured-param,boundary-fallback-error,rangeless-error-boundary}: 12 files, 255 tests pass.behavior-rootbinding@tryhydration cases pass.node --test benchmarks/bundle-size/{minimal,hydration-free}-gates.test.mjs: 14 pass.Tests seen failing before the fix:
bundler-compiler.test.ts› "lowers a @Try without @pending to the catch-only boundary" fails with the old gate (noerrorBlock) and fails with the binding exclusion removed (notryBlockin the binding view).try-failed-body-ops.test.ts: without thedropBodyOpscall, 6 cases fail in dev and prod, including the newFailingBoundary(<ErrorBoundary>) twin, which fails the same way on main'serrorBlock.run-minimal.mjs render-errors: with the old gate, the scenario retains all 23 render-rollback declarations plustryBlockImpl, and the reachability gate fails.hydration/try-clone-thrower.test.ts› "…inner pending-only boundary throws": with the catch switch outsidesuspend, bothUncaught(@try) and the newUncaughtBoundary(<ErrorBoundary>) leave<section></section>beside the catch arm.After the CI round on
6f47340692(failures intry-clone-throwerandsame-file-void-root; shards 1, 2 and 4 were cancelled mid-run), the changed files pass locally inoctaneandoctane-prod. So do the other production-bundle suites that use@catch:optional-driver-bundle,production-error-bundle,hydration/split-hydrate-local-bindings,compiler/signal-declarations.Size A/B (same session,
vite build, esbuild minify):@try(varG)<ErrorBoundary>(varH)errorBlockfixes)run-minimalrender-errors@try)run-minimalsuspense-transitionAfter the change, the
@tryand<ErrorBoundary>weather bundles are the same size. The only growth is the twoerrorBlockcorrectness fixes, which every bundle that keepserrorBlockpays. Head numbers are from528628508a; the perf A/B below ran on6f47340692, whose only difference from head is the error-path-only hydration fix.CI benchmark report (
4956093ee, the merge of6f47340692):dropBodyOpscorrectness fix inerrorBlock:weather_js+258 raw / +91 gzip andweather_fw+258 / +90. The in-repo weather app uses<ErrorBoundary>, so it gains the fix's bytes without the@trysaving.full_fw+46 raw / +6 gzip.render-errors+258 / +99 / +152 brotli.528628508aadds 17 B raw / 13 B gzip more to bundles that keeperrorBlock.Perf A/B (same session, alternating, production builds):
flushSyncupdates × 7 rounds alternating main/head under jsdom, run twice.@try: 3.31 → 3.09 µs/update (−6.5%), then 3.46 → 3.30 (−4.7%).<ErrorBoundary>in the same bundle: −5.0% and −3.7%, since the bundle no longer journals root renders.benchmarks/weather-app/run.mjs 12over four builds (@try/<ErrorBoundary>× main/head), two rounds in reversed target order. The<ErrorBoundary>pair has the same render path on both sides and sets the noise floor (−1.5% to −6.2%).@trystays inside it: initial_ready −5.2%/−2.3%, forecast_cycle −2.4%/0.0%, search_* within 0.1 ms timer quantization (rme 5–15%). No regression is measurable. No app-level speedup is claimed.perf-review:node scripts/perf-review-scan.mjs→ 0 candidates.@trynow emits a 6-argumenterrorBlock(…)instead of a 7-argumenttryBlock(…, null, …), anderrorBlock's update path is a directrenderBlockwith no journal arm, capture window or effect-dep snapshot.dropBodyOpsruns only when a body throws (cold path, one scan of the root's queued ops, the same astryBlock).concise-code: src +30 −11 (runtime +20 −7); no new files or exports outside test fixtures. The one new function,renderErrorBody, ismountErrorBoundary's existing try/catch, lifted so the fresh boundary can run it insidesuspend.errorBlockalready is one.tryBlockskiprollbackEntrywhen catch-only: impossible, because the entry installs at module load andtryBlockImplnames the whole Suspense implementation.<ErrorBoundary>: masks the defect.Risk / follow-ups
@tryin a'use dom bindings'view keepstryBlockand its cost. Moving it would neederrorBlockto claim a streamed or client-rendered arm, asclaimClientArmdoes.planJsx's trailing-argument conditions on!catchOnly && tc.propagateSuspensewere already unreachable, because only the<ErrorBoundary>lowering setspropagateSuspense, and that lowering is always catch-only.octane-prod, hydration, browser) that were not run locally.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.Note
Medium Risk
Touches compiler boundary selection and error-boundary commit paths; behavior shifts for catch-only
@tryin non-suspending bundles when render throws thenables.Overview
Catch-only
@try { … } @catch(no@pending) now lowers toerrorBlock, the same runtime as<ErrorBoundary>, instead oftryBlock. Apps that only need error catching no longer pull in Suspense machinery or the root render rollback (~10 kB gzip on the weather benchmark’s codemod-style@tryport).Compiler:
catchOnlyis any@trywith@catchand no@pending(pluspropagateSuspenseor no binding site). Presentation'use dom bindings'views keeptryBlockso the client can still claim streamed SSR arms.Runtime: When a catch-only boundary’s try body throws on update,
dropBodyOpsruns before unmount (matching full@try), so queued attribute writes, new nodes, and stylesheet resources from the failed render never commit. This also fixes the same leak on<ErrorBoundary>.Semantics: In bundles with no suspending entry, a thenable thrown inside catch-only
@try/ErrorBoundaryis a normal render error caught by@catch(not root suspend)—aligned with documented ErrorBoundary behavior and Octane’s pay-for-what-you-use model.Docs, bundle-size
render-errorsfixture/gates, and tests cover codegen, failed-body ops, and hydration.Reviewed by Cursor Bugbot for commit 5286285. Bugbot is set up for automated code reviews on this repo. Configure here.