fix: handle stale redirected matches during view transitions #7158
main fromfix-7120·opened 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
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: vue-router
View your CI Pipeline Execution ↗ for commit afbe97a8f6d94cc863554d8a2cd35cf9622a8115
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...❌ Failed 17m 23s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 5s View ↗
☁️ Nx Cloud last updated this comment at
2026-04-11 23:59:59UTC🚀 Changeset Version Preview#
1 package(s) bumped directly, 4 bumped as dependents.
🟩 Patch bumps#
Package Version Reason @tanstack/react-router1.168.18 → 1.168.19 Changeset @tanstack/react-start1.167.31 → 1.167.32 Dependent @tanstack/react-start-client1.166.35 → 1.166.36 Dependent @tanstack/react-start-rsc0.0.11 → 0.0.12 Dependent @tanstack/react-start-server1.166.36 → 1.166.37 Dependent Bundle Size Benchmarks#
- Commit:
c3900c832804 - Measured at:
2026-04-11T23:35:07.316Z - Baseline source:
history:0e2c9003c18a - Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Raw Brotli Trend react-router.minimal87.48 KiB +146 B (+0.16%) 275.12 KiB 76.03 KiB █▇▇▇▄▁▁▁▁▁▁▇ react-router.full90.76 KiB +149 B (+0.16%) 286.19 KiB 78.92 KiB ████▄▁▁▁▁▁▁▇ solid-router.minimal35.67 KiB +140 B (+0.38%) 107.22 KiB 32.08 KiB ▅▅▅▅▃▁▁▁▁▁▁█ solid-router.full40.14 KiB +159 B (+0.39%) 120.71 KiB 36.03 KiB ▅▅▅▅▃▁▁▁▁▁▁█ vue-router.minimal53.43 KiB +119 B (+0.22%) 152.60 KiB 47.99 KiB ████▄▁▁▁▁▁▁▆ vue-router.full58.31 KiB +106 B (+0.18%) 168.02 KiB 52.23 KiB ████▄▁▁▁▁▁▁▆ react-start.minimal101.88 KiB +141 B (+0.14%) 322.85 KiB 88.06 KiB ██▅▅▃▁▁▁▁▁▁▅ react-start.full105.32 KiB +136 B (+0.13%) 333.17 KiB 91.03 KiB ██▆▆▃▁▁▁▁▁▁▅ solid-start.minimal49.70 KiB +174 B (+0.34%) 153.03 KiB 43.80 KiB ██▅▅▃▁▁▁▁▁▁█ solid-start.full55.20 KiB +159 B (+0.28%) 169.23 KiB 48.53 KiB ██▅▅▄▁▁▁▁▁▁▇ Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.
- Commit:
More templates
- tanstack-router-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- @tanstack/router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-authjs
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-router-react-example-basic-authjs
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-rscs
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
@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@7158commit:
afbe97aActionable comments posted: 3
🧹 Nitpick comments (1)
e2e/react-router/issue-7120/src/posts.ts (1)
9-19: Prefer an explicit return type forfetchPostsfor 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.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (22)
.changeset/bright-cars-lie.mde2e/react-router/issue-7120/index.htmle2e/react-router/issue-7120/package.jsone2e/react-router/issue-7120/playwright.config.tse2e/react-router/issue-7120/src/main.tsxe2e/react-router/issue-7120/src/posts.lazy.tsxe2e/react-router/issue-7120/src/posts.tse2e/react-router/issue-7120/src/styles.csse2e/react-router/issue-7120/tests/issue-7120.repro.spec.tse2e/react-router/issue-7120/tests/setup/global.setup.tse2e/react-router/issue-7120/tests/setup/global.teardown.tse2e/react-router/issue-7120/tsconfig.jsone2e/react-router/issue-7120/vite.config.jspackages/react-router/src/Match.tsxpackages/react-router/tests/redirect.test.tsxpackages/router-core/src/Matches.tspackages/router-core/src/index.tspackages/router-core/src/load-matches.tspackages/solid-router/src/Match.tsxpackages/solid-router/tests/redirect.test.tsxpackages/vue-router/src/Match.tsxpackages/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: string28+ pendingComponent: unknown29+}) => {30+ const router = useRouter()31+32+ Solid.onMount(() => {33+ const match = router.getMatch(props.matchId)34+ if (match) {35+ markMatchPendingVisible(match)36+ }37+ })⚠️ Potential issue | 🟠 Major
Re-run
markMatchPendingVisiblewhen Solid reuses the pending component.onMountonly fires once. IfPendingRouteMatchstays mounted andprops.matchIdchanges, 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.loadPromise331+ fallbackMatch?._nonReactive.loadPromise ??332+ router.latestLoadPromise333+ )334+ }335+336+ const getRetainedPendingPromise = (337+ matchId: string,338+ fallbackMatch: AnyRouteMatch | undefined,339+ ) => {340+ return (341+ router.getMatch(matchId)?._nonReactive.retainedPendingPromise ??342+ fallbackMatch?._nonReactive.retainedPendingPromise289343 )⚠️ Potential issue | 🔴 Critical
Keep the stale Solid match's
_nonReactivestate available.These helpers only work while
router.getMatch(matchId)still resolves.rawMatchState().matchcurrently 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+ })⚠️ Potential issue | 🟠 Major
Re-run pending visibility marking when
matchIdchanges.PendingRouteMatchonly callsmarkMatchPendingVisibleon mount. Vue can reuse this component instance while patching a newmatchId, 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 change304- 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.Merging this PR will not alter performance#
✅ 6untouched benchmarks
Comparingfix-7120(afbe97a) withmain(0e2c900)[^unexpected-base]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 ?? Xnullish-coalescing expressions inpackages/solid-router/src/Match.tsxwith comma expressions(resource(), X)to fix the TypeScript TS2801 strict-mode errors. BecausecreateResourcefetchers returnPromise<void>(auto-flattened by JavaScript), the resource accessors resolve tovoid, 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 thevoidtype 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'}>
Or Apply changes locally with:
Apply fix locally with your editor ↗ View interactive diff ↗npx nx-cloud apply-locally BB5q-XGYN
🎓 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)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.latestLoadPromise453+454+ if (promise) {455+ throw promise456+ }457+458+ const retainedPendingPromise =459+ routerMatch?._nonReactive.retainedPendingPromise ??460+ match._nonReactive.retainedPendingPromise461+462+ if (retainedPendingPromise) {463+ throw retainedPendingPromise464+ }465+466+ return null406467 }⚠️ 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.tsxRepository: 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 -100Repository: 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 -30Repository: 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.tsRepository: 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.tsRepository: 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.tsRepository: 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=50Repository: 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.tsRepository: 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=20Repository: 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.tsxRepository: 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.tsxRepository: 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.tsxRepository: 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 -nRepository: TanStack/router
Length of output: 1890
Consider adding a clarifying comment explaining the
return nullfallback path.The
return nullat line 466 can be reached when a promise resolves beforeretainedPendingPromiseis 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.Nx Cloud is proposing a fix for your failed CI:#
We updated four
Solid.createResourcefactory functions inpackages/solid-router/src/Match.tsxto returnPromise<null>instead ofPromise<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 isnull | undefinedrather thanvoid | 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()}</>
Or Apply changes locally with:
Apply fix locally with your editor ↗ View interactive diff ↗npx nx-cloud apply-locally jPV0-cpOm
🎓 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)@Sheraff can you look into this?
Running into similar issues as #7120 and looking forward to see this land.
closing in favor of https://github.com/TanStack/router/pull/7637
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
This PR prevents a client-side crash when a root
beforeLoadredirect races with pending UI and a lazy-loaded target whiledefaultViewTransitionis enabled by introducing a retained-pending mechanism and updating Match logic across React, Solid, and Vue; adds an e2e fixture reproducing the regression.Changes#
/.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.jse2e/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.tsbeforeLoadredirect to a lazy/postsroute, fetching posts (switchable to local dummy server), CSS/Tailwind, and a Playwright test that asserts no crash and correct pending UI behavior.packages/router-core/src/Matches.ts,packages/router-core/src/index.ts,packages/router-core/src/load-matches.tsretainedPendingPromisefield andmarkMatchPendingVisible()export; adds clearing of retained pending promise in multiple load/redirect/error finalization paths.packages/react-router/src/Match.tsx,packages/react-router/tests/redirect.test.tsxPendingRouteMatchwrapper to mark matches pending-visible; refactors pending/redirect suspension logic to prefer loader promises but fall back to retained pending; updates test to enabledefaultViewTransitionand assert pending UI appears.packages/solid-router/src/Match.tsx,packages/solid-router/tests/redirect.test.tsxPendingRouteMatch, retained-pending handling, and revised promise selection (includingrouter.latestLoadPromisefallback); adjusts pending rendering and test assertions to cover view-transition case.packages/vue-router/src/Match.tsx,packages/vue-router/tests/redirect.test.tsxPendingRouteMatch, simplifies MatchInner shape passing, generalizes promise lookups withrouter.latestLoadPromisefallback and retained-pending use for redirects; test updated to check pending UI during redirect.Sequence Diagram(s)#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~50 minutes
Possibly related PRs#
Suggested reviewers#
Poem#
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (2 passed)
✨ Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.