Repository navigation
fix(runtime): scope optimistic reverts to transition batches - #2218
Conversation
Benchmark report
Compares js-framework: 1k/10k row operations
All 20 timed operations (19 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
57 other measured values are unchanged. Public-import reachability bundles (bytes)
84 other measured values are unchanged. |
…uspense-rollback Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
…n render A transition render that folds a batch's state updates now skips that batch's useOptimistic values and drops them at commit, as React reverts an optimistic update in its transition's lane. Previously the values stayed queued until the batch finished, so held work that a timeout fallback (setTransitionFallbackTimeout) let commit showed the new state with the optimistic delta applied twice until the boundary resolved. Urgent renders still show every queued value, matching React's urgent optimistic lane, and a dropped transition render discards the drop, so a held batch keeps its values. The finish listener still clears values for batches whose owner never re-renders. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.
Reviewed by Cursor Bugbot for commit 9f54d1c. Configure here.
Between a timeout fallback releasing held work and its retry task, an urgent render folds the ready batch (foldHookQueue) while the batch's hold stays open, so it does not finish in that drain. useOptimistic kept the batch's values in urgent renders and painted the delta twice (saved 1, optimistic 12 instead of 11). An urgent render now skips and drops a batch's values when it folds a ready batch that still has an open hold, which can only be a timeout fallback. Other urgent renders keep showing them, as React renders optimistic values urgently; transition-flush-task's ancestor-cue parity test pins that, and a no-hold batch folded urgently finishes in the same drain. Co-Authored-By: Claude Opus 5.5 <[email protected]>
main now has #2218 (squashed) and #2221. The conflicts were in #2218's own files, actions.ts and actions.test.ts, which this branch carried at #2218's earlier head; they take main's version. #2218's later commits revert a transition's optimistic values once a timeout fallback lets its batch commit around the fallback, so the behind-the-fallback case now pins only isPending, and leaves the optimistic value to that rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* 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]>

Summary
useOptimisticupdate to the transition batch that created it.Why
Changes
octanepatch changeset.scheduleHookPublication). A batch can finish inside a Suspense boundary's render when an urgent update supersedes a held transition, and the old global listener ran under that guard too. Regression:reverts without a cross-render warning when an urgent update supersedes its transition.setTransitionFallbackTimeout) lets held work commit:saved1 / optimistic 2 until the boundary resolved, also present onmain. Regression:reverts with the held work a timeout fallback lets commit (urgentFirst=false).saved1 / optimistic 12 instead of 11. Other urgent renders keep showing optimistic values, as React does. Regression:… (urgentFirst=true).Validation
pnpm sync— passed.node scripts/split-runtime.mjs check— 34 modules, 0 violations.git diff --check— passed.node scripts/check-changesets.jsandnode scripts/check-release-plan.mjs— passed.tests/actions.test.ts— 33/33 in development and production compilation;tests/conformance/async-actions.test.ts— 10/10 in development.typecheck-files— 4 changed runtime TypeScript files passed.pnpm format:check,pnpm typecheck, andpnpm test— not run locally; targeted checks above were used.d466f6f1dd(after mergingmainatf47ddbf2b2):4c60a254ac, loggingCannot update a component (`OptimisticSupersededTransition`) while rendering a different component (`SupersededValue`). It passes onmain's runtime and with the fix.tests/actions.test.ts: 34/34 inoctaneandoctane-prod.transitions,transition-hook-pending,transition-action-order,transition-urgent-equality,transition-timeout,conformance/async-actions— 178/178 inoctane.split-runtime check(0 violations) andpnpm sync(no changes) pass.typecheck:filesreports no errors in the changed source or the added test code; the errors it does report are on pre-existing untyped fixtures and thesubmithelper.heavy integration, was a wall-clock bound incompiler-vite-options.test.ts(6.19 s against a 6 s limit). It is unrelated to this diff, and the push reruns it.9f54d1c491(Bugbot's timeout-reveal finding):2, expected1). It also fails with only the commit-time drop removed (12, expected11).tests/actions.test.tsandconformance/async-actions.test.ts: 90/90 inoctaneandoctane-prod.transitions, everytransition-*,signals-action-lifecycle,fresh-root-scope-holdandeffect-event-actions: 248/248 inoctane. An earlier version that also skipped values in urgent renders failedtransition-flush-task's "commits an optimistic value with the child's previous state", so urgent renders keep them.split-runtime check,pnpm syncand sourcetypecheck:filespass.c6533647e0(Bugbot's urgent-fold finding):urgentFirst=truefails without the hold clause (12, expected11).octaneandoctane-prod.octane.perf-review(follow-up): the scan's only candidate is the existing unowned-revert microtask above. The guard adds one counter increment and decrement per optimistic revert, which runs once per finished batch per hook and is not a per-render path.concise-code(follow-up): +10 runtime lines. The rejected alternative wrapspublishTransitionBatchFinishedin the guard, but the depth counter is private toengine.ts, so that needs exported increment and decrement helpers.Perf review: issue #1348
Scan:
node scripts/perf-review-scan.mjs→ 1 candidate.Hot paths touched:
useOptimistic's render fold is unchanged; owner tracking runs on optimistic dispatch; queue compaction and callback publication run when a transition batch finishes.packages/octane/src/runtime/actions.ts:771No dedicated
useOptimisticallocation benchmark is present, so no local performance claim is made. The batch callback set and owner array add bounded per-batch/per-hook state; the render-time value fold stays unchanged.Concise-code
onTransitionBatchFinished, used byuseOptimistic.Risk / follow-ups
Provenance
agent-authored)Need help on this PR? Tag
@codesmith-botwith what you need.Note
Medium Risk
Touches transition batch lifecycle and render/commit folding for optimistic state—core React 19 actions behavior with several edge paths (Suspense, timeout fallback, urgent supersede), though changes are localized and heavily regression-tested.
Overview
Fixes
useOptimisticlifetime so it follows the transition batch that created each update, not the global transition pending count (issue #1348).Each queued optimistic value is tagged with its owning
TransitionActionBatch. The hook subscribes viaonTransitionBatchFinishedand compacts only that batch’s entries when that batch’s work and holds finish, so unrelated pending transitions no longer clear or prolong optimistic UI incorrectly. UnownedaddOptimisticcalls still revert on a microtask burst.On render, batch-owned values are skipped when a transition render folds their batch (or when a timeout fallback left a hold open on an urgent path), with queue cleanup at commit via
TRANSITION_ROOT_DRIVER.foldandatCommit—matching React’s revert lane and avoiding double-counted optimistic state after partial commits. Revert refreshes usescheduleHookPublicationinstead of the removed globalTRANSITION_LISTENERSontickTransitionCount.Adds regression tests for Suspense holds, an unrelated suspended root, transition-timeout fallback, and urgent supersede without cross-render warnings; includes an
octanepatch changeset.Reviewed by Cursor Bugbot for commit c653364. Bugbot is set up for automated code reviews on this repo. Configure here.