Skip to content
Source
Sign inSign up
TanStack/router

fix: handle stale redirected matches during view transitions #7158

Closedschiller-manuel(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromfix-7120opened

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a client-side crash where a redirect during navigation could blank the UI when view transitions and lazy routes were enabled.
    • Ensured pending UI displays reliably during such redirects instead of leaving the screen empty.
  • Tests

    • Added an end-to-end reproduction test and fixture to prevent regressions and validate the pending UI/redirect behavior.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core

    3. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router

    4. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: vue-router

    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      📝 Walkthrough

      Walkthrough

      This PR prevents a client-side crash when a root beforeLoad redirect races with pending UI and a lazy-loaded target while defaultViewTransition is enabled by introducing a retained-pending mechanism and updating Match logic across React, Solid, and Vue; adds an e2e fixture reproducing the regression.

      Changes

      Cohort / File(s)Summary
      E2E Fixture & Metadata
      /.changeset/bright-cars-lie.md, e2e/react-router/issue-7120/index.html, e2e/react-router/issue-7120/package.json, e2e/react-router/issue-7120/playwright.config.ts, e2e/react-router/issue-7120/tsconfig.json, e2e/react-router/issue-7120/vite.config.js
      New end-to-end test fixture for issue-7120: changeset, app host files, Playwright config/global setup/teardown wiring, and build/dev tooling config.
      E2E App & Tests
      e2e/react-router/issue-7120/src/main.tsx, e2e/react-router/issue-7120/src/posts.lazy.tsx, e2e/react-router/issue-7120/src/posts.ts, e2e/react-router/issue-7120/src/styles.css, e2e/react-router/issue-7120/tests/issue-7120.repro.spec.ts, e2e/react-router/issue-7120/tests/setup/global.setup.ts, e2e/react-router/issue-7120/tests/setup/global.teardown.ts
      Adds a React Router repro app with a root beforeLoad redirect to a lazy /posts route, fetching posts (switchable to local dummy server), CSS/Tailwind, and a Playwright test that asserts no crash and correct pending UI behavior.
      Router Core: retained-pending support
      packages/router-core/src/Matches.ts, packages/router-core/src/index.ts, packages/router-core/src/load-matches.ts
      Introduces retainedPendingPromise field and markMatchPendingVisible() export; adds clearing of retained pending promise in multiple load/redirect/error finalization paths.
      React Router Match updates
      packages/react-router/src/Match.tsx, packages/react-router/tests/redirect.test.tsx
      Adds PendingRouteMatch wrapper to mark matches pending-visible; refactors pending/redirect suspension logic to prefer loader promises but fall back to retained pending; updates test to enable defaultViewTransition and assert pending UI appears.
      Solid Router Match updates
      packages/solid-router/src/Match.tsx, packages/solid-router/tests/redirect.test.tsx
      Adds PendingRouteMatch, retained-pending handling, and revised promise selection (including router.latestLoadPromise fallback); adjusts pending rendering and test assertions to cover view-transition case.
      Vue Router Match updates
      packages/vue-router/src/Match.tsx, packages/vue-router/tests/redirect.test.tsx
      Adds PendingRouteMatch, simplifies MatchInner shape passing, generalizes promise lookups with router.latestLoadPromise fallback and retained-pending use for redirects; test updated to check pending UI during redirect.

      Sequence Diagram(s)

      sequenceDiagram
        participant Browser
        participant FrameworkMatch as Match Component
        participant RouterCore
        participant LazyRoute as Lazy Loader
        Browser->>FrameworkMatch: Navigate (root)
        FrameworkMatch->>RouterCore: beforeLoad runs -> redirect to /posts
        Browser->>FrameworkMatch: Render pendingComponent (view transition starts)
        FrameworkMatch->>RouterCore: markMatchPendingVisible(matchId)
        RouterCore->>LazyRoute: start loading /posts (async)
        alt Lazy resolves before redirect finalizes
          LazyRoute-->>FrameworkMatch: component ready
          FrameworkMatch->>RouterCore: consume load result -> finish navigation
        else Redirect/transition races and match becomes stale
          RouterCore-->>FrameworkMatch: provide retainedPendingPromise fallback
          FrameworkMatch->>Browser: keep/clear pending UI safely (no crash)
        end

      Estimated code review effort

      🎯 4 (Complex) | ⏱️ ~50 minutes

      • TanStack/router#6867: Related router-core changes touching match lifecycle and load-matches finalization that overlap retained-pending and loader finalization logic.
      • TanStack/router#5691: Related adjustments to pending/transition handling across router-core and framework Match implementations.

      Suggested reviewers

      • tannerlinsley

      Poem

      🐰 A hop, a pending promise held so tight,

      Redirects raced the view transition’s light. Retained and marked, no stale match will fall, Three frameworks shelter one graceful call. Paws on keys — regressions fixed tonight!

      🚥 Pre-merge checks | ✅ 2 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (2 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title 'fix: handle stale redirected matches during view transitions' accurately and concisely describes the main change: handling stale redirected matches that occur during view transitions when a redirect races with lazy-loaded routes.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      ✨ Finishing Touches
      📝 Generate docstrings
      • Create stacked PR
      • Commit on current branch
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `fix-7120`

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    6. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit afbe97a8f6d94cc863554d8a2cd35cf9622a8115

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:unit,tes...❌ Failed17m 23sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded1m 5sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-04-11 23:59:59 UTC

    7. github-actions[bot](GitHub profile, opens in a new tab)commented

      🚀 Changeset Version Preview

      1 package(s) bumped directly, 4 bumped as dependents.

      🟩 Patch bumps

      PackageVersionReason
      @tanstack/react-router1.168.18 → 1.168.19Changeset
      @tanstack/react-start1.167.31 → 1.167.32Dependent
      @tanstack/react-start-client1.166.35 → 1.166.36Dependent
      @tanstack/react-start-rsc0.0.11 → 0.0.12Dependent
      @tanstack/react-start-server1.166.36 → 1.166.37Dependent
    8. github-actions[bot](GitHub profile, opens in a new tab)commented

      Bundle Size Benchmarks

      • Commit: c3900c832804
      • Measured at: 2026-04-11T23:35:07.316Z
      • Baseline source: history:0e2c9003c18a
      • Dashboard: bundle-size history
      ScenarioCurrent (gzip)Delta vs baselineRawBrotliTrend
      react-router.minimal87.48 KiB+146 B (+0.16%)275.12 KiB76.03 KiB█▇▇▇▄▁▁▁▁▁▁▇
      react-router.full90.76 KiB+149 B (+0.16%)286.19 KiB78.92 KiB████▄▁▁▁▁▁▁▇
      solid-router.minimal35.67 KiB+140 B (+0.38%)107.22 KiB32.08 KiB▅▅▅▅▃▁▁▁▁▁▁█
      solid-router.full40.14 KiB+159 B (+0.39%)120.71 KiB36.03 KiB▅▅▅▅▃▁▁▁▁▁▁█
      vue-router.minimal53.43 KiB+119 B (+0.22%)152.60 KiB47.99 KiB████▄▁▁▁▁▁▁▆
      vue-router.full58.31 KiB+106 B (+0.18%)168.02 KiB52.23 KiB████▄▁▁▁▁▁▁▆
      react-start.minimal101.88 KiB+141 B (+0.14%)322.85 KiB88.06 KiB██▅▅▃▁▁▁▁▁▁▅
      react-start.full105.32 KiB+136 B (+0.13%)333.17 KiB91.03 KiB██▆▆▃▁▁▁▁▁▁▅
      solid-start.minimal49.70 KiB+174 B (+0.34%)153.03 KiB43.80 KiB██▅▅▃▁▁▁▁▁▁█
      solid-start.full55.20 KiB+159 B (+0.28%)169.23 KiB48.53 KiB██▅▅▄▁▁▁▁▁▁▇

      Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

    9. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented
      More templates

      @tanstack/arktype-adapter

      npm i https://pkg.pr.new/@tanstack/arktype-adapter@7158

      @tanstack/eslint-plugin-router

      npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7158

      @tanstack/eslint-plugin-start

      npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7158

      @tanstack/history

      npm i https://pkg.pr.new/@tanstack/history@7158

      @tanstack/nitro-v2-vite-plugin

      npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7158

      @tanstack/react-router

      npm i https://pkg.pr.new/@tanstack/react-router@7158

      @tanstack/react-router-devtools

      npm i https://pkg.pr.new/@tanstack/react-router-devtools@7158

      @tanstack/react-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7158

      @tanstack/react-start

      npm i https://pkg.pr.new/@tanstack/react-start@7158

      @tanstack/react-start-client

      npm i https://pkg.pr.new/@tanstack/react-start-client@7158

      @tanstack/react-start-rsc

      npm i https://pkg.pr.new/@tanstack/react-start-rsc@7158

      @tanstack/react-start-server

      npm i https://pkg.pr.new/@tanstack/react-start-server@7158

      @tanstack/router-cli

      npm i https://pkg.pr.new/@tanstack/router-cli@7158

      @tanstack/router-core

      npm i https://pkg.pr.new/@tanstack/router-core@7158

      @tanstack/router-devtools

      npm i https://pkg.pr.new/@tanstack/router-devtools@7158

      @tanstack/router-devtools-core

      npm i https://pkg.pr.new/@tanstack/router-devtools-core@7158

      @tanstack/router-generator

      npm i https://pkg.pr.new/@tanstack/router-generator@7158

      @tanstack/router-plugin

      npm i https://pkg.pr.new/@tanstack/router-plugin@7158

      @tanstack/router-ssr-query-core

      npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7158

      @tanstack/router-utils

      npm i https://pkg.pr.new/@tanstack/router-utils@7158

      @tanstack/router-vite-plugin

      npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7158

      @tanstack/solid-router

      npm i https://pkg.pr.new/@tanstack/solid-router@7158

      @tanstack/solid-router-devtools

      npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7158

      @tanstack/solid-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7158

      @tanstack/solid-start

      npm i https://pkg.pr.new/@tanstack/solid-start@7158

      @tanstack/solid-start-client

      npm i https://pkg.pr.new/@tanstack/solid-start-client@7158

      @tanstack/solid-start-server

      npm i https://pkg.pr.new/@tanstack/solid-start-server@7158

      @tanstack/start-client-core

      npm i https://pkg.pr.new/@tanstack/start-client-core@7158

      @tanstack/start-fn-stubs

      npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7158

      @tanstack/start-plugin-core

      npm i https://pkg.pr.new/@tanstack/start-plugin-core@7158

      @tanstack/start-server-core

      npm i https://pkg.pr.new/@tanstack/start-server-core@7158

      @tanstack/start-static-server-functions

      npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7158

      @tanstack/start-storage-context

      npm i https://pkg.pr.new/@tanstack/start-storage-context@7158

      @tanstack/valibot-adapter

      npm i https://pkg.pr.new/@tanstack/valibot-adapter@7158

      @tanstack/virtual-file-routes

      npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7158

      @tanstack/vue-router

      npm i https://pkg.pr.new/@tanstack/vue-router@7158

      @tanstack/vue-router-devtools

      npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7158

      @tanstack/vue-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7158

      @tanstack/vue-start

      npm i https://pkg.pr.new/@tanstack/vue-start@7158

      @tanstack/vue-start-client

      npm i https://pkg.pr.new/@tanstack/vue-start-client@7158

      @tanstack/vue-start-server

      npm i https://pkg.pr.new/@tanstack/vue-start-server@7158

      @tanstack/zod-adapter

      npm i https://pkg.pr.new/@tanstack/zod-adapter@7158

      commit: afbe97a

    10. Actionable comments posted: 3

      🧹 Nitpick comments (1)
      e2e/react-router/issue-7120/src/posts.ts (1)

      9-19: Prefer an explicit return type for fetchPosts for stronger type contracts.

      This helps keep call-site expectations stable if response typing changes later.

      ♻️ Suggested update
       export const fetchPosts = async () => {
      +export const fetchPosts = async (): Promise<Array<PostType>> => {
         return axios
           .get<Array<PostType>>(`${queryURL}/posts`)
           .then((r) => r.data.slice(0, 10))
       }

      As per coding guidelines, **/*.{ts,tsx}: Use TypeScript strict mode with extensive type safety.

      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In `@e2e/react-router/issue-7120/src/posts.ts` around lines 9 - 19, The function
      fetchPosts lacks an explicit return type; update its signature to include a
      strong TypeScript return type (e.g. export const fetchPosts = async ():
      Promise<PostType[]> => { ... }) so callers know they receive an array of
      PostType (the function still returns the first 10 items from queryURL via
      axios.get<Array<PostType>>). Keep the implementation unchanged except for the
      annotated return type (or use Promise<Array<PostType>> if you prefer that
      notation).
      🤖 Prompt for all review comments with AI agents
      Verify each finding against the current code and only fix it if needed.
      
      Inline comments:
      In `@packages/solid-router/src/Match.tsx`:
      - Around line 336-343: The helper getRetainedPendingPromise loses access to a
      stale match's internal _nonReactive because rawMatchState().match returns a
      stripped match; restore or preserve the original match object so its
      _nonReactive is available as a fallback. Concretely, update rawMatchState (or
      the code that produces fallbackMatch) to return the full match object including
      _nonReactive (instead of stripping it), then change getRetainedPendingPromise to
      prefer router.getMatch(matchId)?._nonReactive.retainedPendingPromise and fall
      back to fallbackMatch?._nonReactive.retainedPendingPromise; apply the same
      change to the second occurrence (the block around lines 455-462) so both places
      can suspend on the retainedPendingPromise of a stale match.
      - Around line 32-37: The current Solid.onMount call only runs once so when
      PendingRouteMatch remains mounted and props.matchId changes the new match isn't
      marked pending-visible; replace or supplement the onMount with a reactive
      watcher (e.g., Solid.createEffect) that depends on props.matchId, call
      router.getMatch(props.matchId) inside it and invoke
      markMatchPendingVisible(match) whenever a non-null match is found; keep or
      remove the original onMount as needed to preserve initial behavior, and
      reference the existing functions Solid.onMount / Solid.createEffect,
      router.getMatch, markMatchPendingVisible and the PendingRouteMatch component to
      locate where to add the reactive effect.
      
      In `@packages/vue-router/src/Match.tsx`:
      - Around line 304-309: The component currently only calls
      markMatchPendingVisible in Vue.onMounted, so when props.matchId changes in a
      reused instance new matches aren't marked; add a watcher using Vue.watch(() =>
      props.matchId, ...) (in addition to the existing Vue.onMounted call) that
      retrieves the new match via router.getMatch(props.matchId) and invokes
      markMatchPendingVisible(match) when a match exists, ensuring pending visibility
      is re-applied on matchId updates.
      
      ---
      
      Nitpick comments:
      In `@e2e/react-router/issue-7120/src/posts.ts`:
      - Around line 9-19: The function fetchPosts lacks an explicit return type;
      update its signature to include a strong TypeScript return type (e.g. export
      const fetchPosts = async (): Promise<PostType[]> => { ... }) so callers know
      they receive an array of PostType (the function still returns the first 10 items
      from queryURL via axios.get<Array<PostType>>). Keep the implementation unchanged
      except for the annotated return type (or use Promise<Array<PostType>> if you
      prefer that notation).
      🪄 Autofix (Beta)

      Fix all unresolved CodeRabbit comments on this PR:

      • Push a commit to this branch (recommended)
      • Create a new PR with the fixes

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: 58c421fc-673d-4c3f-88da-a66531f614e0

      📥 Commits

      Reviewing files that changed from the base of the PR and between c3900c832804b37d3e7f1a5d9b5859e3b9867bca and 60932dde22cfe4be97ba974062fff1cb19eaa730.

      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
      📒 Files selected for processing (22)
      • .changeset/bright-cars-lie.md
      • e2e/react-router/issue-7120/index.html
      • e2e/react-router/issue-7120/package.json
      • e2e/react-router/issue-7120/playwright.config.ts
      • e2e/react-router/issue-7120/src/main.tsx
      • e2e/react-router/issue-7120/src/posts.lazy.tsx
      • e2e/react-router/issue-7120/src/posts.ts
      • e2e/react-router/issue-7120/src/styles.css
      • e2e/react-router/issue-7120/tests/issue-7120.repro.spec.ts
      • e2e/react-router/issue-7120/tests/setup/global.setup.ts
      • e2e/react-router/issue-7120/tests/setup/global.teardown.ts
      • e2e/react-router/issue-7120/tsconfig.json
      • e2e/react-router/issue-7120/vite.config.js
      • packages/react-router/src/Match.tsx
      • packages/react-router/tests/redirect.test.tsx
      • packages/router-core/src/Matches.ts
      • packages/router-core/src/index.ts
      • packages/router-core/src/load-matches.ts
      • packages/solid-router/src/Match.tsx
      • packages/solid-router/tests/redirect.test.tsx
      • packages/vue-router/src/Match.tsx
      • packages/vue-router/tests/redirect.test.tsx
      @@ -17,3 +18,20 @@
      1718 import { renderRouteNotFound } from './renderRouteNotFound'
      1819 import { ScrollRestoration } from './scroll-restoration'
      19-import type { AnyRoute, RootRouteOptions } from '@tanstack/router-core'
      20+import type {
      21+ AnyRoute,
      22+ AnyRouteMatch,
      23+ RootRouteOptions,
      24+} from '@tanstack/router-core'
      25+
      26+const PendingRouteMatch = (props: {
      27+ matchId: string
      28+ pendingComponent: unknown
      29+}) => {
      30+ const router = useRouter()
      31+
      32+ Solid.onMount(() => {
      33+ const match = router.getMatch(props.matchId)
      34+ if (match) {
      35+ markMatchPendingVisible(match)
      36+ }
      37+ })
      coderabbitai[bot](GitHub profile, opens in a new tab)commented

      ⚠️ Potential issue | 🟠 Major

      Re-run markMatchPendingVisible when Solid reuses the pending component.

      onMount only fires once. If PendingRouteMatch stays mounted and props.matchId changes, the new match is never marked pending-visible, so later redirect/pending transitions won't retain the right promise.

      Suggested fix
      -  Solid.onMount(() => {
      +  Solid.createEffect(() => {
           const match = router.getMatch(props.matchId)
           if (match) {
             markMatchPendingVisible(match)
           }
         })
      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In `@packages/solid-router/src/Match.tsx` around lines 32 - 37, The current
      Solid.onMount call only runs once so when PendingRouteMatch remains mounted and
      props.matchId changes the new match isn't marked pending-visible; replace or
      supplement the onMount with a reactive watcher (e.g., Solid.createEffect) that
      depends on props.matchId, call router.getMatch(props.matchId) inside it and
      invoke markMatchPendingVisible(match) whenever a non-null match is found; keep
      or remove the original onMount as needed to preserve initial behavior, and
      reference the existing functions Solid.onMount / Solid.createEffect,
      router.getMatch, markMatchPendingVisible and the PendingRouteMatch component to
      locate where to add the reactive effect.
      @@ -282,8 +327,17 @@
      282- }
      283- }
      284- | undefined,
      327+ fallbackMatch: AnyRouteMatch | undefined,
      285328 ) => {
      286329 return (
      287330 router.getMatch(matchId)?._nonReactive.loadPromise ??
      288- fallbackMatch?._nonReactive.loadPromise
      331+ fallbackMatch?._nonReactive.loadPromise ??
      332+ router.latestLoadPromise
      333+ )
      334+ }
      335+
      336+ const getRetainedPendingPromise = (
      337+ matchId: string,
      338+ fallbackMatch: AnyRouteMatch | undefined,
      339+ ) => {
      340+ return (
      341+ router.getMatch(matchId)?._nonReactive.retainedPendingPromise ??
      342+ fallbackMatch?._nonReactive.retainedPendingPromise
      289343 )
      coderabbitai[bot](GitHub profile, opens in a new tab)commented

      ⚠️ Potential issue | 🔴 Critical

      Keep the stale Solid match's _nonReactive state available.

      These helpers only work while router.getMatch(matchId) still resolves. rawMatchState().match currently strips _nonReactive, so once the redirected match drops out of the router pool there is no retained promise left to suspend on and this branch falls through instead of preserving the pending UI.

      Suggested fix
           return {
             key,
             routeId,
      -      match: {
      -        id: currentMatch.id,
      -        status: currentMatch.status,
      -        error: currentMatch.error,
      -        _forcePending: currentMatch._forcePending ?? false,
      -        _displayPending: currentMatch._displayPending ?? false,
      -      },
      +      match: currentMatch,
           }
      -                const routerMatch = router.getMatch(matchId)
      +                const fallbackMatch = currentMatch()
      
                       if (!isRedirect(currentMatch().error)) {
                         if (process.env.NODE_ENV !== 'production') {
                           throw new Error(
                             'Invariant failed: Expected a redirect error',
      @@
                       const [loaderResult] = Solid.createResource(async () => {
                         await new Promise((r) => setTimeout(r, 0))
      -                  return getLoadPromise(matchId, routerMatch)
      +                  return getLoadPromise(matchId, fallbackMatch)
                       })
      
                       const [retainedPendingResult] = Solid.createResource(
                         async () => {
                           await new Promise((r) => setTimeout(r, 0))
      -                    return getRetainedPendingPromise(matchId, routerMatch)
      +                    return getRetainedPendingPromise(matchId, fallbackMatch)
                         },
                       )

      Also applies to: 455-462

      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In `@packages/solid-router/src/Match.tsx` around lines 336 - 343, The helper
      getRetainedPendingPromise loses access to a stale match's internal _nonReactive
      because rawMatchState().match returns a stripped match; restore or preserve the
      original match object so its _nonReactive is available as a fallback.
      Concretely, update rawMatchState (or the code that produces fallbackMatch) to
      return the full match object including _nonReactive (instead of stripping it),
      then change getRetainedPendingPromise to prefer
      router.getMatch(matchId)?._nonReactive.retainedPendingPromise and fall back to
      fallbackMatch?._nonReactive.retainedPendingPromise; apply the same change to the
      second occurrence (the block around lines 455-462) so both places can suspend on
      the retainedPendingPromise of a stale match.
      @@ -283,0 +289,21 @@
      289+ name: 'PendingRouteMatch',
      290+ props: {
      291+ matchId: {
      292+ type: String,
      293+ required: true,
      294+ },
      295+ pendingComponent: {
      296+ type: [Object, Function] as Vue.PropType<any>,
      297+ required: false,
      298+ default: undefined,
      299+ },
      300+ },
      301+ setup(props) {
      302+ const router = useRouter()
      303+
      304+ Vue.onMounted(() => {
      305+ const match = router.getMatch(props.matchId)
      306+ if (match) {
      307+ markMatchPendingVisible(match)
      308+ }
      309+ })
      coderabbitai[bot](GitHub profile, opens in a new tab)commented

      ⚠️ Potential issue | 🟠 Major

      Re-run pending visibility marking when matchId changes.

      PendingRouteMatch only calls markMatchPendingVisible on mount. Vue can reuse this component instance while patching a new matchId, so later pending/redirect transitions never mark the new match as visible and won't retain its pending promise.

      Suggested fix
         setup(props) {
           const router = useRouter()
      
      -    Vue.onMounted(() => {
      -      const match = router.getMatch(props.matchId)
      +    const markPendingVisible = (matchId: string) => {
      +      const match = router.getMatch(matchId)
             if (match) {
               markMatchPendingVisible(match)
             }
      -    })
      +    }
      +
      +    Vue.onMounted(() => {
      +      markPendingVisible(props.matchId)
      +    })
      +
      +    Vue.watch(
      +      () => props.matchId,
      +      (matchId) => {
      +        markPendingVisible(matchId)
      +      },
      +      { flush: 'post' },
      +    )
      
           return () => (props.pendingComponent ? Vue.h(props.pendingComponent) : null)
         },
      📝 Committable suggestion

      ‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

      Suggested change
      304- Vue.onMounted(() => {
      305- const match = router.getMatch(props.matchId)
      306- if (match) {
      307- markMatchPendingVisible(match)
      308- }
      309- })
      304+ const markPendingVisible = (matchId: string) => {
      305+ const match = router.getMatch(matchId)
      306+ if (match) {
      307+ markMatchPendingVisible(match)
      308+ }
      309+ }
      310+
      311+ Vue.onMounted(() => {
      312+ markPendingVisible(props.matchId)
      313+ })
      314+
      315+ Vue.watch(
      316+ () => props.matchId,
      317+ (matchId) => {
      318+ markPendingVisible(matchId)
      319+ },
      320+ { flush: 'post' },
      321+ )
      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In `@packages/vue-router/src/Match.tsx` around lines 304 - 309, The component
      currently only calls markMatchPendingVisible in Vue.onMounted, so when
      props.matchId changes in a reused instance new matches aren't marked; add a
      watcher using Vue.watch(() => props.matchId, ...) (in addition to the existing
      Vue.onMounted call) that retrieves the new match via
      router.getMatch(props.matchId) and invokes markMatchPendingVisible(match) when a
      match exists, ensuring pending visibility is re-applied on matchId updates.
    11. codspeed[bot](GitHub profile, opens in a new tab)commented

      Merging this PR will not alter performance

      ✅ 6 untouched benchmarks


      Comparing fix-7120 (afbe97a) with main (0e2c900)[^unexpected-base] Open in CodSpeed
    12. Important

      At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

      Nx Cloud is proposing a fix for your failed CI:

      We replaced the four void ?? X nullish-coalescing expressions in packages/solid-router/src/Match.tsx with comma expressions (resource(), X) to fix the TypeScript TS2801 strict-mode errors. Because createResource fetchers return Promise<void> (auto-flattened by JavaScript), the resource accessors resolve to void, which TypeScript forbids on the left-hand side of ??. The comma operator preserves the resource accessor call (keeping SolidJS reactive tracking and Suspense integration intact) while eliminating the void type from the ?? operator.

      Warning

      ❌ We could not verify this fix.

      Suggested Fix changes
      diff --git a/packages/solid-router/src/Match.tsx b/packages/solid-router/src/Match.tsx
      index 3f07c8889b..8d22710e52 100644
      --- a/packages/solid-router/src/Match.tsx
      +++ b/packages/solid-router/src/Match.tsx
      @@ -359,7 +359,7 @@ export const MatchInner = (): any => {
                             .displayPendingPromise,
                       )
       
      -                return <>{displayPendingResult() ?? renderPending()}</>
      +                return <>{(displayPendingResult(), renderPending())}</>
                     }}
                   </Solid.Match>
                   <Solid.Match when={currentMatch()._forcePending}>
      @@ -370,7 +370,7 @@ export const MatchInner = (): any => {
                             .minPendingPromise,
                       )
       
      -                return <>{minPendingResult() ?? renderPending()}</>
      +                return <>{(minPendingResult(), renderPending())}</>
                     }}
                   </Solid.Match>
                   <Solid.Match when={currentMatch().status === 'pending'}>
      @@ -407,7 +407,7 @@ export const MatchInner = (): any => {
                           .loadPromise
                       })
       
      -                return <>{loaderResult() ?? renderPending()}</>
      +                return <>{(loaderResult(), renderPending())}</>
                     }}
                   </Solid.Match>
                   <Solid.Match when={currentMatch().status === 'notFound'}>
      @@ -459,7 +459,7 @@ export const MatchInner = (): any => {
                         },
                       )
       
      -                return <>{loaderResult() ?? retainedPendingResult()}</>
      +                return <>{(loaderResult(), retainedPendingResult())}</>
                     }}
                   </Solid.Match>
                   <Solid.Match when={currentMatch().status === 'error'}>
      

      Apply fix via Nx Cloud  Reject fix via Nx Cloud


      Or Apply changes locally with:

      npx nx-cloud apply-locally BB5q-XGYN
      Apply fix locally with your editor ↗   View interactive diff ↗

      🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)
    13. Actionable comments posted: 1

      🤖 Prompt for all review comments with AI agents
      Verify each finding against the current code and only fix it if needed.
      
      Inline comments:
      In `@packages/react-router/src/Match.tsx`:
      - Around line 444-467: Add a concise clarifying comment inside the
      suspendOrKeepPending function (near the final "return null") explaining that
      returning null is intentional: it covers the race where a resolved promise
      cleared before retainedPendingPromise was set (i.e., there is simply no active
      promise to throw/suspend on), so the caller should continue rendering normally;
      reference the function name suspendOrKeepPending and variables promise and
      retainedPendingPromise to indicate the exact fallback path being documented.
      🪄 Autofix (Beta)

      Fix all unresolved CodeRabbit comments on this PR:

      • Push a commit to this branch (recommended)
      • Create a new PR with the fixes

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: 95471f9b-c5d8-4377-b41c-233743a4f0ae

      📥 Commits

      Reviewing files that changed from the base of the PR and between 60932dde22cfe4be97ba974062fff1cb19eaa730 and afbe97a8f6d94cc863554d8a2cd35cf9622a8115.

      📒 Files selected for processing (1)
      • packages/react-router/src/Match.tsx
      @@ -406 +447,21 @@
      447+ const routerMatch = router.getMatch(match.id)
      448+
      449+ const promise =
      450+ routerMatch?._nonReactive[key] ??
      451+ match._nonReactive[key] ??
      452+ router.latestLoadPromise
      453+
      454+ if (promise) {
      455+ throw promise
      456+ }
      457+
      458+ const retainedPendingPromise =
      459+ routerMatch?._nonReactive.retainedPendingPromise ??
      460+ match._nonReactive.retainedPendingPromise
      461+
      462+ if (retainedPendingPromise) {
      463+ throw retainedPendingPromise
      464+ }
      465+
      466+ return null
      406467 }
      coderabbitai[bot](GitHub profile, opens in a new tab)commented

      ⚠️ Potential issue | 🟡 Minor

      🧩 Analysis chain

      🏁 Script executed:

      #!/bin/bash
      # Check if there are any test cases or comments explaining when suspendOrKeepPending might return null
      
      # Search for test coverage or comments about this behavior
      rg -n -C3 "suspendOrKeepPending|return null" packages/react-router/src/
      
      # Check if there's e2e coverage for this specific edge case
      rg -n "retainedPendingPromise" e2e/

      Repository: TanStack/router

      Length of output: 6869


      🏁 Script executed:

      # Read the Match.tsx file around the suspendOrKeepPending function to understand the full context
      sed -n '430,530p' packages/react-router/src/Match.tsx

      Repository: TanStack/router

      Length of output: 3287


      🏁 Script executed:

      # Search for where retainedPendingPromise is set and used
      rg -n "retainedPendingPromise" packages/react-router/src/ packages/router-core/src/ --max-count=50
      
      # Also check if there are comments explaining when suspendOrKeepPending might return null
      rg -n -B5 "return null" packages/react-router/src/Match.tsx | head -100

      Repository: TanStack/router

      Length of output: 1488


      🏁 Script executed:

      # See the context around where retainedPendingPromise is set and cleared
      sed -n '100,120p' packages/router-core/src/Matches.ts
      
      # See the context where it's cleared
      sed -n '40,55p' packages/router-core/src/load-matches.ts
      
      # Search for tests related to this edge case
      rg -n "suspendOrKeepPending|retainedPendingPromise" e2e/ --type tsx --type ts | head -30

      Repository: TanStack/router

      Length of output: 1049


      🏁 Script executed:

      # Search for e2e tests that cover pending/suspense behavior
      find e2e -name "*.tsx" -o -name "*.ts" | head -20
      
      # Look for tests related to pending or suspense
      rg -n "pending|suspense" e2e/ --max-count=30 | grep -i "test\|it\|describe"
      
      # Check the Matches.ts file for more context on how retainedPendingPromise is used
      sed -n '100,180p' packages/router-core/src/Matches.ts

      Repository: TanStack/router

      Length of output: 21100


      🏁 Script executed:

      # Look at the full context of clearRetainedPending and when it's called
      rg -n "clearRetainedPending" packages/router-core/src/ -A 5 -B 5
      
      # Check the load-matches.ts to understand when promises are cleared
      sed -n '30,60p' packages/router-core/src/load-matches.ts

      Repository: TanStack/router

      Length of output: 5198


      🏁 Script executed:

      # Look at the updateMatch callback and how match status changes
      sed -n '220,280p' packages/router-core/src/load-matches.ts

      Repository: TanStack/router

      Length of output: 1589


      🏁 Script executed:

      # Search for where _displayPending and _forcePending are set
      rg -n "_displayPending|_forcePending" packages/router-core/src/ --max-count=50

      Repository: TanStack/router

      Length of output: 637


      🏁 Script executed:

      # Look at the context where _displayPending and _forcePending are set and cleared
      sed -n '110,130p' packages/router-core/src/ssr/ssr-client.ts
      sed -n '280,310p' packages/router-core/src/ssr/ssr-client.ts

      Repository: TanStack/router

      Length of output: 1719


      🏁 Script executed:

      # Look for where markMatchPendingVisible is called to understand when retainedPendingPromise is set
      rg -n "markMatchPendingVisible" packages/ --max-count=20

      Repository: TanStack/router

      Length of output: 687


      🏁 Script executed:

      # Look at the context around line 253 where markMatchPendingVisible is called
      sed -n '240,280p' packages/react-router/src/Match.tsx

      Repository: TanStack/router

      Length of output: 1171


      🏁 Script executed:

      # Look at what renders PendingRouteMatch and when pendingElement is provided
      sed -n '300,400p' packages/react-router/src/Match.tsx

      Repository: TanStack/router

      Length of output: 2895


      🏁 Script executed:

      # Continue reading the client-side rendering logic to see when PendingRouteMatch is rendered
      sed -n '400,480p' packages/react-router/src/Match.tsx

      Repository: TanStack/router

      Length of output: 2442


      🏁 Script executed:

      # Look for any tests or code that might exercise the return null path
      rg -n "return null" packages/react-router/src/Match.tsx -B 10 | head -40
      
      # Check if there's any documentation about when return null is expected
      rg -n "pending\|redirected" packages/react-router/src/Match.tsx | grep -i "comment\|todo\|fixme\|note"

      Repository: TanStack/router

      Length of output: 1269


      🏁 Script executed:

      # Search for any comments explaining the suspendOrKeepPending logic
      sed -n '430,480p' packages/react-router/src/Match.tsx | cat -n

      Repository: TanStack/router

      Length of output: 1890


      Consider adding a clarifying comment explaining the return null fallback path.

      The return null at line 466 can be reached when a promise resolves before retainedPendingPromise is set (a race condition window that occurs when pending UI hasn't rendered yet). This is expected behavior, but adding a comment explaining that returning null is appropriate when there's no promise to suspend on would improve code clarity and prevent future maintainers from questioning this logic.

      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In `@packages/react-router/src/Match.tsx` around lines 444 - 467, Add a concise
      clarifying comment inside the suspendOrKeepPending function (near the final
      "return null") explaining that returning null is intentional: it covers the race
      where a resolved promise cleared before retainedPendingPromise was set (i.e.,
      there is simply no active promise to throw/suspend on), so the caller should
      continue rendering normally; reference the function name suspendOrKeepPending
      and variables promise and retainedPendingPromise to indicate the exact fallback
      path being documented.
    14. Nx Cloud is proposing a fix for your failed CI:

      We updated four Solid.createResource factory functions in packages/solid-router/src/Match.tsx to return Promise<null> instead of Promise<void>, fixing TypeScript 5.5 error TS1345 ("An expression of type 'void' cannot be tested for truthiness"). The factories now chain .then(() => null) on the underlying promises so their resolved type is null | undefined rather than void | undefined, making the ?? renderPending() expressions valid while preserving identical runtime suspension behavior.

      Tip

      ✅ We verified this fix by re-running @tanstack/solid-router:test:types.

      Suggested Fix changes
      diff --git a/packages/solid-router/src/Match.tsx b/packages/solid-router/src/Match.tsx
      index 3f07c8889b..e43df877d3 100644
      --- a/packages/solid-router/src/Match.tsx
      +++ b/packages/solid-router/src/Match.tsx
      @@ -354,9 +354,10 @@ export const MatchInner = (): any => {
                   <Solid.Match when={currentMatch()._displayPending}>
                     {(_) => {
                       const [displayPendingResult] = Solid.createResource(
      -                  () =>
      -                    router.getMatch(currentMatch().id)?._nonReactive
      -                      .displayPendingPromise,
      +                  (): Promise<null> | undefined =>
      +                    router
      +                      .getMatch(currentMatch().id)
      +                      ?._nonReactive.displayPendingPromise?.then(() => null),
                       )
       
                       return <>{displayPendingResult() ?? renderPending()}</>
      @@ -365,9 +366,10 @@ export const MatchInner = (): any => {
                   <Solid.Match when={currentMatch()._forcePending}>
                     {(_) => {
                       const [minPendingResult] = Solid.createResource(
      -                  () =>
      -                    router.getMatch(currentMatch().id)?._nonReactive
      -                      .minPendingPromise,
      +                  (): Promise<null> | undefined =>
      +                    router
      +                      .getMatch(currentMatch().id)
      +                      ?._nonReactive.minPendingPromise?.then(() => null),
                       )
       
                       return <>{minPendingResult() ?? renderPending()}</>
      @@ -401,11 +403,16 @@ export const MatchInner = (): any => {
                         }
                       }
       
      -                const [loaderResult] = Solid.createResource(async () => {
      -                  await new Promise((r) => setTimeout(r, 0))
      -                  return router.getMatch(currentMatch().id)?._nonReactive
      -                    .loadPromise
      -                })
      +                const [loaderResult] = Solid.createResource(
      +                  (): Promise<null> =>
      +                    new Promise<void>((r) => setTimeout(r, 0))
      +                      .then(
      +                        () =>
      +                          router.getMatch(currentMatch().id)?._nonReactive
      +                            .loadPromise,
      +                      )
      +                      .then(() => null),
      +                )
       
                       return <>{loaderResult() ?? renderPending()}</>
                     }}
      @@ -447,16 +454,20 @@ export const MatchInner = (): any => {
                         invariant()
                       }
       
      -                const [loaderResult] = Solid.createResource(async () => {
      -                  await new Promise((r) => setTimeout(r, 0))
      -                  return getLoadPromise(matchId, routerMatch)
      -                })
      +                const [loaderResult] = Solid.createResource(
      +                  (): Promise<null> =>
      +                    new Promise<void>((r) => setTimeout(r, 0))
      +                      .then(() => getLoadPromise(matchId, routerMatch))
      +                      .then(() => null),
      +                )
       
                       const [retainedPendingResult] = Solid.createResource(
      -                  async () => {
      -                    await new Promise((r) => setTimeout(r, 0))
      -                    return getRetainedPendingPromise(matchId, routerMatch)
      -                  },
      +                  (): Promise<null> =>
      +                    new Promise<void>((r) => setTimeout(r, 0))
      +                      .then(() =>
      +                        getRetainedPendingPromise(matchId, routerMatch),
      +                      )
      +                      .then(() => null),
                       )
       
                       return <>{loaderResult() ?? retainedPendingResult()}</>
      

      Apply fix via Nx Cloud  Reject fix via Nx Cloud


      Or Apply changes locally with:

      npx nx-cloud apply-locally jPV0-cpOm
      Apply fix locally with your editor ↗   View interactive diff ↗

      🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)
    15. @Sheraff can you look into this?

    16. melv-n(GitHub profile, opens in a new tab)commented

      Running into similar issues as #7120 and looking forward to see this land.

Sign in to join this conversation.