Skip to content

Commit e9acd3a

Browse files
fix: match loading
fixes #7602 fixes #7210 fixes #7457 fixes #7673 fixes #6221
1 parent bb2daa6 commit e9acd3a

122 files changed

Lines changed: 20325 additions & 4539 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/violet-poets-wait.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@tanstack/router-core': patch
3+
'@tanstack/react-router': patch
4+
'@tanstack/solid-router': patch
5+
'@tanstack/vue-router': patch
6+
'@tanstack/start-server-core': patch
7+
---
8+
9+
Fix match loading consistency across client navigation, preloading, background reloads, server rendering, and hydration.
10+
11+
- `beforeLoad` context is now propagated to descendant loaders and components during background reloads, preloaded navigation, route re-entry while background work is still in flight, and error or notFound states.
12+
- Redirects no longer use a renderable `RouteMatch.status`; `RouteMatch.status` is now `'pending' | 'success' | 'error' | 'notFound'`. Abandoned, redirected, or failed matches are dropped from cache and their readiness promises are settled so stale suspense work cannot keep rendering suspended.
13+
- Route assets from `head` and `scripts` are projected from the committed match lane after loader data is current, including preloaded navigations, background reloads, and SSR hydration.
14+
- Pending UI and `pendingMinMs` now remain owned by match loading, so long-running `beforeLoad` or loader work does not prematurely clear pending fallbacks.
15+
- SSR hydration now handles dehydrated and data-only matches in a dedicated hydration pass, restoring route context and assets without rerunning client loaders.
16+
- Server loading now has a dedicated path for status codes, redirects, notFound and error responses.
17+
- React, Solid, and Vue match rendering now consume the simplified match readiness model, including aborted loader errors, SSR/data-only pending fallbacks, and stale render snapshots.

‎docs/router/api/router/RouteMatchType.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface RouteMatch {
1111
routeId: string
1212
pathname: string
1313
params: Route['allParams']
14-
status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'
14+
status: 'pending' | 'success' | 'error' | 'notFound'
1515
isFetching: false | 'beforeLoad' | 'loader'
1616
showPending: boolean
1717
error: unknown

‎docs/router/api/router/RouterStateType.md‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ The `RouterState` type represents shape of the internal state of the router. The
99
type RouterState = {
1010
status: 'pending' | 'idle'
1111
isLoading: boolean
12-
isTransitioning: boolean
1312
matches: Array<RouteMatch>
1413
location: ParsedLocation
1514
resolvedLocation: ParsedLocation
@@ -30,11 +29,6 @@ The `RouterState` type contains all of the properties that are available on the
3029
- Type: `boolean`
3130
- `true` if the router is currently loading a route or waiting for a route to finish loading.
3231
33-
### `isTransitioning` property
34-
35-
- Type: `boolean`
36-
- `true` if the router is currently transitioning to a new route.
37-
3832
### `matches` property
3933
4034
- Type: [`Array<RouteMatch>`](./RouteMatchType.md)

‎docs/router/how-to/debug-router-issues.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ function DataLoadingDebug() {
326326

327327
console.log('Route status:', {
328328
isLoading: location.isLoading,
329-
isTransitioning: location.isTransitioning,
330329
})
331330

332331
return null

‎e2e/react-router/basic-file-based/tests/app.spec.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ async function getRenderCount(page: Page) {
246246
return renderCount
247247
}
248248
async function structuralSharingTest(page: Page, enabled: boolean) {
249-
page.goto(`/structural-sharing/${enabled}/?foo=f1&bar=b1`)
249+
await page.goto(`/structural-sharing/${enabled}/?foo=f1&bar=b1`)
250250
await expect(page.getByTestId('enabled')).toHaveText(JSON.stringify(enabled))
251251

252252
async function checkSearch({ foo, bar }: { foo: string; bar: string }) {
@@ -268,9 +268,9 @@ async function structuralSharingTest(page: Page, enabled: boolean) {
268268

269269
test('structural sharing disabled', async ({ page }) => {
270270
await structuralSharingTest(page, false)
271-
expect(await getRenderCount(page)).toBe(2)
271+
expect(await getRenderCount(page)).toBe(3)
272272
await page.getByTestId('link').click()
273-
expect(await getRenderCount(page)).toBeGreaterThan(2)
273+
expect(await getRenderCount(page)).toBeGreaterThan(3)
274274
})
275275

276276
test('structural sharing enabled', async ({ page }) => {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Issue 7120</title>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<script type="module" src="/src/main.tsx"></script>
11+
</body>
12+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "tanstack-router-e2e-react-issue-7120",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "vite --port 3000",
7+
"dev:e2e": "vite",
8+
"build": "vite build && tsc --noEmit",
9+
"preview": "vite preview",
10+
"start": "vite",
11+
"test:e2e": "rm -rf port*.txt; playwright test --project=chromium"
12+
},
13+
"dependencies": {
14+
"@tanstack/react-router": "workspace:^",
15+
"react": "^19.0.0",
16+
"react-dom": "^19.0.0"
17+
},
18+
"devDependencies": {
19+
"@playwright/test": "^1.50.1",
20+
"@tanstack/router-e2e-utils": "workspace:^",
21+
"@types/react": "^19.0.8",
22+
"@types/react-dom": "^19.0.3",
23+
"@vitejs/plugin-react": "^6.0.1",
24+
"vite": "^8.0.14"
25+
}
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
import { getTestServerPort } from '@tanstack/router-e2e-utils'
3+
import packageJson from './package.json' with { type: 'json' }
4+
5+
const PORT = await getTestServerPort(packageJson.name)
6+
const baseURL = `http://localhost:${PORT}`
7+
8+
export default defineConfig({
9+
testDir: './tests',
10+
workers: 1,
11+
reporter: [['line']],
12+
use: {
13+
baseURL,
14+
},
15+
webServer: {
16+
command: `VITE_NODE_ENV="test" VITE_SERVER_PORT=${PORT} pnpm build && pnpm preview --port ${PORT}`,
17+
url: baseURL,
18+
reuseExistingServer: !process.env.CI,
19+
stdout: 'pipe',
20+
},
21+
projects: [
22+
{
23+
name: 'chromium',
24+
use: { ...devices['Desktop Chrome'] },
25+
},
26+
],
27+
})
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import ReactDOM from 'react-dom/client'
2+
import {
3+
Outlet,
4+
RouterProvider,
5+
createRootRoute,
6+
createRoute,
7+
createRouter,
8+
redirect,
9+
} from '@tanstack/react-router'
10+
11+
const posts = [
12+
{
13+
id: '1',
14+
title: 'sunt aut facere repellat provident occaecati',
15+
},
16+
]
17+
18+
const rootRoute = createRootRoute({
19+
component: RootComponent,
20+
pendingMs: 0,
21+
pendingComponent: () => {
22+
;(globalThis as any).__pendingSeen = true
23+
return <div data-testid="root-pending">loading</div>
24+
},
25+
beforeLoad: async ({ matches }) => {
26+
if (matches.find((match) => match.routeId === '/posts')) {
27+
return
28+
}
29+
30+
await new Promise((resolve) => setTimeout(resolve, 1000))
31+
throw redirect({ to: '/posts' })
32+
},
33+
})
34+
35+
function RootComponent() {
36+
return <Outlet />
37+
}
38+
39+
const indexRoute = createRoute({
40+
getParentRoute: () => rootRoute,
41+
path: '/',
42+
component: () => <div>Home</div>,
43+
})
44+
45+
const postsRoute = createRoute({
46+
getParentRoute: () => rootRoute,
47+
path: 'posts',
48+
loader: async () => {
49+
await new Promise((resolve) => setTimeout(resolve, 10))
50+
return posts
51+
},
52+
}).lazy(() => import('./posts.lazy').then((d) => d.Route))
53+
54+
const routeTree = rootRoute.addChildren([indexRoute, postsRoute])
55+
56+
const router = createRouter({
57+
routeTree,
58+
defaultViewTransition: true,
59+
})
60+
61+
declare module '@tanstack/react-router' {
62+
interface Register {
63+
router: typeof router
64+
}
65+
}
66+
67+
const rootElement = document.getElementById('app')!
68+
69+
if (!rootElement.innerHTML) {
70+
const root = ReactDOM.createRoot(rootElement)
71+
root.render(<RouterProvider router={router} />)
72+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Link, createLazyRoute } from '@tanstack/react-router'
2+
3+
export const Route = createLazyRoute('/posts')({
4+
component: PostsComponent,
5+
})
6+
7+
function PostsComponent() {
8+
const posts = Route.useLoaderData()
9+
10+
return (
11+
<div>
12+
<ul>
13+
{posts.map((post) => {
14+
return (
15+
<li key={post.id}>
16+
<Link to="/posts">
17+
<div>{post.title.substring(0, 20)}</div>
18+
</Link>
19+
</li>
20+
)
21+
})}
22+
</ul>
23+
</div>
24+
)
25+
}

0 commit comments

Comments
 (0)