Skip to content
Source
Sign inSign up
TanStack/router

perf: geting lazy?, doing less work? generate more (plus some recommendations) #1564

Mergedchorobin(GitHub profile, opens in a new tab)merged 12 commits intomain fromrefs/pull/1564/headmerged by chorobin(GitHub profile, opens in a new tab)

Showing 29 changed files with 166 additions and 1 deletion (loading 23).

x
0 of 29 viewed, 29 left
137 additions and 0 deletionsdocs/framework/react/guide/type-safety.mdModified
View file
@@ -110,3 +110,140 @@
```
+​
+## Performance Recommendations
+​
+As your application scales, TypeScript check times will naturally increase. There are a few things to keep in mind when your application scales to keep your TS check times down.
+​
+### Narrow to relevant routes as much as you possibly can
+​
+Consider the following usage of `Link`
+​
+```tsx
+<Link to=".." search={{ page: 0 }} />
+<Link to="." search={{ page: 0 }} />
+<Link search={{ page: 0 }} />
+```
+​
+**These examples are bad for TS performance**. That's because `search` resolves to a union of all `search` params for all routes and TS has to check whatever you pass to the `search` prop against this potentially big union. As your application grows, this check time will increase linearly to number of routes and search params. We have done our best to optimise for this case (TypeScript will typically do this work once and cache it) but the initial check against this large union is expensive. This also applies to `params` and other API's such as `useSearch`, `useParams`, `useNavigate` etc
+​
+Instead you should try to narrow to relevant routes with `from` or `to`
+​
+```tsx
+<Link from={Route.fullPath} to=".." search={{page: 0}} />
+<Link from="/posts" to=".." search={{page: 0}} />