Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

workload.tsx

81 lines1.7 KB

1import { Link, useParams, useSearch } from '@tanstack/react-router'
2​
3const probes = Array.from({ length: 10 }, (_, index) => index)
4​
5function runSelectorWork(input: string, salt: number) {
6 let value = salt
7​
8 for (let index = 0; index < input.length; index++) {
9 value = (value * 33 + input.charCodeAt(index) + index) >>> 0
10 }
11​
12 for (let index = 0; index < 16; index++) {
13 value = (value ^ (value << 13)) >>> 0
14 value = (value ^ (value >> 17)) >>> 0
15 value = (value ^ (value << 5)) >>> 0
16 }
17​
18 return value
20​
21function ParamsProbe({ salt }: { salt: number }) {
22 const params = useParams({
23 strict: false,
24 select: (nextParams) =>
25 runSelectorWork(
26 `${nextParams.a ?? ''}/${nextParams.b ?? ''}/${nextParams.c ?? ''}/${nextParams.d ?? ''}`,
27 salt,
28 ),
29 })
30​
31 void params
32​
33 return null
35​
36function SearchProbe({ salt }: { salt: number }) {
37 const search = useSearch({
38 strict: false,
39 select: (nextSearch) => runSelectorWork(String(nextSearch.q ?? ''), salt),
40 })
41​
42 void search
43​
44 return null
46​
47function LinkProbe({ salt }: { salt: number }) {
48 const value = String((salt % 97) + 1)
49​
50 return (
51 <Link
52 to="/$a/$b/$c/$d"
53 params={{
54 a: `a-${value}`,
55 b: `b-${value}`,
56 c: `c-${value}`,
57 d: `d-${value}`,
58 }}
59 search={{ q: `q-${value}` }}
60 preload={false}
61 >
62 Link
63 </Link>
64 )
66​
67export function RouteWorkload() {
68 return (
69 <>
70 {probes.map((probe) => (
71 <ParamsProbe key={`params-${probe}`} salt={probe + 1} />
72 ))}
73 {probes.map((probe) => (
74 <SearchProbe key={`search-${probe}`} salt={probe + 11} />
75 ))}
76 {probes.map((probe) => (
77 <LinkProbe key={`link-${probe}`} salt={probe + 21} />
78 ))}
79 </>
80 )