Skip to content

fix(universal): keep live suspense replays across unrelated scheduled renders - #1299

Merged
trueadm merged 1 commit into
octanejs:mainfrom
aleclarson:fix/universal-settled-replay-cancel
Sep 24, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
aleclarson:fix/universal-settled-replay-cancel

Conversation

@aleclarson

@aleclarson aleclarson commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a universal-runtime bug where a scheduled re-render during a suspended
boundary permanently cancels the pending suspense replay, leaving @pending
content on screen forever after the promise resolves.

A committed @try/@pending boundary collects its thrown thenables and wires
them into a SuspendedMemoReplay: on settle, queueReplay() stores the replay
and queues a microtask. But prepare() unconditionally calls
cancelSuspendedReplays(true) before preparing its attempt — so when an
unrelated scheduled render runs in between (e.g. a useSyncExternalStore
notification or a sibling useState bump), it deactivates the queued replay.
runReplay() then early-returns, and when the render only re-executes a
scoped owner (prepareOwnedUpdate) or retains the suspended subtree because
its inputs look unchanged, nothing else ever re-attempts the region.

prepare() now detects a live non-transition replay for the same component
and hands its memo cache to the fresh attempt (prepareWithReplay with
allowRetain: false), so the render itself re-attempts the suspended regions:

  • Thenable already settled → the boundary resolves inside that commit.
  • Thenable still pending → the boundary re-suspends and republishes a fresh
    replay (memo entries keep the pinned thenable, so no refetch).

Transition replays keep their existing supersede semantics — they are still
cancelled and their batches requeued so the transition lane re-attempts them.

Validation

  • pnpm format:check
  • pnpm typecheck (typecheck:files on changed files — clean)
  • pnpm test
  • targeted tests:
    • packages/octane/tests/universal-external-store.test.ts — 2 new regression
      tests (settled replay + pending replay across an unrelated store update);
      red without the fix, green with it (dev + prod projects)
    • All 46 universal-* test files: 818 tests green in dev + prod
    • Full packages/octane suite: 24,966 pass; 31 failures in
      behavior-root, hydration-ssr-diagnostics, compiler/*, and
      browser/* files — none import universal code (verified); timeouts
      appear environmental/pre-existing on this base

Not verified on a NativeScript device; fix is at the universal-runtime layer
the NS driver consumes.

Risk / follow-ups

While a replay is live, scheduled renders skip the scoped-owner fast path and
subtree retention for the affected root (a full re-execution, same as
runReplay would have done). The cost is bounded to the suspension episode
and only when a live replay exists.

Provenance

  • An agent produced this diff (agent-authored)

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
Touches core universal render preparation and Suspense replay lifecycle; wrong handling could affect transitions, retention, or stuck pending UI, but scope is limited to non-transition replays and is covered by new tests.

Overview
Fixes a universal runtime bug where an unrelated scheduled render could cancel a queued Suspense replay and leave @pending UI stuck after its promise had already resolved.

prepare() now finds an active non-transition replay for the same root component via absorbableReplay(), passes its memo cache into prepareWithReplay, and turns off subtree retention for that attempt so suspended regions are re-executed in the same commit. Settled boundaries can commit their resolved content; still-pending ones re-suspend and publish a new replay. Transition replays are unchanged—they are still cancelled and requeued.

While a live replay is present, the scoped-owner shortcut and retain-eligible fast paths are skipped so the retry is not dropped. Two regression tests in universal-external-store.test.ts cover settled and still-pending replays racing an external-store-driven render.

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

… renders

A committed @try/@pending boundary wires its thrown thenables into a local
replay that re-renders with the pinned memo cache once they settle. The next
scheduled render unconditionally deactivated that replay before preparing its
own attempt, so when the render only re-executed a scoped owner — or retained
the suspended subtree because its inputs looked unchanged — nothing else ever
re-attempted the region and pending content stayed on screen after its
thenable had already resolved.

prepare() now hands a live non-transition replay's memo cache to the fresh
attempt and disables retention for it, so the render itself re-attempts the
suspended regions: a settled boundary resolves inside that commit, and one
still waiting re-suspends and republishes a fresh replay. Transition replays
keep their existing supersede semantics.
@aleclarson
aleclarson marked this pull request as ready for review September 24, 2026 04:03
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 24, 2026
@trueadm
trueadm merged commit 47580bd into octanejs:main Sep 24, 2026
46 of 49 checks passed
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.

2 participants