Skip to content

Commit 3b61ca2

Browse files
authored
test(react-start): new profiling scenario for search/loader/redirect (#6511)
1 parent 80bb8dd commit 3b61ca2

File tree

3 files changed

+80
-8
lines changed

3 files changed

+80
-8
lines changed

e2e/react-start/flamegraph-bench/src/routeTree.gen.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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 SearchRouteImport } from './routes/search'
1213
import { Route as IndexRouteImport } from './routes/index'
1314
import { Route as PageIdRouteImport } from './routes/page.$id'
1415
import { Route as NestedARouteImport } from './routes/nested/$a'
@@ -38,6 +39,11 @@ import { Route as NestedABCDEFGHIJKLMNOPQRSTUVWXRouteImport } from './routes/nes
3839
import { Route as NestedABCDEFGHIJKLMNOPQRSTUVWXYRouteImport } from './routes/nested/$a.$b.$c.$d.$e.$f.$g.$h.$i.$j.$k.$l.$m.$n.$o.$p.$q.$r.$s.$t.$u.$v.$w.$x.$y'
3940
import { Route as NestedABCDEFGHIJKLMNOPQRSTUVWXYZRouteImport } from './routes/nested/$a.$b.$c.$d.$e.$f.$g.$h.$i.$j.$k.$l.$m.$n.$o.$p.$q.$r.$s.$t.$u.$v.$w.$x.$y.$z'
4041

42+
const SearchRoute = SearchRouteImport.update({
43+
id: '/search',
44+
path: '/search',
45+
getParentRoute: () => rootRouteImport,
46+
} as any)
4147
const IndexRoute = IndexRouteImport.update({
4248
id: '/',
4349
path: '/',
@@ -190,6 +196,7 @@ const NestedABCDEFGHIJKLMNOPQRSTUVWXYZRoute =
190196

191197
export interface FileRoutesByFullPath {
192198
'/': typeof IndexRoute
199+
'/search': typeof SearchRoute
193200
'/nested/$a': typeof NestedARouteWithChildren
194201
'/page/$id': typeof PageIdRoute
195202
'/nested/$a/$b': typeof NestedABRouteWithChildren
@@ -220,6 +227,7 @@ export interface FileRoutesByFullPath {
220227
}
221228
export interface FileRoutesByTo {
222229
'/': typeof IndexRoute
230+
'/search': typeof SearchRoute
223231
'/nested/$a': typeof NestedARouteWithChildren
224232
'/page/$id': typeof PageIdRoute
225233
'/nested/$a/$b': typeof NestedABRouteWithChildren
@@ -251,6 +259,7 @@ export interface FileRoutesByTo {
251259
export interface FileRoutesById {
252260
__root__: typeof rootRouteImport
253261
'/': typeof IndexRoute
262+
'/search': typeof SearchRoute
254263
'/nested/$a': typeof NestedARouteWithChildren
255264
'/page/$id': typeof PageIdRoute
256265
'/nested/$a/$b': typeof NestedABRouteWithChildren
@@ -283,6 +292,7 @@ export interface FileRouteTypes {
283292
fileRoutesByFullPath: FileRoutesByFullPath
284293
fullPaths:
285294
| '/'
295+
| '/search'
286296
| '/nested/$a'
287297
| '/page/$id'
288298
| '/nested/$a/$b'
@@ -313,6 +323,7 @@ export interface FileRouteTypes {
313323
fileRoutesByTo: FileRoutesByTo
314324
to:
315325
| '/'
326+
| '/search'
316327
| '/nested/$a'
317328
| '/page/$id'
318329
| '/nested/$a/$b'
@@ -343,6 +354,7 @@ export interface FileRouteTypes {
343354
id:
344355
| '__root__'
345356
| '/'
357+
| '/search'
346358
| '/nested/$a'
347359
| '/page/$id'
348360
| '/nested/$a/$b'
@@ -374,12 +386,20 @@ export interface FileRouteTypes {
374386
}
375387
export interface RootRouteChildren {
376388
IndexRoute: typeof IndexRoute
389+
SearchRoute: typeof SearchRoute
377390
NestedARoute: typeof NestedARouteWithChildren
378391
PageIdRoute: typeof PageIdRoute
379392
}
380393

381394
declare module '@tanstack/react-router' {
382395
interface FileRoutesByPath {
396+
'/search': {
397+
id: '/search'
398+
path: '/search'
399+
fullPath: '/search'
400+
preLoaderRoute: typeof SearchRouteImport
401+
parentRoute: typeof rootRouteImport
402+
}
383403
'/': {
384404
id: '/'
385405
path: '/'
@@ -903,6 +923,7 @@ const NestedARouteWithChildren =
903923

904924
const rootRouteChildren: RootRouteChildren = {
905925
IndexRoute: IndexRoute,
926+
SearchRoute: SearchRoute,
906927
NestedARoute: NestedARouteWithChildren,
907928
PageIdRoute: PageIdRoute,
908929
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
createFileRoute,
3+
useLoaderData,
4+
useSearch,
5+
} from '@tanstack/react-router'
6+
7+
export const Route = createFileRoute('/search')({
8+
validateSearch: (search: Record<string, any>) => ({
9+
q: search.q as string | undefined,
10+
game: search.game as string | undefined,
11+
set: search.set as string | undefined,
12+
rarity: search.rarity as string | undefined,
13+
page: Number(search.page) || 1,
14+
limit: 24,
15+
sort: search.sort,
16+
order: search.order,
17+
minPrice: search.minPrice ? Number(search.minPrice) : undefined,
18+
maxPrice: search.maxPrice ? Number(search.maxPrice) : undefined,
19+
}),
20+
loaderDeps: ({ search }) => search,
21+
loader: async ({ deps }) => {
22+
return Promise.resolve(deps)
23+
},
24+
component: SearchPage,
25+
})
26+
27+
function SearchPage() {
28+
const q = useSearch({
29+
from: '/search',
30+
select: (s) => (s as any).q,
31+
})
32+
const page = useLoaderData({
33+
from: '/search',
34+
select: (d: any) => d.page,
35+
})
36+
return (
37+
<div>
38+
<p>q: {q as any}</p>
39+
<p>page: {page as any}</p>
40+
</div>
41+
)
42+
}

e2e/react-start/flamegraph-bench/tests/bench.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,26 @@ const instance = autocannon({
1919
// ],
2020

2121
// Test nested routes + useParams
22+
// requests: [
23+
// {
24+
// setupRequest: (req) => {
25+
// // Shuffle the alphabet for each request
26+
// const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('')
27+
// for (let i = alphabet.length - 1; i > 0; i--) {
28+
// const j = Math.floor(Math.random() * (i + 1))
29+
// ;[alphabet[i], alphabet[j]] = [alphabet[j], alphabet[i]]
30+
// }
31+
// const path = '/nested/' + alphabet.join('/')
32+
// return { ...req, path }
33+
// },
34+
// },
35+
// ],
36+
37+
// Test search params + loader + loader deps + useLoaderData
2238
requests: [
2339
{
2440
setupRequest: (req) => {
25-
// Shuffle the alphabet for each request
26-
const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('')
27-
for (let i = alphabet.length - 1; i > 0; i--) {
28-
const j = Math.floor(Math.random() * (i + 1))
29-
;[alphabet[i], alphabet[j]] = [alphabet[j], alphabet[i]]
30-
}
31-
const path = '/nested/' + alphabet.join('/')
32-
return { ...req, path }
41+
return { ...req, path: `/search?q=${Math.random()}` }
3342
},
3443
},
3544
],

0 commit comments

Comments
 (0)