Skip to content

Commit 105d056

Browse files
fix(router-generator): harden route file transform rewrites (#7167)
1 parent 5b8480d commit 105d056

278 files changed

Lines changed: 2230 additions & 4518 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/clean-lamps-tease.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@tanstack/router-generator': patch
3+
'@tanstack/react-router': patch
4+
'@tanstack/solid-router': patch
5+
'@tanstack/vue-router': patch
6+
---
7+
8+
Fix route file transforms to preserve route ID quoting, handle more exported `Route` patterns, and avoid incorrect import rewrites in edge cases.
9+
10+
Improve transform robustness with clearer route-call detection, safer import removal, and expanded test coverage for quote preservation, constructor swaps, and unsupported route definitions.

‎e2e/react-router/basic-file-based-code-splitting/package.json‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
"build": "vite build && tsc --noEmit",
99
"preview": "vite preview",
1010
"start": "vite",
11-
"test:e2e:verbose-routes:true": "rm -rf port*.txt; VERBOSE_FILE_ROUTES=1 playwright test --project=chromium",
12-
"test:e2e:verbose-routes:false": "rm -rf port*.txt; VERBOSE_FILE_ROUTES=0 playwright test --project=chromium",
13-
"test:e2e": "rm -rf port*.txt; pnpm run test:e2e:verbose-routes:true && pnpm run test:e2e:verbose-routes:false"
11+
"test:e2e": "rm -rf port*.txt; playwright test --project=chromium"
1412
},
1513
"dependencies": {
1614
"@tailwindcss/vite": "^4.2.2",

‎e2e/react-router/basic-file-based-code-splitting/src/routeTree.gen.ts‎

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// You should NOT make any changes in this file as it will be overwritten.
99
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
1010

11-
import type { CreateFileRoute, FileRoutesByPath } from '@tanstack/react-router'
12-
1311
import { Route as rootRouteImport } from './routes/__root'
1412
import { Route as WithoutLoaderRouteImport } from './routes/without-loader'
1513
import { Route as ViewportTestRouteImport } from './routes/viewport-test'
@@ -240,106 +238,6 @@ declare module '@tanstack/react-router' {
240238
}
241239
}
242240

243-
declare module './routes/index' {
244-
const createFileRoute: CreateFileRoute<
245-
'/',
246-
FileRoutesByPath['/']['parentRoute'],
247-
FileRoutesByPath['/']['id'],
248-
FileRoutesByPath['/']['path'],
249-
FileRoutesByPath['/']['fullPath']
250-
>
251-
}
252-
declare module './routes/_layout' {
253-
const createFileRoute: CreateFileRoute<
254-
'/_layout',
255-
FileRoutesByPath['/_layout']['parentRoute'],
256-
FileRoutesByPath['/_layout']['id'],
257-
FileRoutesByPath['/_layout']['path'],
258-
FileRoutesByPath['/_layout']['fullPath']
259-
>
260-
}
261-
declare module './routes/posts' {
262-
const createFileRoute: CreateFileRoute<
263-
'/posts',
264-
FileRoutesByPath['/posts']['parentRoute'],
265-
FileRoutesByPath['/posts']['id'],
266-
FileRoutesByPath['/posts']['path'],
267-
FileRoutesByPath['/posts']['fullPath']
268-
>
269-
}
270-
declare module './routes/shared-singleton' {
271-
const createFileRoute: CreateFileRoute<
272-
'/shared-singleton',
273-
FileRoutesByPath['/shared-singleton']['parentRoute'],
274-
FileRoutesByPath['/shared-singleton']['id'],
275-
FileRoutesByPath['/shared-singleton']['path'],
276-
FileRoutesByPath['/shared-singleton']['fullPath']
277-
>
278-
}
279-
declare module './routes/viewport-test' {
280-
const createFileRoute: CreateFileRoute<
281-
'/viewport-test',
282-
FileRoutesByPath['/viewport-test']['parentRoute'],
283-
FileRoutesByPath['/viewport-test']['id'],
284-
FileRoutesByPath['/viewport-test']['path'],
285-
FileRoutesByPath['/viewport-test']['fullPath']
286-
>
287-
}
288-
declare module './routes/without-loader' {
289-
const createFileRoute: CreateFileRoute<
290-
'/without-loader',
291-
FileRoutesByPath['/without-loader']['parentRoute'],
292-
FileRoutesByPath['/without-loader']['id'],
293-
FileRoutesByPath['/without-loader']['path'],
294-
FileRoutesByPath['/without-loader']['fullPath']
295-
>
296-
}
297-
declare module './routes/_layout/_layout-2' {
298-
const createFileRoute: CreateFileRoute<
299-
'/_layout/_layout-2',
300-
FileRoutesByPath['/_layout/_layout-2']['parentRoute'],
301-
FileRoutesByPath['/_layout/_layout-2']['id'],
302-
FileRoutesByPath['/_layout/_layout-2']['path'],
303-
FileRoutesByPath['/_layout/_layout-2']['fullPath']
304-
>
305-
}
306-
declare module './routes/posts.$postId' {
307-
const createFileRoute: CreateFileRoute<
308-
'/posts/$postId',
309-
FileRoutesByPath['/posts/$postId']['parentRoute'],
310-
FileRoutesByPath['/posts/$postId']['id'],
311-
FileRoutesByPath['/posts/$postId']['path'],
312-
FileRoutesByPath['/posts/$postId']['fullPath']
313-
>
314-
}
315-
declare module './routes/posts.index' {
316-
const createFileRoute: CreateFileRoute<
317-
'/posts/',
318-
FileRoutesByPath['/posts/']['parentRoute'],
319-
FileRoutesByPath['/posts/']['id'],
320-
FileRoutesByPath['/posts/']['path'],
321-
FileRoutesByPath['/posts/']['fullPath']
322-
>
323-
}
324-
declare module './routes/_layout/_layout-2/layout-a' {
325-
const createFileRoute: CreateFileRoute<
326-
'/_layout/_layout-2/layout-a',
327-
FileRoutesByPath['/_layout/_layout-2/layout-a']['parentRoute'],
328-
FileRoutesByPath['/_layout/_layout-2/layout-a']['id'],
329-
FileRoutesByPath['/_layout/_layout-2/layout-a']['path'],
330-
FileRoutesByPath['/_layout/_layout-2/layout-a']['fullPath']
331-
>
332-
}
333-
declare module './routes/_layout/_layout-2/layout-b' {
334-
const createFileRoute: CreateFileRoute<
335-
'/_layout/_layout-2/layout-b',
336-
FileRoutesByPath['/_layout/_layout-2/layout-b']['parentRoute'],
337-
FileRoutesByPath['/_layout/_layout-2/layout-b']['id'],
338-
FileRoutesByPath['/_layout/_layout-2/layout-b']['path'],
339-
FileRoutesByPath['/_layout/_layout-2/layout-b']['fullPath']
340-
>
341-
}
342-
343241
interface LayoutLayout2RouteChildren {
344242
LayoutLayout2LayoutARoute: typeof LayoutLayout2LayoutARoute
345243
LayoutLayout2LayoutBRoute: typeof LayoutLayout2LayoutBRoute

‎e2e/react-router/basic-file-based-code-splitting/src/routes/_layout.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Outlet } from '@tanstack/react-router'
1+
import { Outlet, createFileRoute } from '@tanstack/react-router'
22

3-
export const Route = createFileRoute({
3+
export const Route = createFileRoute('/_layout')({
44
component: LayoutComponent,
55
})
66

‎e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Link, Outlet } from '@tanstack/react-router'
1+
import { Link, Outlet, createFileRoute } from '@tanstack/react-router'
22

3-
export const Route = createFileRoute({
3+
export const Route = createFileRoute('/_layout/_layout-2')({
44
component: LayoutComponent,
55
})
66

‎e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2/layout-a.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export const Route = createFileRoute({
1+
import { createFileRoute } from '@tanstack/react-router'
2+
export const Route = createFileRoute('/_layout/_layout-2/layout-a')({
23
component: LayoutAComponent,
34
})
45

‎e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2/layout-b.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export const Route = createFileRoute({
1+
import { createFileRoute } from '@tanstack/react-router'
2+
export const Route = createFileRoute('/_layout/_layout-2/layout-b')({
23
component: LayoutBComponent,
34
})
45

‎e2e/react-router/basic-file-based-code-splitting/src/routes/index.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { createFileRoute } from '@tanstack/react-router'
12
import * as React from 'react'
23

3-
export const Route = createFileRoute({
4+
export const Route = createFileRoute('/')({
45
component: Home,
56
})
67

‎e2e/react-router/basic-file-based-code-splitting/src/routes/posts.$postId.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from 'react'
2-
import { ErrorComponent } from '@tanstack/react-router'
2+
import { ErrorComponent, createFileRoute } from '@tanstack/react-router'
33
import { fetchPost } from '../posts'
44
import type { ErrorComponentProps } from '@tanstack/react-router'
55

6-
export const Route = createFileRoute({
6+
export const Route = createFileRoute('/posts/$postId')({
77
loader: async ({ params: { postId } }) => fetchPost(postId),
88
errorComponent: PostErrorComponent as any,
99
notFoundComponent: () => {

‎e2e/react-router/basic-file-based-code-splitting/src/routes/posts.index.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { createFileRoute } from '@tanstack/react-router'
12
import * as React from 'react'
23

3-
export const Route = createFileRoute({
4+
export const Route = createFileRoute('/posts/')({
45
component: PostsIndexComponent,
56
})
67

0 commit comments

Comments
 (0)