Repository navigation
fix(octane): publish resumed hydration events on acceptance - #2193
Conversation
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)
13 other measured values are unchanged. Public-import reachability bundles (bytes)
39 other measured values are unchanged. |
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 1b7cecc. Configure here.
…ransition 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]>
* 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
When a suspended hydration arm resumes during an event and then suspends again or is discarded, handlers written during that speculative attempt can receive the in-flight event. Stage resumed-arm event authority with the capture and publish surviving handlers at root acceptance, before mutation callbacks. Native custom-element listeners retain their original callback identity; repeated writes publish only the final surviving value.
A parked reveal forwards its staged handlers to the root. If native registration then fails, recover the affected arm and retry the exact restored reveal without reviving an already released transition hold or clearing another root's pending state. When a sibling releases a ready boundary inside an active same-root transaction, journal the parked slot and its actions before consuming the reveal.
Validation
pnpm format:checkon the implementation commit; scoped formatting passed on the final feedback fix.pnpm typecheck— full workspace typecheck could not complete with the filtered local install. Production-source scoped typecheck passed; selecting the new test also reports two pre-existing exact-optional-property errors intests/_server-fixture.ts, unchanged from the upstream base.pnpm test— the full command stopped in the Visx declaration precheck before Vitest; the filtered local install was required because an unrelated workspace tarball returned HTTP 403.1b7ceccdf; all four passed after journaling the nested reveal.pnpm syncpassed before publication.a9e731528; the Chromium job passed on one targeted rerun after the first attempt timed out in an unrelated fixture setup.At
a9e731528, matched complete Vite/Oxc executable bundle gzip deltas versus upstream119f1059fa508a44751fcb0aee6f7e7e2741a134: root-static +78 B, prop-attributes +87 B, hydrate-root +1,075 B, suspense-transition +197 B; all eight executable checks passed. In synthetic Chromium cohorts with 128 handlers, median synchronous resumed hydration increased from 20.0 to 76.7 microseconds for delegated handlers (paired ratio 3.82, 95% interval 3.64–4.00) and from 40.0 to 55.0 microseconds for native custom-element handlers (1.42, 1.32–1.55). Ordinary-mount medians matched, no-listener controls showed no clear difference, and identity and delivery checks passed. These success-path measurements exclude setup and paint; they do not time registration failure or parked-reveal recovery and do not establish application latency.Risk / follow-ups
Deferring native registration can change listener order relative to third-party registrations during render, including
stopImmediatePropagationbehavior, and shifts registration errors to acceptance. Superseded transient registrations no longer run their host-side effects. The design preserves native callback identity and external deduplication; it does not promise general atomic rollback of arbitrary host operations. Hosts whose internal event slots cannot be safely staged retain the existing immediate-write behavior. The measured resumed-handler overhead is material in relative terms, and the final recovery code adds a small common-path bundle cost; both need maintainer judgment. This change does not address retention across changed forwarded inputs.Provenance
agent-authored)Need help on this PR? Tag
@codesmith-botwith what you need.Note
High Risk
Touches hydration commit ordering, event handler publication, and custom-element listener registration—security- and behavior-sensitive paths where registration timing and failure recovery can change listener order and error surfacing.
Overview
Fixes a hydration bug where speculative resumed arms could install event handlers that still ran for an in-flight DOM event, even when that attempt was later suspended again or discarded.
During resumed suspense hydration, delegated handlers,
$$signalOwner, and custom-elementon*listeners are staged on the offscreen capture (hostEvents) instead of going live immediately.acceptHydrationHostEventspublishes them at root acceptance, before mutation-phase commit work, with journal undo and arm-level recovery when native registration throws. Discarded captures drop staged host events; splicing merges them into enclosing work like other capture queues.Custom-element listener setup moves to
setCustomElementListener; deferred registration can run after third-party listeners added during render (documented in the changeset).evt*paths route throughsetEventHandlerwhen recovery is active so bundles are not written directly during speculative render.Adds focused hydration tests for in-flight delivery, discarded listeners, native identity/dedup, render-phase listener swaps, registration failure recovery, and independent earlier-arm commits.
Reviewed by Cursor Bugbot for commit 57cb302. Bugbot is set up for automated code reviews on this repo. Configure here.