-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: generator improvements #6296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ages/router-generator/tests/generator/virtual-physical-empty-path-conflict-root/routes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { physical, rootRoute } from '@tanstack/virtual-file-routes' | ||
|
|
||
| // This test verifies that a __root.tsx in a physical directory mounted at root | ||
| // produces a proper conflict error with the virtual root | ||
| export const routes = rootRoute('__root.tsx', [physical('', 'merged')]) |
5 changes: 5 additions & 0 deletions
5
...ter-generator/tests/generator/virtual-physical-empty-path-conflict-root/routes/__root.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { createRootRoute, Outlet } from '@tanstack/react-router' | ||
|
|
||
| export const Route = createRootRoute({ | ||
| component: () => <Outlet />, | ||
| }) |
5 changes: 5 additions & 0 deletions
5
...nerator/tests/generator/virtual-physical-empty-path-conflict-root/routes/merged/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
|
|
||
| export const Route = createFileRoute('/')({ | ||
| component: () => <div>Index</div>, | ||
| }) |
5 changes: 5 additions & 0 deletions
5
...nerator/tests/generator/virtual-physical-empty-path-conflict-root/routes/merged/route.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
|
|
||
| // This route.tsx in a physical directory mounted at root level | ||
| // conflicts with the virtual root __root.tsx - can't have two root routes | ||
| export const Route = createFileRoute('')({}) |
5 changes: 5 additions & 0 deletions
5
...outer-generator/tests/generator/virtual-physical-empty-path-conflict-root/tsr.config.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "routesDirectory": "./routes", | ||
| "generatedRouteTree": "./routeTree.gen.ts", | ||
| "virtualRouteConfig": "./routes.ts" | ||
| } |
8 changes: 8 additions & 0 deletions
8
...s/router-generator/tests/generator/virtual-physical-empty-path-conflict-virtual/routes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { physical, rootRoute, route } from '@tanstack/virtual-file-routes' | ||
|
|
||
| // This test verifies that a virtual route path conflicts with | ||
| // a physical route path when using empty path prefix | ||
| export const routes = rootRoute('__root.tsx', [ | ||
| route('/about', 'about.tsx'), // virtual /about | ||
| physical('', 'merged'), // physical also has about.tsx -> /about | ||
| ]) |
5 changes: 5 additions & 0 deletions
5
...-generator/tests/generator/virtual-physical-empty-path-conflict-virtual/routes/__root.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { createRootRoute, Outlet } from '@tanstack/react-router' | ||
|
|
||
| export const Route = createRootRoute({ | ||
| component: () => <Outlet />, | ||
| }) |
6 changes: 6 additions & 0 deletions
6
...r-generator/tests/generator/virtual-physical-empty-path-conflict-virtual/routes/about.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
|
|
||
| // Virtual about route - conflicts with merged/about.tsx | ||
| export const Route = createFileRoute('/about')({ | ||
| component: () => <div>About (virtual)</div>, | ||
| }) |
6 changes: 6 additions & 0 deletions
6
...ator/tests/generator/virtual-physical-empty-path-conflict-virtual/routes/merged/about.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
|
|
||
| // Physical about route - conflicts with virtual about.tsx -> /about | ||
| export const Route = createFileRoute('/about')({ | ||
| component: () => <div>About (physical)</div>, | ||
| }) |
5 changes: 5 additions & 0 deletions
5
...ator/tests/generator/virtual-physical-empty-path-conflict-virtual/routes/merged/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
|
|
||
| export const Route = createFileRoute('/')({ | ||
| component: () => <div>Index</div>, | ||
| }) |
5 changes: 5 additions & 0 deletions
5
...er-generator/tests/generator/virtual-physical-empty-path-conflict-virtual/tsr.config.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "routesDirectory": "./routes", | ||
| "generatedRouteTree": "./routeTree.gen.ts", | ||
| "virtualRouteConfig": "./routes.ts" | ||
| } |
95 changes: 95 additions & 0 deletions
95
.../router-generator/tests/generator/virtual-physical-empty-path-merge/routeTree.snapshot.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* eslint-disable */ | ||
|
|
||
| // @ts-nocheck | ||
|
|
||
| // noinspection JSUnusedGlobalSymbols | ||
|
|
||
| // This file was automatically generated by TanStack Router. | ||
| // You should NOT make any changes in this file as it will be overwritten. | ||
| // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. | ||
|
|
||
| import { Route as rootRouteImport } from './routes/__root' | ||
| import { Route as ContactRouteImport } from './routes/merged/contact' | ||
| import { Route as aboutRouteImport } from './routes/about' | ||
| import { Route as IndexRouteImport } from './routes/merged/index' | ||
|
|
||
| const ContactRoute = ContactRouteImport.update({ | ||
| id: '/contact', | ||
| path: '/contact', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const aboutRoute = aboutRouteImport.update({ | ||
| id: '/about', | ||
| path: '/about', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const IndexRoute = IndexRouteImport.update({ | ||
| id: '/', | ||
| path: '/', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
|
|
||
| export interface FileRoutesByFullPath { | ||
| '/': typeof IndexRoute | ||
| '/about': typeof aboutRoute | ||
| '/contact': typeof ContactRoute | ||
| } | ||
| export interface FileRoutesByTo { | ||
| '/': typeof IndexRoute | ||
| '/about': typeof aboutRoute | ||
| '/contact': typeof ContactRoute | ||
| } | ||
| export interface FileRoutesById { | ||
| __root__: typeof rootRouteImport | ||
| '/': typeof IndexRoute | ||
| '/about': typeof aboutRoute | ||
| '/contact': typeof ContactRoute | ||
| } | ||
| export interface FileRouteTypes { | ||
| fileRoutesByFullPath: FileRoutesByFullPath | ||
| fullPaths: '/' | '/about' | '/contact' | ||
| fileRoutesByTo: FileRoutesByTo | ||
| to: '/' | '/about' | '/contact' | ||
| id: '__root__' | '/' | '/about' | '/contact' | ||
| fileRoutesById: FileRoutesById | ||
| } | ||
| export interface RootRouteChildren { | ||
| IndexRoute: typeof IndexRoute | ||
| aboutRoute: typeof aboutRoute | ||
| ContactRoute: typeof ContactRoute | ||
| } | ||
|
|
||
| declare module '@tanstack/react-router' { | ||
| interface FileRoutesByPath { | ||
| '/contact': { | ||
| id: '/contact' | ||
| path: '/contact' | ||
| fullPath: '/contact' | ||
| preLoaderRoute: typeof ContactRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/about': { | ||
| id: '/about' | ||
| path: '/about' | ||
| fullPath: '/about' | ||
| preLoaderRoute: typeof aboutRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/': { | ||
| id: '/' | ||
| path: '/' | ||
| fullPath: '/' | ||
| preLoaderRoute: typeof IndexRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const rootRouteChildren: RootRouteChildren = { | ||
| IndexRoute: IndexRoute, | ||
| aboutRoute: aboutRoute, | ||
| ContactRoute: ContactRoute, | ||
| } | ||
| export const routeTree = rootRouteImport | ||
| ._addFileChildren(rootRouteChildren) | ||
| ._addFileTypes<FileRouteTypes>() |
8 changes: 8 additions & 0 deletions
8
packages/router-generator/tests/generator/virtual-physical-empty-path-merge/routes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { physical, rootRoute, route } from '@tanstack/virtual-file-routes' | ||
|
|
||
| export const routes = rootRoute('__root.tsx', [ | ||
| // Virtual route defined here | ||
| route('/about', 'about.tsx'), | ||
| // Physical mount with empty path - should merge into root level | ||
| physical('', 'merged'), | ||
| ]) |
3 changes: 3 additions & 0 deletions
3
...ages/router-generator/tests/generator/virtual-physical-empty-path-merge/routes/__root.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { createRootRoute } from '@tanstack/react-router' | ||
|
|
||
| export const Route = createRootRoute() | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
2 changes: 2 additions & 0 deletions
2
packages/router-generator/tests/generator/virtual-physical-empty-path-merge/routes/about.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
| export const Route = createFileRoute('/about')() |
2 changes: 2 additions & 0 deletions
2
...ter-generator/tests/generator/virtual-physical-empty-path-merge/routes/merged/contact.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
| export const Route = createFileRoute('/contact')() |
2 changes: 2 additions & 0 deletions
2
...outer-generator/tests/generator/virtual-physical-empty-path-merge/routes/merged/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
| export const Route = createFileRoute('/')() |
5 changes: 5 additions & 0 deletions
5
packages/router-generator/tests/generator/virtual-physical-empty-path-merge/tsr.config.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "routesDirectory": "./routes", | ||
| "generatedRouteTree": "./routeTree.gen.ts", | ||
| "virtualRouteConfig": "./routes.ts" | ||
| } |
95 changes: 95 additions & 0 deletions
95
packages/router-generator/tests/generator/virtual-physical-no-prefix/routeTree.snapshot.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* eslint-disable */ | ||
|
|
||
| // @ts-nocheck | ||
|
|
||
| // noinspection JSUnusedGlobalSymbols | ||
|
|
||
| // This file was automatically generated by TanStack Router. | ||
| // You should NOT make any changes in this file as it will be overwritten. | ||
| // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. | ||
|
|
||
| import { Route as rootRouteImport } from './routes/__root' | ||
| import { Route as ContactRouteImport } from './routes/merged/contact' | ||
| import { Route as aboutRouteImport } from './routes/about' | ||
| import { Route as IndexRouteImport } from './routes/merged/index' | ||
|
|
||
| const ContactRoute = ContactRouteImport.update({ | ||
| id: '/contact', | ||
| path: '/contact', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const aboutRoute = aboutRouteImport.update({ | ||
| id: '/about', | ||
| path: '/about', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const IndexRoute = IndexRouteImport.update({ | ||
| id: '/', | ||
| path: '/', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
|
|
||
| export interface FileRoutesByFullPath { | ||
| '/': typeof IndexRoute | ||
| '/about': typeof aboutRoute | ||
| '/contact': typeof ContactRoute | ||
| } | ||
| export interface FileRoutesByTo { | ||
| '/': typeof IndexRoute | ||
| '/about': typeof aboutRoute | ||
| '/contact': typeof ContactRoute | ||
| } | ||
| export interface FileRoutesById { | ||
| __root__: typeof rootRouteImport | ||
| '/': typeof IndexRoute | ||
| '/about': typeof aboutRoute | ||
| '/contact': typeof ContactRoute | ||
| } | ||
| export interface FileRouteTypes { | ||
| fileRoutesByFullPath: FileRoutesByFullPath | ||
| fullPaths: '/' | '/about' | '/contact' | ||
| fileRoutesByTo: FileRoutesByTo | ||
| to: '/' | '/about' | '/contact' | ||
| id: '__root__' | '/' | '/about' | '/contact' | ||
| fileRoutesById: FileRoutesById | ||
| } | ||
| export interface RootRouteChildren { | ||
| IndexRoute: typeof IndexRoute | ||
| aboutRoute: typeof aboutRoute | ||
| ContactRoute: typeof ContactRoute | ||
| } | ||
|
|
||
| declare module '@tanstack/react-router' { | ||
| interface FileRoutesByPath { | ||
| '/contact': { | ||
| id: '/contact' | ||
| path: '/contact' | ||
| fullPath: '/contact' | ||
| preLoaderRoute: typeof ContactRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/about': { | ||
| id: '/about' | ||
| path: '/about' | ||
| fullPath: '/about' | ||
| preLoaderRoute: typeof aboutRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/': { | ||
| id: '/' | ||
| path: '/' | ||
| fullPath: '/' | ||
| preLoaderRoute: typeof IndexRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const rootRouteChildren: RootRouteChildren = { | ||
| IndexRoute: IndexRoute, | ||
| aboutRoute: aboutRoute, | ||
| ContactRoute: ContactRoute, | ||
| } | ||
| export const routeTree = rootRouteImport | ||
| ._addFileChildren(rootRouteChildren) | ||
| ._addFileTypes<FileRouteTypes>() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify language identifier for fenced code block.
The fenced code block showing the file structure should have a language identifier for better rendering and accessibility.
🔎 Proposed fix
In docs/router/framework/react/routing/virtual-file-routes.md around lines 233
to 241, the fenced code block showing the file structure lacks a language
identifier; update the opening fence to include a language (e.g., use ```text)
so the block is rendered correctly and improves accessibility/semantics in docs.