Repository navigation
fix(universal): pace Suspense retries on an already-settled thenable - #1404
Merged
Merged
Conversation
A universal retry that suspended again on a thenable whose settlement had already been observed re-rendered on that thenable's next microtask, forever. This happens when a thenable's owner publishes its status on a later task, or when a reverse-region DOM child routes the same suspension back to its universal owner on every commit. Timers and native callbacks never ran, so the state that would end the suspension never arrived and the root livelocked. Boundary and hidden-Activity replays, root and transition suspensions, and routed renderer- region suspensions all looped. Every universal resume subscription now goes through resumeOnSettle, the same design as the DOM runtime. A first settlement still retries on its microtask. A thenable whose settlement was already seen still subscribes through then, so a reusable custom wakeable is not polled, and then retries after one macrotask, as React's Scheduler ping does. The urgent-projection release is paced the same way: releasing it on the microtask lets a DOM-hosted root with held transition work re-prepare, suspend on the same thenable, and loop. Universal use() also stops rewriting a thenable status it did not set. It used to replace a status React does not recognize, such as router-core's 'resolved', with its own tracking. It now leaves it alone and treats the thenable as pending, matching React's trackUsedThenable and the DOM runtime. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With #1400 on main, a universal root inside a DOM Suspense boundary is paced by both runtimes' resume subscriptions. Cover it directly: a projected root suspension, and one that holds a transition. The second fails if the urgent projection is released on the microtask, which is the only regression test for that pacing. Link the universal contract from SUSPENSE_DIVERGENCE §13. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The universal renderer (
octane/universal, used by Lynx, three, ink and opentui) had the same Suspense retry livelock that #1400 fixed in the DOM runtime. A retry that suspended again on a thenable whose settlement had already been observed re-rendered on that thenable's next microtask, forever. Timers and native callbacks never ran, so the state that would end the suspension never arrived.It is reachable when a thenable's owner publishes its
statuson a later task. It is also reachable when a reverse-region DOM child re-suspends on every host commit and routes the suspension back to its universal owner. Boundary and hidden-Activity replays, root suspensions without a boundary, held transitions, routed renderer-region suspensions, and universal roots inside a DOM Suspense boundary all looped.Changes
packages/octane/src/universal-core.tsaddsresumeOnSettle, the same design as fix(octane): pace Suspense retries on an already-settled wakeable #1400. A lazyWeakSetrecords wakeables whose settlement a resume listener has seen, and the decision is made when the listener is attached. A first settlement still retries on its microtask. A thenable already seen to settle still subscribes throughthen, so a reusable custom wakeable is not polled, and then retries after one macrotask, as React's Scheduler ping does.publishLocalReplay(boundary and hidden Activity),routeUniversalOwnerSuspense(reverse-region DOM children), andreleaseProjectioninsuspend(). The last one matters. Released on the microtask, it lets a DOM-hosted root with held transition work re-prepare and suspend on the same thenable again.use()change:trackUniversalThenableno longer rewrites astatusit did not set. It used to replace an unrecognized status, such as router-core's'resolved', with its own'pending'/'fulfilled'tracking, which writes to a field another library owns. History shows no rationale: it arrived with the Lynx scaffolding (Add Lynx Phase 1 native scaffolding #180), with no comment, doc or test. It now leaves the status alone and treats the thenable as pending, matching React'strackUsedThenableand the DOM runtime. The visible change: universaluse()of a'resolved'-status thenable stays suspended, with paced retries, instead of revealing after one microtask. The changeset calls this out.SUSPENSE_DIVERGENCE.md§13, and the contract indocs/universal-renderer-architecture.md§6.main, including fix(octane): pace Suspense retries on an already-settled wakeable #1400. A universal root inside a DOM boundary resumes through both runtimes, so its tests need both fixes.Validation
pnpm format:check: not run repo-wide;pnpm format:files:checkon every changed file passes.pnpm syncmakes no changes.pnpm typecheck: not run in full;tsgo -p packages/octane/tsconfig.json,tsgo -p packages/lynx/tsconfig.json,tsgo -p packages/lynx/tsconfig.testing.jsonandtsrx-tsc -p packages/three/tsconfig.jsonall pass.pnpm test: not run in full. The projects this change reaches were run on the merged head instead:octane+octane-prod: 24,659 / 24,661 pass. Under full-suite load, twobehavior-root.test.tstextarea-retirement tests hit the 5 s timeout. In an earlier run it was onehydration/independent-parent.test.tsactivation-timing assertion. Neither file touches universal code, and both pass 478/478 in isolation on repeated runs in both projects.lynx(404),three+three-differential(142),ink+ink-differential(30),opentui(4): all pass.tests/universal-settled-wakeable.test.ts, 12 tests, run in bothoctaneandoctane-prod. It uses a compiled.object.tsrxfixture, a hand-written reverse-region scene, and the existing DOM@pendinghost-boundary fixture.'resolved'status, root, transition, hidden Activity, and routed renderer region. Both DOM-hosted tests also fail there.releaseProjection(caught only by the DOM-hosted held-transition test) andtrackUniversalThenable. So does each rejected design: deciding when the listener fires, skippingthenfor settled thenables, and pacing every retry.node benchmarks/bundle-size/run-minimal.mjs: identical across every scenario. None of them reaches universal-core.Risk / follow-ups
flushUniversalActdoes not drain it, the same asact()for fix(octane): pace Suspense retries on an already-settled wakeable #1400. No existing Lynx, three, ink or opentui test relied on microtask re-suspension converging.useBatchmakes a fresh combined promise for two or more pending members, so a batch of two or more lagging-status thenables still retries on microtasks. The DOM runtime has the same gap.packages/lynx/src/main-renderer.ts) keeps its own copy of the status overwrite. It renders once and never retries, so it cannot loop.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes universal Suspense scheduling and
use()thenable handling on Lynx/universal paths; behavior shifts for unrecognizedstatusvalues, but scope is bounded to suspension retries with strong regression tests.Overview
Fixes a Suspense livelock in the universal renderer (Lynx and other
octane/universaltargets) when a retry keeps suspending on a thenable that already settled. Retries used to run on that thenable’s next microtask, starving timers and native callbacks so the UI never recovered.Runtime (
universal-core.ts): AddsresumeOnSettle(same idea as the DOM fix in #1400): aWeakSetremembers wakeables whose settlement was already observed. First settlement still retries on a microtask; subsequent retries wait for the nextthennotification, thensetTimeout(0)once. All universal resume paths go through it—suspended attempts, local/root replays, reverse-region owner routing, and DOM-bridgereleaseProjection(so held transition work doesn’t re-suspend on the microtask).use():trackUniversalThenableonly tags thenables with nostatus; it no longer overwrites foreign statuses (e.g. router-core'resolved') and treats them as pending, aligned with React’strackUsedThenable.Docs and
SUSPENSE_DIVERGENCE.mddescribe the contract;universal-settled-wakeable.test.tscovers boundaries, roots, transitions, hidden Activity, DOM-hosted roots, and custom wakeables.Reviewed by Cursor Bugbot for commit a331160. Bugbot is set up for automated code reviews on this repo. Configure here.