Skip to content
Source
Sign inSign up
TanStack/router

refactor(router-core): cache matched route branch alongside the rest of the route match #5882

MergedSheraff(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/5882/headmerged by Sheraff(GitHub profile, opens in a new tab)

Showing 2 changed files with 33 additions and 23 deletions.

x
0 of 2 viewed, 2 left
27 additions and 9 deletionspackages/router-core/src/new-process-route-tree.tsModified
View file
@@ -537,7 +537,7 @@
/** @deprecated keep until v2 so that `router.matchRoute` can keep not caring about the actual route tree */
singleCache: LRUCache<string, AnySegmentNode<TSingle>>
/** a cache of route matches from the `segmentTree` */
- matchCache: LRUCache<string, ReturnType<typeof findMatch<TTree>>>
+ matchCache: LRUCache<string, RouteMatch<TTree> | null>
/** a cache of route matches from the `masksTree` */
flatCache: LRUCache<string, ReturnType<typeof findMatch<TFlat>>> | null
@@ -603,6 +603,12 @@
return findMatch(path, tree, fuzzy)
​
+type RouteMatch<T extends Extract<RouteLike, { fullPath: string }>> = {
+ route: T
+ params: Record<string, string>
+ branch: ReadonlyArray<T>
+}
+​
export function findRouteMatch<
T extends Extract<RouteLike, { fullPath: string }>,
@@ -612,12 +618,17 @@