Skip to content

fix(octane): render a deferred value's final attempt while a root holds its first render - #2223

Merged
trueadm merged 4 commits into
feat/parallel-transitions-mainfrom
fix/deferred-root-attempt
Oct 23, 2026
Merged

trueadm merged 4 commits into
feat/parallel-transitions-mainfrom
fix/deferred-root-attempt

Conversation

@trueadm

@trueadm trueadm commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Why

  • With a @try/@pending boundary, Octane already switched to the final value (:484). Without one, the root rolls back its whole first attempt. That disposes the slot that spawned the deferred swap, and swapDeferredValue dropped swaps for disposed slots. Root suspension without a boundary has been supported since Retain and retry a suspended root when no Suspense boundary is present #821, so the old "N/A: requires a parked root render" note was stale.
  • None of this comes from a documented divergence. Octane still posts the deferred render in a host task, and it never pre-warms. The ported tests assert only committed DOM, not React's pre-warm logs.
  • The fix doesn't depend on feat(octane): commit unrelated transitions independently #2222's reveal-group changes; it applies on main as well.

Changes

  • swapDeferredValue (runtime/engine.ts): when the slot's Block is disposed and its root is still waiting for its first commit, it calls owner.retry(true) instead of returning. The condition is owner.wakeable !== null and owner.current is null or disposed; a transition mount leaves a disposed root Block between attempts.
  • RootRenderOwner.retry(deferred?) and renderResolved(…, deferred): a deferred retry mounts directly at transition priority with pendingDeferred set. A useDeferredValue mounting inside that pass adopts its final value through the existing anti-waterfall rule.
  • suspendRootRender (runtime/render.ts): a suspension inside a deferred pass also wakes on the wakeable of the attempt that spawned it. Either attempt can then commit first. The value is read before the rollback, because disposing the root Block clears it.
  • Tests:
    • the two React 19.3.0 cases in conformance/parallel-transitions.test.ts (fixture DeferredSiblings);
    • :407, :526, and a transition-mount variant of :407 in conformance/deferred-value.test.ts;
    • the accounting comment and the conformance ledger are updated, and docs/react-parity-coverage.md is regenerated.

Validation

  • pnpm format:check: not run; changed files were formatted with pnpm format:files.
  • pnpm typecheck: not run. pnpm typecheck:files passes on the three changed runtime files.
  • pnpm test: not run locally. CI doesn't run on this PR while its base is feat/parallel-transitions-main: ci.yml filters PRs to main, next and jon/update-bindings-*. CI runs once it targets main.
  • targeted tests on top of feat(octane): commit unrelated transitions independently #2222: parallel-transitions.test.ts and deferred-value.test.ts pass in octane and octane-prod (54/54).
    • Before the fix: the 19.3.0 "final value's sibling loads first" case, :407, and the transition-mount case fail in both projects.
    • With only the swap change (no wakeable union): :526 and the 19.3.0 "original sibling loads first" case fail (checked on main), so those two pin the neighbouring behavior.
    • Without the disposed-root condition: the transition-mount case fails.
  • pnpm react-parity:validate: metadata current.
  • pnpm sync: no generated changes.
  • perf-review: this PR's diff scans clean (git diff origin/feat/parallel-transitions-main...HEAD | node scripts/perf-review-scan.mjs --diff -).
    • Hand review: the new branch in swapDeferredValue runs only for a disposed slot (cold). pendingDeferred is a declared BlockImpl boolean set once per root mount, so there is no shape change. The retry closure is still one per root.render(). suspendRootRender adds one field read, plus one resumeOnSettle only for a deferred pass. No compiled output, imports, or reachability changes.
  • concise-code: src +27 −5 (all runtime). No new files or exports outside test fixtures.
    • Alternatives rejected: documenting a divergence (the boundary case already behaves like React, so the root case was a gap, not a choice); queueing the deferred attempt as a transition mount (its empty queuing commit clears the original wakeable and leaves a disposed root Block); covering committed roots too (see follow-ups).
    • Bytes: see the CI bench report once CI runs.

Risk / follow-ups

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.


Note

High Risk
Touches root suspension, deferred-value scheduling, and commit/retry ordering in the reconciler—behavior that affects first paint and transition mounts without a Suspense boundary.

Overview
Aligns useDeferredValue with React when a root has no Suspense boundary: a suspended first render on the initial value now also schedules a deferred final-value attempt, and whichever attempt’s data is ready first commits (including transition mounts and dual-hook roots).

Runtime: swapDeferredValue no longer drops swaps when the spawning block was rolled back on root suspend—it returns the held root so runDeferredSwaps can call retry(true) once per root. Root retry(deferred) / renderResolved mount deferred passes with pendingDeferred, and suspendRootRender registers wakeables for both the current deferred pass and the spawning attempt.

Conformance: Ports upstream ReactDeferredValue-test.js cases previously marked N/A (:407, :526) plus React 19.3 sibling-resolution cases in deferred-value.test.ts and parallel-transitions.test.ts; ledger and parity docs move those entries to covered.

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

@trueadm
trueadm marked this pull request as ready for review October 23, 2026 17:48
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 23, 2026
@trueadm
trueadm marked this pull request as draft October 23, 2026 17:49
…ds its first render

When a root with no Suspense boundary suspends on its first render, a
useDeferredValue mounted with an initialValue spawned its swap, but the
rollback disposed the slot and the swap was dropped. The final value
never rendered until the preview fully loaded.

The swap now renders the root again as a deferred pass in its host task.
Its suspension keeps the original attempt's wakeable live, so whichever
attempt is ready first commits, as in React 19.3 (react/react#35392).

Ports the two React 19.3.0 ReactDeferredValue-test.js sibling cases into
parallel-transitions.test.ts, and :407 and :526 into deferred-value.test.ts,
asserting committed DOM.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm force-pushed the fix/deferred-root-attempt branch from e4af203 to 8c6ea66 Compare October 23, 2026 17:51
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp b0af5ed Commit Preview URL

Branch Preview URL
Oct 23 2026, 07:07 PM

@trueadm
trueadm changed the base branch from main to feat/parallel-transitions-main October 23, 2026 17:52
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website b0af5ed Commit Preview URL

Branch Preview URL
Oct 23 2026, 07:09 PM

@trueadm
trueadm marked this pull request as ready for review October 23, 2026 18:39
…into fix/deferred-root-attempt

# Conflicts:
#	packages/octane/tests/conformance/_fixtures/parallel-transitions.tsrx
#	packages/octane/tests/conformance/parallel-transitions.test.ts

@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: Duplicate deferred retries drop original wakeable
    • Added per-owner deduplication in runDeferredSwaps using a Set so that when multiple disposed useDeferredValue slots share the same root owner, only the first calls owner.retry(true), preventing subsequent retries from invalidating the first attempt's generation and orphaning the original wakeable's ping.

Create PR

Or push these changes by commenting:

@cursor push d7b9b98eeb
Preview (d7b9b98eeb)
diff --git a/packages/octane/src/runtime/engine.ts b/packages/octane/src/runtime/engine.ts
--- a/packages/octane/src/runtime/engine.ts
+++ b/packages/octane/src/runtime/engine.ts
@@ -5031,6 +5031,7 @@
  * is queued (spawnDeferredSwap). Async act() keeps draining while it is set.
  */
 let DEFERRED_SWAPS: Array<DeferredSlot<any>> | null = null;
+let DEFERRED_RETRIED: Set<RootRenderOwner> | undefined;
 
 /**
  * Schedule the deferred current→next swap in a later host task (#1864). A
@@ -5071,6 +5072,7 @@
 		for (let i = 0; i < slots.length; i++) swapDeferredValue(slots[i]);
 	} finally {
 		TRANSITION_TASK_ACTIVE = false;
+		DEFERRED_RETRIED = undefined;
 	}
 }
 
@@ -5087,9 +5089,12 @@
 		if (
 			owner !== undefined &&
 			owner.wakeable !== null &&
-			(owner.current === null || owner.current.disposed)
-		)
+			(owner.current === null || owner.current.disposed) &&
+			!(DEFERRED_RETRIED ??= new Set()).has(owner)
+		) {
+			DEFERRED_RETRIED.add(owner);
 			owner.retry(true);
+		}
 		return;
 	}
 	if (Object.is(s.value, s.next)) return;

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

Reviewed by Cursor Bugbot for commit b7c7baa. Configure here.

Comment thread packages/octane/src/runtime/engine.ts Resolved
Each disposed useDeferredValue slot from a rolled-back root render called
owner.retry(true) on its own. With two such hooks, the second deferred
attempt rolled back the first and unioned only its wakeable, so the
original attempt's data no longer retried the root and the initial
values never committed. Collect held roots and retry each once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 801a51d into feat/parallel-transitions-main Oct 23, 2026
5 checks passed
@trueadm
trueadm deleted the fix/deferred-root-attempt branch October 23, 2026 20:35
trueadm added a commit that referenced this pull request Oct 23, 2026
trueadm added a commit that referenced this pull request Oct 23, 2026
* fix(runtime): scope optimistic cleanup to transition batches

* fix(runtime): keep optimistic reverts out of cross-render diagnosis

A transition batch can finish while a Suspense boundary renders: an urgent
update that supersedes a held transition releases the hold inside the
boundary's render (releaseHeldTransition -> releaseTransitionHookHolder ->
finishTransitionHookBatch). The batch-scoped useOptimistic revert then
scheduled its block while another component was on the stack, so dev logged
"Cannot update a component while rendering a different component" and the
block was flagged as a cross-render update. The global listener this
replaced ran under the publish-depth guard; schedule the revert under it
again via scheduleHookPublication.

Also update the TRANSITION_PENDING_COUNT comment: optimistic lifetimes no
longer subscribe to it.

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

* feat(octane): commit unrelated transitions independently

Re-lands #2165 on main. It merged into `next` on 2026-10-20, after
#2103 had already integrated `next` into `main`, and `next` was then
deleted, so the change never reached `main`.

This is the #2165 squash commit (2af686e) without its useOptimistic
fix: #2218 scopes optimistic reverts to their transition batch, so this
change builds on it rather than adding a second mechanism.

React 19.3 renders each transition lane on its own, so a suspended
transition no longer holds back an unrelated one:

- The reveal barrier groups held boundaries that hold a common batch
  (stagedRevealGroup), so one transition's boundaries still reveal
  together while unrelated groups commit on their own, each once per
  flush.
- A held boundary still on screen retries its batches when any thenable
  it suspended on settles, keeping the fresher thenable's resume and
  fallback timeout.

Refs #2053.

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

* fix(octane): give boundaries without a batch hold their own reveal group

stagedRevealGroup put every held boundary without a batch hold into
every group. That one rule covered three different cases: a transition
that folded no hook work (`root.render` in startTransition), a holder
released during its retry, and members of a view-transition-deferred
reveal. So unrelated groups were pulled together: a hook transition
waited behind an unrelated root.render transition, and a deferred group
could be absorbed into another flush.

Boundaries without a batch hold now form one group of their own, the
barrier before parallel transitions, and never join a batch's group.

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

* fix(octane): render a deferred value's final attempt while a root holds its first render (#2223)

* fix(octane): render a deferred value's final attempt while a root holds its first render

When a root with no Suspense boundary suspends on its first render, a
useDeferredValue mounted with an initialValue spawned its swap, but the
rollback disposed the slot and the swap was dropped. The final value
never rendered until the preview fully loaded.

The swap now renders the root again as a deferred pass in its host task.
Its suspension keeps the original attempt's wakeable live, so whichever
attempt is ready first commits, as in React 19.3 (react/react#35392).

Ports the two React 19.3.0 ReactDeferredValue-test.js sibling cases into
parallel-transitions.test.ts, and :407 and :526 into deferred-value.test.ts,
asserting committed DOM.

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

* fix(octane): retry a held root's deferred attempt once per swap task

Each disposed useDeferredValue slot from a rolled-back root render called
owner.retry(true) on its own. With two such hooks, the second deferred
attempt rolled back the first and unioned only its wakeable, so the
original attempt's data no longer retried the root and the initial
values never committed. Collect held roots and retry each once.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

* test(octane): reveal a parked hydration boundary while an unrelated transition holds

The sibling case from #2193 expected Gate's ready reveal to wait for
Later's unrelated transition, the global barrier from before parallel
transitions. Gate's root.render transition and Later's setLater
transition are separate, so Gate now reveals once its own data lands
while Later keeps holding; the primary, listener and event assertions
run at that point.

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

---------

Co-authored-by: dannyward630 <[email protected]>
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