Repository navigation
fix(tanstack-router): keep route matches suspended across match states - #1397
Merged
Merged
Conversation
MatchInner suspended through use() on a different router promise per match state. use() is positional, so after a state change a replay received the promise stored for the earlier state. Router-core's controlled promises settle to status 'resolved', which use() reads as pending, so the stored promise re-suspended on every retry, on a microtask, starving the timers and network callbacks the loader needed. Throw the relevant promise instead, as upstream does. A redirected match waits for its next store update rather than its already-resolved loadPromise, which would otherwise spin until the redirect target loads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…table-match-suspension
trueadm
marked this pull request as ready for review
September 29, 2026 13:26
This was referenced Sep 29, 2026
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
MatchInnerin@octanejs/tanstack-routersuspended throughuse(), on a different router promise for each match state:displayPendingPromise,minPendingPromise, orloadPromiseforpendingandredirected. Octane'suse(thenable)is positional. During a resume replay, a thenable at an occupied position is replaced by the stored one, the same as React 19'strackUsedThenable. So when a suspended match changed state, the replay got back the promise stored for the earlier state.The suspected failure was a render without loader data. With router-core's real promises it is a livelock instead.
createControlledPromisesettles tostatus: 'resolved', not React's'fulfilled', souse()reads the stored promise as still pending. Every retry suspends on it again, the settled promise wakes the boundary on the next microtask, and the loop starves the timers and network callbacks the loader needs to finish.Two consumer paths hit it:
ssr: falseroute with a slow client loader. router-core'shydrate()sets_forcePendingwith aminPendingPromise. WhenpendingMinMselapses before the client loader resolves, the replay'suse(loadPromise)lands on the stored, settledminPendingPromiseand the page locks up.handleRedirectAndNotFoundresolves the match'sloadPromisewhen it marks the matchredirected.use()then re-suspends on that settled promise on every microtask until the redirect target commits, and the target cannot load while the loop runs.Related: #1381, fixed for tanstack-query in #1390.
Changes
MatchInnernow throws the relevant promise instead of callinguse(), as upstream does. A thrown promise has no position, so a replay always suspends on the promise for the current state. Coreuse()semantics are unchanged.redirectedmatch waits for its next match-store update instead of itsloadPromise, which router-core has already resolved. That promise would otherwise retry on microtasks until the redirect target loads, starving that load's timers and network callbacks. React's scheduler paces the same retry for upstream; Octane's retry does not. Server atoms have nosubscribe, so the server keeps upstream'sloadPromise; Start answers server redirects before rendering.tests/conformance/match-suspension.test.tswith fixturetests/_fixtures/match-suspension.tsrx:hydrate()andRouterClientwith anssr: falseroute whose client loader outlastspendingMinMs.router.getMatchreads, so a regression fails in about a second instead of hanging the worker. A test timeout cannot fire during a microtask livelock.packages/tanstack-router/audit/test-classifications.json.@octanejs/tanstack-router.Validation
pnpm format:check(not run repo-wide;pnpm format:files:checkon the changed files passes)pnpm typecheck(not run repo-wide;pnpm typecheck:fileson the changed files passes viatsrx-tsc)pnpm test(not run in full; targeted projects below)vitest run --project tanstack-router --project tanstack-router-ssr --project tanstack-router-differential --project tanstack-router-ssr-query, 19 files / 105 tests passinghmr: false: thetanstack-routerproject re-run through a scratch config withoctane({ hmr: false }), 16 files / 89 tests passingpnpm react-parity:validate,pnpm changeset:check, andpnpm sync(clean)hmr: false: against the originaluse()code, both new tests trip the render-loop guard; without the guard the worker spun at 100% CPU until killed. Two other broken variants also fail. A literal upstream port that throwsloadPromiseforredirectedfails the redirect test the same way. A singleuse()on the currently relevant promise at one fixed position fails both tests, because the stored settled promise still wins on the replay.Risk / follow-ups
nextMatchUpdatesubscribes once per redirected match snapshot, cached in aWeakMap. If the match unmounts without another store update, the listener stays on the orphaned atom and is collected with it.RouterClienthydrates anssr: falseroute in jsdom (createRoot), the rootMatchesSuspense stays in fallback with the root layout hidden (display: none) while the child route is pending. This happens both before and after this change; client navigation does not show it.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches core route match Suspense/navigation rendering; behavior change is narrow and regression-tested, but incorrect suspension could still affect loading, redirects, and hydration.
Overview
Fixes page livelocks and premature route renders when a TanStack route match moves between pending states (hydration force-pending, slow loaders, redirects).
MatchInnerno longer suspends via Octane's positionaluse(thenable). It throws the same router-core promises as upstream for_displayPending,_forcePending, andpending, so Suspense retries always wait on the promise for the current state instead of reusing a settled promise from an earlier state (which could spin on microtasks and block timers/network).For
redirected, suspension waits onnextMatchUpdate(first match-store update after the snapshot) when the store supports subscribe, instead ofloadPromise, which router-core has already resolved—avoiding the same microtask loop while the redirect target's loader runs.Adds conformance tests (hydrated
ssr: falseclient loader outlastingpendingMinMs, redirect to a timer-based target), a shared fixture, audit classification, and a patch changeset.Reviewed by Cursor Bugbot for commit 8692661. Bugbot is set up for automated code reviews on this repo. Configure here.