Skip to content

Commit 22bb4e0

Browse files
fix: various fixes (#5593)
1 parent 91d9940 commit 22bb4e0

File tree

18 files changed

+341
-71
lines changed

18 files changed

+341
-71
lines changed

e2e/react-start/server-functions/tests/server-functions.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ test('primitives', async ({ page }) => {
450450
const testCases = await page
451451
.locator('[data-testid^="expected-"]')
452452
.elementHandles()
453+
expect(testCases.length).not.toBe(0)
454+
453455
for (const testCase of testCases) {
454456
const testId = await testCase.getAttribute('data-testid')
455457

e2e/react-start/server-routes/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
"test:e2e": "playwright test --project=chromium"
1212
},
1313
"dependencies": {
14+
"@tanstack/react-query": "5.66.0",
1415
"@tanstack/react-router": "workspace:^",
1516
"@tanstack/react-router-devtools": "workspace:^",
17+
"@tanstack/react-router-ssr-query": "workspace:^",
1618
"@tanstack/react-start": "workspace:^",
1719
"js-cookie": "^3.0.5",
1820
"react": "^19.0.0",

e2e/react-start/server-routes/src/routeTree.gen.ts

Lines changed: 111 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,46 @@
99
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
1010

1111
import { Route as rootRouteImport } from './routes/__root'
12-
import { Route as MergeServerFnMiddlewareContextRouteImport } from './routes/merge-server-fn-middleware-context'
12+
import { Route as MergeMiddlewareContextRouteImport } from './routes/merge-middleware-context'
13+
import { Route as MethodsRouteRouteImport } from './routes/methods/route'
1314
import { Route as IndexRouteImport } from './routes/index'
15+
import { Route as MethodsIndexRouteImport } from './routes/methods/index'
16+
import { Route as MethodsOnlyAnyRouteImport } from './routes/methods/only-any'
17+
import { Route as ApiOnlyAnyRouteImport } from './routes/api/only-any'
1418
import { Route as ApiMiddlewareContextRouteImport } from './routes/api/middleware-context'
1519
import { Route as ApiParamsFooRouteRouteImport } from './routes/api/params/$foo/route'
1620
import { Route as ApiParamsFooBarRouteImport } from './routes/api/params/$foo/$bar'
1721

18-
const MergeServerFnMiddlewareContextRoute =
19-
MergeServerFnMiddlewareContextRouteImport.update({
20-
id: '/merge-server-fn-middleware-context',
21-
path: '/merge-server-fn-middleware-context',
22-
getParentRoute: () => rootRouteImport,
23-
} as any)
22+
const MergeMiddlewareContextRoute = MergeMiddlewareContextRouteImport.update({
23+
id: '/merge-middleware-context',
24+
path: '/merge-middleware-context',
25+
getParentRoute: () => rootRouteImport,
26+
} as any)
27+
const MethodsRouteRoute = MethodsRouteRouteImport.update({
28+
id: '/methods',
29+
path: '/methods',
30+
getParentRoute: () => rootRouteImport,
31+
} as any)
2432
const IndexRoute = IndexRouteImport.update({
2533
id: '/',
2634
path: '/',
2735
getParentRoute: () => rootRouteImport,
2836
} as any)
37+
const MethodsIndexRoute = MethodsIndexRouteImport.update({
38+
id: '/',
39+
path: '/',
40+
getParentRoute: () => MethodsRouteRoute,
41+
} as any)
42+
const MethodsOnlyAnyRoute = MethodsOnlyAnyRouteImport.update({
43+
id: '/only-any',
44+
path: '/only-any',
45+
getParentRoute: () => MethodsRouteRoute,
46+
} as any)
47+
const ApiOnlyAnyRoute = ApiOnlyAnyRouteImport.update({
48+
id: '/api/only-any',
49+
path: '/api/only-any',
50+
getParentRoute: () => rootRouteImport,
51+
} as any)
2952
const ApiMiddlewareContextRoute = ApiMiddlewareContextRouteImport.update({
3053
id: '/api/middleware-context',
3154
path: '/api/middleware-context',
@@ -44,64 +67,95 @@ const ApiParamsFooBarRoute = ApiParamsFooBarRouteImport.update({
4467

4568
export interface FileRoutesByFullPath {
4669
'/': typeof IndexRoute
47-
'/merge-server-fn-middleware-context': typeof MergeServerFnMiddlewareContextRoute
70+
'/methods': typeof MethodsRouteRouteWithChildren
71+
'/merge-middleware-context': typeof MergeMiddlewareContextRoute
4872
'/api/middleware-context': typeof ApiMiddlewareContextRoute
73+
'/api/only-any': typeof ApiOnlyAnyRoute
74+
'/methods/only-any': typeof MethodsOnlyAnyRoute
75+
'/methods/': typeof MethodsIndexRoute
4976
'/api/params/$foo': typeof ApiParamsFooRouteRouteWithChildren
5077
'/api/params/$foo/$bar': typeof ApiParamsFooBarRoute
5178
}
5279
export interface FileRoutesByTo {
5380
'/': typeof IndexRoute
54-
'/merge-server-fn-middleware-context': typeof MergeServerFnMiddlewareContextRoute
81+
'/merge-middleware-context': typeof MergeMiddlewareContextRoute
5582
'/api/middleware-context': typeof ApiMiddlewareContextRoute
83+
'/api/only-any': typeof ApiOnlyAnyRoute
84+
'/methods/only-any': typeof MethodsOnlyAnyRoute
85+
'/methods': typeof MethodsIndexRoute
5686
'/api/params/$foo': typeof ApiParamsFooRouteRouteWithChildren
5787
'/api/params/$foo/$bar': typeof ApiParamsFooBarRoute
5888
}
5989
export interface FileRoutesById {
6090
__root__: typeof rootRouteImport
6191
'/': typeof IndexRoute
62-
'/merge-server-fn-middleware-context': typeof MergeServerFnMiddlewareContextRoute
92+
'/methods': typeof MethodsRouteRouteWithChildren
93+
'/merge-middleware-context': typeof MergeMiddlewareContextRoute
6394
'/api/middleware-context': typeof ApiMiddlewareContextRoute
95+
'/api/only-any': typeof ApiOnlyAnyRoute
96+
'/methods/only-any': typeof MethodsOnlyAnyRoute
97+
'/methods/': typeof MethodsIndexRoute
6498
'/api/params/$foo': typeof ApiParamsFooRouteRouteWithChildren
6599
'/api/params/$foo/$bar': typeof ApiParamsFooBarRoute
66100
}
67101
export interface FileRouteTypes {
68102
fileRoutesByFullPath: FileRoutesByFullPath
69103
fullPaths:
70104
| '/'
71-
| '/merge-server-fn-middleware-context'
105+
| '/methods'
106+
| '/merge-middleware-context'
72107
| '/api/middleware-context'
108+
| '/api/only-any'
109+
| '/methods/only-any'
110+
| '/methods/'
73111
| '/api/params/$foo'
74112
| '/api/params/$foo/$bar'
75113
fileRoutesByTo: FileRoutesByTo
76114
to:
77115
| '/'
78-
| '/merge-server-fn-middleware-context'
116+
| '/merge-middleware-context'
79117
| '/api/middleware-context'
118+
| '/api/only-any'
119+
| '/methods/only-any'
120+
| '/methods'
80121
| '/api/params/$foo'
81122
| '/api/params/$foo/$bar'
82123
id:
83124
| '__root__'
84125
| '/'
85-
| '/merge-server-fn-middleware-context'
126+
| '/methods'
127+
| '/merge-middleware-context'
86128
| '/api/middleware-context'
129+
| '/api/only-any'
130+
| '/methods/only-any'
131+
| '/methods/'
87132
| '/api/params/$foo'
88133
| '/api/params/$foo/$bar'
89134
fileRoutesById: FileRoutesById
90135
}
91136
export interface RootRouteChildren {
92137
IndexRoute: typeof IndexRoute
93-
MergeServerFnMiddlewareContextRoute: typeof MergeServerFnMiddlewareContextRoute
138+
MethodsRouteRoute: typeof MethodsRouteRouteWithChildren
139+
MergeMiddlewareContextRoute: typeof MergeMiddlewareContextRoute
94140
ApiMiddlewareContextRoute: typeof ApiMiddlewareContextRoute
141+
ApiOnlyAnyRoute: typeof ApiOnlyAnyRoute
95142
ApiParamsFooRouteRoute: typeof ApiParamsFooRouteRouteWithChildren
96143
}
97144

98145
declare module '@tanstack/react-router' {
99146
interface FileRoutesByPath {
100-
'/merge-server-fn-middleware-context': {
101-
id: '/merge-server-fn-middleware-context'
102-
path: '/merge-server-fn-middleware-context'
103-
fullPath: '/merge-server-fn-middleware-context'
104-
preLoaderRoute: typeof MergeServerFnMiddlewareContextRouteImport
147+
'/merge-middleware-context': {
148+
id: '/merge-middleware-context'
149+
path: '/merge-middleware-context'
150+
fullPath: '/merge-middleware-context'
151+
preLoaderRoute: typeof MergeMiddlewareContextRouteImport
152+
parentRoute: typeof rootRouteImport
153+
}
154+
'/methods': {
155+
id: '/methods'
156+
path: '/methods'
157+
fullPath: '/methods'
158+
preLoaderRoute: typeof MethodsRouteRouteImport
105159
parentRoute: typeof rootRouteImport
106160
}
107161
'/': {
@@ -111,6 +165,27 @@ declare module '@tanstack/react-router' {
111165
preLoaderRoute: typeof IndexRouteImport
112166
parentRoute: typeof rootRouteImport
113167
}
168+
'/methods/': {
169+
id: '/methods/'
170+
path: '/'
171+
fullPath: '/methods/'
172+
preLoaderRoute: typeof MethodsIndexRouteImport
173+
parentRoute: typeof MethodsRouteRoute
174+
}
175+
'/methods/only-any': {
176+
id: '/methods/only-any'
177+
path: '/only-any'
178+
fullPath: '/methods/only-any'
179+
preLoaderRoute: typeof MethodsOnlyAnyRouteImport
180+
parentRoute: typeof MethodsRouteRoute
181+
}
182+
'/api/only-any': {
183+
id: '/api/only-any'
184+
path: '/api/only-any'
185+
fullPath: '/api/only-any'
186+
preLoaderRoute: typeof ApiOnlyAnyRouteImport
187+
parentRoute: typeof rootRouteImport
188+
}
114189
'/api/middleware-context': {
115190
id: '/api/middleware-context'
116191
path: '/api/middleware-context'
@@ -135,6 +210,20 @@ declare module '@tanstack/react-router' {
135210
}
136211
}
137212

213+
interface MethodsRouteRouteChildren {
214+
MethodsOnlyAnyRoute: typeof MethodsOnlyAnyRoute
215+
MethodsIndexRoute: typeof MethodsIndexRoute
216+
}
217+
218+
const MethodsRouteRouteChildren: MethodsRouteRouteChildren = {
219+
MethodsOnlyAnyRoute: MethodsOnlyAnyRoute,
220+
MethodsIndexRoute: MethodsIndexRoute,
221+
}
222+
223+
const MethodsRouteRouteWithChildren = MethodsRouteRoute._addFileChildren(
224+
MethodsRouteRouteChildren,
225+
)
226+
138227
interface ApiParamsFooRouteRouteChildren {
139228
ApiParamsFooBarRoute: typeof ApiParamsFooBarRoute
140229
}
@@ -148,8 +237,10 @@ const ApiParamsFooRouteRouteWithChildren =
148237

149238
const rootRouteChildren: RootRouteChildren = {
150239
IndexRoute: IndexRoute,
151-
MergeServerFnMiddlewareContextRoute: MergeServerFnMiddlewareContextRoute,
240+
MethodsRouteRoute: MethodsRouteRouteWithChildren,
241+
MergeMiddlewareContextRoute: MergeMiddlewareContextRoute,
152242
ApiMiddlewareContextRoute: ApiMiddlewareContextRoute,
243+
ApiOnlyAnyRoute: ApiOnlyAnyRoute,
153244
ApiParamsFooRouteRoute: ApiParamsFooRouteRouteWithChildren,
154245
}
155246
export const routeTree = rootRouteImport
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { createRouter } from '@tanstack/react-router'
2+
import { setupRouterSsrQueryIntegration } from '@tanstack/react-router-ssr-query'
3+
import { QueryClient } from '@tanstack/react-query'
24
import { routeTree } from './routeTree.gen'
35
import { DefaultCatchBoundary } from './components/DefaultCatchBoundary'
46
import { NotFound } from './components/NotFound'
57

68
export function getRouter() {
9+
const queryClient = new QueryClient()
710
const router = createRouter({
811
routeTree,
912
defaultPreload: 'intent',
1013
defaultErrorComponent: DefaultCatchBoundary,
1114
defaultNotFoundComponent: () => <NotFound />,
1215
scrollRestoration: true,
1316
})
17+
setupRouterSsrQueryIntegration({ router, queryClient })
1418

1519
return router
1620
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
import { json } from '@tanstack/react-start'
3+
4+
export const Route = createFileRoute('/api/only-any')({
5+
server: {
6+
handlers: {
7+
ANY: ({ request }) => {
8+
return json(
9+
{
10+
handler: 'ANY',
11+
method: request.method,
12+
},
13+
{ headers: { 'X-HANDLER': 'ANY', 'X-METHOD': request.method } },
14+
)
15+
},
16+
},
17+
},
18+
})

e2e/react-start/server-routes/src/routes/index.tsx

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

33
export const Route = createFileRoute('/')({
44
component: Home,
@@ -10,9 +10,12 @@ function Home() {
1010
<h1 className="font-bold text-lg">Server Routes E2E tests</h1>
1111
<ul className="list-disc p-4">
1212
<li>
13-
<Link to="/merge-server-fn-middleware-context">
14-
server function middleware context is merged correctly
15-
</Link>
13+
<Route.Link to="./merge-middleware-context">
14+
server route middleware context is merged correctly
15+
</Route.Link>
16+
</li>
17+
<li>
18+
<Route.Link to="./methods">server route methods</Route.Link>
1619
</li>
1720
</ul>
1821
</div>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { createFileRoute } from '@tanstack/react-router'
22
import * as React from 'react'
33

4-
export const Route = createFileRoute('/merge-server-fn-middleware-context')({
5-
component: () => <MergeServerFnMiddlewareContext />,
4+
export const Route = createFileRoute('/merge-middleware-context')({
5+
component: MergeMiddlewareContext,
66
})
77

8-
function MergeServerFnMiddlewareContext() {
8+
function MergeMiddlewareContext() {
99
const [apiResponse, setApiResponse] = React.useState<any>(null)
1010

1111
const fetchMiddlewareContext = async () => {
@@ -21,7 +21,7 @@ function MergeServerFnMiddlewareContext() {
2121

2222
return (
2323
<div className="p-2 m-2 grid gap-2">
24-
<h3>Merge Server Function Middleware Context Test</h3>
24+
<h3>Merge Server Route Middleware Context Test</h3>
2525
<div className="flex flex-col gap-2">
2626
<button
2727
type="button"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/methods/')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
return (
9+
<div className="p-8">
10+
<ul className="list-disc p-4">
11+
<li>
12+
<Route.Link to="./only-any">
13+
Server Route only has ANY handler
14+
</Route.Link>
15+
</li>
16+
</ul>
17+
</div>
18+
)
19+
}

0 commit comments

Comments
 (0)