Skip to content

fix(suspense): keep a pending boundary's query$ loads across parent renders - #1620

Merged
trueadm merged 8 commits into
mainfrom
fix/jsx-boundary-parent-render-query
Oct 3, 2026
Merged

trueadm merged 8 commits into
mainfrom
fix/jsx-boundary-parent-render-query

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • A pending <Suspense> boundary no longer restarts its query$ loads whenever its parent renders. Before this, a JSX <Suspense> lost them on every parent render, even with equal props. A compiled @try lost them on any new input. When the parent re-rendered faster than a load settled, the fallback stayed up forever.
  • The restarted attempt takes over the abandoned attempt's signal owners. A redeclared query$ re-selects from the new inputs, as fix(octane): re-select component-local query$ when captured props change #1550 made it do, and shares the load already in flight when its selection is unchanged. A changed selection starts its own load and aborts the old one immediately. Hooks still start fresh, as before.

Why

The 2026-10-02 review of PRs merged since 85cb387 rated this P1 (finding D1). #1607 covered only a boundary retrying itself. A parent render still superseded the attempt through two paths:

  • Client root: tryBlock sees new children (a JSX boundary builds new descriptors every render) and calls attemptHiddenReveal(…, 'parent'). restartUncommittedTry then unmounts the hidden primary, which retires every signal owner in it. The replacement mints new owners and starts another load.
  • Hydration first attempt: the supersedesInputs branch in tryBlock cleared the boundary's retained retry owners.

Repro (client root; App re-renders, rendering Suspense > Mid > Field, where Field calls query$(() => props.id, load).get()):

  • Before: three equal-prop parent renders gave loads ['a','a','a','a']. A parent that re-rendered before each load settled never revealed.
  • After: loads stay ['a'], and the boundary reveals v0.

Changes

  • runtime.ts:
    • restartUncommittedTry moves the old primary's owners into the boundary's retry cache, and the replacement claims them by path.
    • A dedicated handOverSignalRetryScope walk, reached only from this restart path, leaves the old scopes with false, an ownerless marker that still records retirement on deletion. It stops at a non-propagating nested boundary, as signalRetryBoundary does, because a nested primary claims only from its own cache. Those owners stay mapped and retire with the abandoned tree. Cursor Bugbot caught this on the third head. The handover can't rely on the RETAINED_SIGNAL_OWNERS window, because a root render defers a pre-existing block's teardown to its commit, after the replacement has claimed the owner.
  • runtime.ts: on superseding inputs, supersedeSignalRetryOwners prunes the cache instead of clearing it. It retires only owners whose cells cannot follow new inputs.
  • signals/owner-context.ts: adds supersedeSignalOwner, an indirection the facade installs, so the runtime never imports the engine. It returns whether an owner can be kept; a kept owner's cells are marked provisional.
  • signals/redeclaration.ts and ScopeImpl.supersede(): a provisional cell was never presented by a committed render. Until a render that declares it is accepted, a discarded render's definition replaces the abandoned one, so a changed selection aborts the obsolete request as soon as the restarted attempt suspends. This keeps the existing contract in signals-pending-stream.test.ts ("keeps pending inputs through parent renders before …"), which CI caught on the second head.
  • signals/engine.ts and signals/computations.ts: add ScopeImpl.unkeyedState. An authored signal$ sets it (in __signalAt), because its first initial value wins. A DerivedBinding sets it when its result turns asynchronous, because captured render values never restart that work. Those owners still restart with the attempt.
  • docs/signals.md: states the contract. Adds a changeset (octane patch).

Validation

Risk / follow-ups

  • A boundary nested inside the restarted primary still restarts its own queries, which is unchanged from before. Its pending request is aborted at the restart.
  • If a root or transition rolls back after a restart, the result is at worst an extra load, never a disposed-scope read, because the old scopes no longer hold the owners.
  • Review finding D2 (a local derived$ recomputes on every render, from fix(octane): re-select component-local query$ when captured props change #1550) is separate and not addressed here.

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
Changes Suspense retry and signal-owner lifecycle on a critical async rendering path, but behavior is narrowly scoped with extensive targeted tests.

Overview
Fixes a bug where a pending <Suspense> boundary restarted its query$ loads on every parent re-render (including equal JSX props or compiled @try input changes), so fast parent updates could leave the fallback up indefinitely; the same issue affected hydration when the client waited on an unresolved query.

When an uncommitted attempt restarts, the runtime hands signal owners into the boundary retry cache and supersedes them instead of clearing everything: query$ cells stay and the new attempt re-selects—unchanged selection reuses the in-flight request, changed selection starts a new load and aborts the old one. signal$ and async derived$ are marked unkeyedState and still restart with the attempt; provisional redeclaration keeps superseded query behavior correct when renders are discarded.

Docs and a patch changeset describe the contract; client and hydration tests cover equal props, selection changes, unmount abort, and nested boundaries.

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

…enders

A parent render that gave a pending Suspense boundary new children (every
render of a JSX <Suspense>, even with equal props) or new inputs (a compiled
@Try) restarted the uncommitted attempt and retired its signal owners. Each
render started the load again, and a parent that re-rendered faster than the
load settled kept the fallback up forever.

On a client root, restartUncommittedTry now hands the abandoned primary's
owners to the boundary's retry cache, and the replacement claims them by
path. The old scopes are marked ownerless rather than relying on the
retained-owner window, because a root render defers their teardown to its
commit. During hydration the supersede path prunes the cache instead of
clearing it. A redeclared query$ re-selects from the new inputs and shares
an equal in-flight request. Owners holding an authored signal$ or an
asynchronous derived$ still restart, since those cells cannot follow new
inputs.

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

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 25 value(s) increased
  • 🔴 bundle-reachability: 33 value(s) increased

Compares 27c2a12da with 7423948e3 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 3.82 3.70 −3.1% ±36% ⚪ within noise
octane-tsrx replace 7.59 8.91 +17.4% ±20% ⚪ within noise
octane-tsrx add 3.62 3.54 −2.2% ±20% ⚪ within noise
octane-tsrx update 0.50 0.46 −8.0% ±36% ⚪ within noise
octane-tsrx select 0.20 0.19 −5.0% ±82% ⚪ within noise
octane-tsrx swap 0.42 0.43 +2.4% ±45% ⚪ within noise
octane-tsrx remove 0.47 0.45 −4.3% ±82% ⚪ within noise
octane-tsrx runlots 33.84 32.53 −3.9% ±26% ⚪ within noise
octane-tsrx select_lots 0.29 0.29 −0.0% ±47% ⚪ within noise
octane-tsrx clear 48.15 47.91 −0.5% ±14% ⚪ within noise
octane-jsx run 3.84 3.68 −4.2% ±10% ⚪ within noise
octane-jsx replace 8.12 7.94 −2.2% ±21% ⚪ within noise
octane-jsx add 3.34 3.27 −2.1% ±8% ⚪ within noise
octane-jsx update 0.68 0.62 −8.8% ±33% ⚪ within noise
octane-jsx select 0.56 0.47 −16.1% ±58% ⚪ within noise
octane-jsx swap 0.88 0.70 −20.5% ±57% ⚪ within noise
octane-jsx remove 0.79 0.63 −20.3% ±53% ⚪ within noise
octane-jsx runlots 30.53 30.35 −0.6% ±24% ⚪ within noise
octane-jsx select_lots 2.47 3.01 +21.9% ±23% ⚪ within noise
octane-jsx clear 52.16 50.35 −3.5% ±20% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 126,850 126,869 +19 (+0.0%) 🔴
octane-tsrx js_gzip 41,978 41,989 +11 (+0.0%) 🔴
octane-tsrx js_brotli 37,005 36,964 −41 (−0.1%) 🟢
octane-tsrx app_gzip 2,563 2,561 −2 (−0.1%) 🟢
octane-tsrx app_brotli 2,226 2,225 −1 (−0.0%) 🟢
octane-tsrx fw_raw 119,338 119,357 +19 (+0.0%) 🔴
octane-tsrx fw_gzip 39,415 39,428 +13 (+0.0%) 🔴
octane-tsrx fw_brotli 34,779 34,739 −40 (−0.1%) 🟢
octane-tsrx todo_js_raw 142,237 142,256 +19 (+0.0%) 🔴
octane-tsrx todo_js_gzip 46,993 47,001 +8 (+0.0%) 🔴
octane-tsrx todo_js_brotli 41,173 41,221 +48 (+0.1%) 🔴
octane-tsrx todo_app_gzip 2,478 2,476 −2 (−0.1%) 🟢
octane-tsrx todo_app_brotli 2,121 2,119 −2 (−0.1%) 🟢
octane-tsrx todo_fw_raw 137,127 137,146 +19 (+0.0%) 🔴
octane-tsrx todo_fw_gzip 44,515 44,525 +10 (+0.0%) 🔴
octane-tsrx todo_fw_brotli 39,052 39,102 +50 (+0.1%) 🔴
octane-tsrx chat_js_raw 141,446 141,465 +19 (+0.0%) 🔴
octane-tsrx chat_js_gzip 46,937 46,944 +7 (+0.0%) 🔴
octane-tsrx chat_js_brotli 41,277 41,276 −1 (−0.0%) 🟢
octane-tsrx chat_app_gzip 2,978 2,976 −2 (−0.1%) 🟢
octane-tsrx chat_app_brotli 2,639 2,637 −2 (−0.1%) 🟢
octane-tsrx chat_fw_raw 134,793 134,812 +19 (+0.0%) 🔴
octane-tsrx chat_fw_gzip 43,959 43,968 +9 (+0.0%) 🔴
octane-tsrx chat_fw_brotli 38,638 38,639 +1 (+0.0%) 🔴
octane-tsrx weather_js_raw 178,412 178,431 +19 (+0.0%) 🔴
octane-tsrx weather_js_gzip 58,345 58,357 +12 (+0.0%) 🔴
octane-tsrx weather_js_brotli 50,794 50,779 −15 (−0.0%) 🟢
octane-tsrx weather_app_gzip 9,044 9,045 +1 (+0.0%) 🔴
octane-tsrx weather_app_brotli 7,580 7,590 +10 (+0.1%) 🔴
octane-tsrx weather_fw_raw 151,677 151,696 +19 (+0.0%) 🔴
octane-tsrx weather_fw_gzip 49,301 49,312 +11 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 43,214 43,189 −25 (−0.1%) 🟢
octane-jsx js_raw 226,725 226,744 +19 (+0.0%) 🔴
octane-jsx js_gzip 72,362 72,374 +12 (+0.0%) 🔴
octane-jsx js_brotli 62,642 62,637 −5 (−0.0%) 🟢
octane-jsx app_brotli 2,510 2,509 −1 (−0.0%) 🟢
octane-jsx fw_raw 218,266 218,285 +19 (+0.0%) 🔴
octane-jsx fw_gzip 69,426 69,438 +12 (+0.0%) 🔴
octane-jsx fw_brotli 60,132 60,128 −4 (−0.0%) 🟢

6 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 116,542 116,561 +19 (+0.0%) 🔴
cli-spa-starter gzip 39,358 39,366 +8 (+0.0%) 🔴
cli-spa-starter brotli 34,372 34,390 +18 (+0.1%) 🔴
root-static raw 203,053 203,072 +19 (+0.0%) 🔴
root-static gzip 64,558 64,568 +10 (+0.0%) 🔴
root-static brotli 55,909 55,988 +79 (+0.1%) 🔴
hydrate-root raw 171,116 171,776 +660 (+0.4%) 🔴
hydrate-root gzip 54,299 54,465 +166 (+0.3%) 🔴
hydrate-root brotli 47,409 47,531 +122 (+0.3%) 🔴
deferred-hydration raw 234,555 235,185 +630 (+0.3%) 🔴
deferred-hydration gzip 74,202 74,385 +183 (+0.2%) 🔴
deferred-hydration brotli 64,069 64,222 +153 (+0.2%) 🔴
suspense-transition raw 166,174 166,803 +629 (+0.4%) 🔴
suspense-transition gzip 53,406 53,588 +182 (+0.3%) 🔴
suspense-transition brotli 46,776 46,850 +74 (+0.2%) 🔴
binding-base-ui-vite raw 213,244 213,263 +19 (+0.0%) 🔴
binding-base-ui-vite gzip 68,126 68,137 +11 (+0.0%) 🔴
binding-base-ui-vite brotli 59,074 59,061 −13 (−0.0%) 🟢
binding-base-ui-esbuild raw 211,201 211,220 +19 (+0.0%) 🔴
binding-base-ui-esbuild gzip 68,109 68,119 +10 (+0.0%) 🔴
binding-base-ui-esbuild brotli 59,025 59,081 +56 (+0.1%) 🔴
binding-radix-vite raw 215,174 215,193 +19 (+0.0%) 🔴
binding-radix-vite gzip 68,698 68,707 +9 (+0.0%) 🔴
binding-radix-vite brotli 59,547 59,664 +117 (+0.2%) 🔴
binding-radix-esbuild raw 213,091 213,110 +19 (+0.0%) 🔴
binding-radix-esbuild gzip 68,697 68,708 +11 (+0.0%) 🔴
binding-radix-esbuild brotli 59,585 59,656 +71 (+0.1%) 🔴
binding-mantine-hooks-esbuild gzip 32,791 32,792 +1 (+0.0%) 🔴
binding-mantine-hooks-esbuild brotli 29,107 29,081 −26 (−0.1%) 🟢
binding-apollo-client-vite raw 358,299 358,318 +19 (+0.0%) 🔴
binding-apollo-client-vite gzip 112,252 112,263 +11 (+0.0%) 🔴
binding-apollo-client-vite brotli 97,943 97,966 +23 (+0.0%) 🔴
binding-apollo-client-esbuild raw 361,248 361,267 +19 (+0.0%) 🔴
binding-apollo-client-esbuild gzip 114,463 114,471 +8 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,622 99,629 +7 (+0.0%) 🔴
binding-usehooks-ts-esbuild brotli 29,268 29,244 −24 (−0.1%) 🟢

69 other measured values are unchanged.

trueadm and others added 3 commits October 3, 2026 00:53
The detach parameter on retainSignalRetryScope added 22 bytes to every
bundle that can reach root suspension, which put root-chained-jsx over its
budget. Only a restarted Suspense primary hands owners to a replacement, so
detach its scopes in a separate walk on that path. The facade's follows-inputs
predicate is also exported as a live binding rather than through a wrapper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A pending boundary that restarts with a changed selection kept the
abandoned attempt's request in flight until the boundary revealed, because
the kept cell staged the new selection as a private view. That cell was never
presented by a committed render. Supersession now marks the kept cells
provisional: until a render declaring them is accepted, a discarded render's
definition replaces the abandoned one, so the obsolete request is aborted as
soon as the restarted attempt suspends. This restores the pending native
stream contract in signals-pending-stream.test.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Nested query owners leak on restart
    • Passed includeHiddenTry=false to forEachSubtreeChild in retainSignalRetryScope and detachSignalRetryScope so nested Suspense boundaries' hidden primaries are not walked, preventing inner owners from leaking onto the outer boundary's cache.

Create PR

Or push these changes by commenting:

@cursor push ced00597bb
Preview (ced00597bb)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -698,7 +698,7 @@
 		}
 	}
 	if (subtree)
-		forEachSubtreeChild(scope, (child) => retainSignalRetryScope(child, root, holder, true));
+		forEachSubtreeChild(scope, (child) => retainSignalRetryScope(child, root, holder, true), false);
 	else if (scope.children !== null)
 		for (const child of scope.children) retainSignalRetryScope(child.scope, root, holder);
 }
@@ -709,7 +709,7 @@
 function detachSignalRetryScope(scope: Scope, cache: SignalRetryOwners): void {
 	const owner = SCOPE_SIGNAL_OWNERS.get(scope);
 	if (owner && cache.owners.has(owner)) SCOPE_SIGNAL_OWNERS.set(scope, false);
-	forEachSubtreeChild(scope, (child) => detachSignalRetryScope(child, cache));
+	forEachSubtreeChild(scope, (child) => detachSignalRetryScope(child, cache), false);
 }
 
 function clearSignalRetryOwners(holder: { retrySignalOwners?: SignalRetryOwners }): void {

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 4352a7a. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
trueadm and others added 4 commits October 3, 2026 01:39
…-over

The restart hand-over walked into nested Suspense primaries and parked their
owners in the outer boundary's retry cache. A nested primary claims only from
its own cache, so those owners were never reclaimed: the replacement started a
new load while the old nested request stayed in flight until the outer boundary
revealed. The hand-over now has its own walk, which stops at a non-propagating
nested boundary, as signalRetryBoundary does. Those owners stay mapped and
retire with the abandoned tree. The walk also replaces the separate detach pass.

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