@tanstack/router-core 1.168.10 → 1.168.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/load-matches.cjs +4 -4
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/router.cjs +34 -34
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/ssr/createRequestHandler.cjs +1 -1
- package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-client.cjs +2 -2
- package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-server.cjs +1 -1
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
- package/dist/cjs/stores.cjs +37 -37
- package/dist/cjs/stores.cjs.map +1 -1
- package/dist/cjs/stores.d.cts +14 -14
- package/dist/esm/load-matches.js +4 -4
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/router.js +34 -34
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/ssr/createRequestHandler.js +1 -1
- package/dist/esm/ssr/createRequestHandler.js.map +1 -1
- package/dist/esm/ssr/ssr-client.js +2 -2
- package/dist/esm/ssr/ssr-client.js.map +1 -1
- package/dist/esm/ssr/ssr-server.js +1 -1
- package/dist/esm/ssr/ssr-server.js.map +1 -1
- package/dist/esm/stores.d.ts +14 -14
- package/dist/esm/stores.js +37 -37
- package/dist/esm/stores.js.map +1 -1
- package/package.json +1 -1
- package/src/load-matches.ts +6 -9
- package/src/router.ts +39 -52
- package/src/ssr/createRequestHandler.ts +1 -1
- package/src/ssr/ssr-client.ts +2 -2
- package/src/ssr/ssr-server.ts +1 -1
- package/src/stores.ts +57 -57
package/src/router.ts
CHANGED
|
@@ -1420,7 +1420,7 @@ export class RouterCore<
|
|
|
1420
1420
|
// Snapshot of active match state keyed by routeId, used to stabilise
|
|
1421
1421
|
// params/search across navigations.
|
|
1422
1422
|
const previousActiveMatchesByRouteId = new Map<string, AnyRouteMatch>()
|
|
1423
|
-
for (const store of this.stores.
|
|
1423
|
+
for (const store of this.stores.matchStores.values()) {
|
|
1424
1424
|
if (store.routeId) {
|
|
1425
1425
|
previousActiveMatchesByRouteId.set(store.routeId, store.get())
|
|
1426
1426
|
}
|
|
@@ -1717,8 +1717,7 @@ export class RouterCore<
|
|
|
1717
1717
|
// Determine params: reuse from state if possible, otherwise parse
|
|
1718
1718
|
const lastStateMatchId = last(this.stores.matchesId.get())
|
|
1719
1719
|
const lastStateMatch =
|
|
1720
|
-
lastStateMatchId &&
|
|
1721
|
-
this.stores.activeMatchStoresById.get(lastStateMatchId)?.get()
|
|
1720
|
+
lastStateMatchId && this.stores.matchStores.get(lastStateMatchId)?.get()
|
|
1722
1721
|
const canReuseParams =
|
|
1723
1722
|
lastStateMatch &&
|
|
1724
1723
|
lastStateMatch.routeId === lastRoute.id &&
|
|
@@ -1767,16 +1766,16 @@ export class RouterCore<
|
|
|
1767
1766
|
}
|
|
1768
1767
|
|
|
1769
1768
|
cancelMatches = () => {
|
|
1770
|
-
this.stores.
|
|
1769
|
+
this.stores.pendingIds.get().forEach((matchId) => {
|
|
1771
1770
|
this.cancelMatch(matchId)
|
|
1772
1771
|
})
|
|
1773
1772
|
|
|
1774
1773
|
this.stores.matchesId.get().forEach((matchId) => {
|
|
1775
|
-
if (this.stores.
|
|
1774
|
+
if (this.stores.pendingMatchStores.has(matchId)) {
|
|
1776
1775
|
return
|
|
1777
1776
|
}
|
|
1778
1777
|
|
|
1779
|
-
const match = this.stores.
|
|
1778
|
+
const match = this.stores.matchStores.get(matchId)?.get()
|
|
1780
1779
|
if (!match) {
|
|
1781
1780
|
return
|
|
1782
1781
|
}
|
|
@@ -2356,7 +2355,7 @@ export class RouterCore<
|
|
|
2356
2355
|
// Match the routes
|
|
2357
2356
|
const pendingMatches = this.matchRoutes(this.latestLocation)
|
|
2358
2357
|
|
|
2359
|
-
const nextCachedMatches = this.stores.
|
|
2358
|
+
const nextCachedMatches = this.stores.cachedMatches
|
|
2360
2359
|
.get()
|
|
2361
2360
|
.filter((d) => !pendingMatches.some((e) => e.id === d.id))
|
|
2362
2361
|
|
|
@@ -2366,9 +2365,9 @@ export class RouterCore<
|
|
|
2366
2365
|
this.stores.statusCode.set(200)
|
|
2367
2366
|
this.stores.isLoading.set(true)
|
|
2368
2367
|
this.stores.location.set(this.latestLocation)
|
|
2369
|
-
this.stores.
|
|
2368
|
+
this.stores.setPending(pendingMatches)
|
|
2370
2369
|
// If a cached match moved to pending matches, remove it from cached matches
|
|
2371
|
-
this.stores.
|
|
2370
|
+
this.stores.setCached(nextCachedMatches)
|
|
2372
2371
|
})
|
|
2373
2372
|
}
|
|
2374
2373
|
|
|
@@ -2404,7 +2403,7 @@ export class RouterCore<
|
|
|
2404
2403
|
router: this,
|
|
2405
2404
|
sync: opts?.sync,
|
|
2406
2405
|
forceStaleReload: previousLocation.href === next.href,
|
|
2407
|
-
matches: this.stores.
|
|
2406
|
+
matches: this.stores.pendingMatches.get(),
|
|
2408
2407
|
location: next,
|
|
2409
2408
|
updateMatch: this.updateMatch,
|
|
2410
2409
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -2428,27 +2427,25 @@ export class RouterCore<
|
|
|
2428
2427
|
let hookStayingMatches: Array<AnyRouteMatch> | null = null
|
|
2429
2428
|
|
|
2430
2429
|
this.batch(() => {
|
|
2431
|
-
const pendingMatches =
|
|
2432
|
-
this.stores.pendingMatchesSnapshot.get()
|
|
2430
|
+
const pendingMatches = this.stores.pendingMatches.get()
|
|
2433
2431
|
const mountPending = pendingMatches.length
|
|
2434
|
-
const currentMatches =
|
|
2435
|
-
this.stores.activeMatchesSnapshot.get()
|
|
2432
|
+
const currentMatches = this.stores.matches.get()
|
|
2436
2433
|
|
|
2437
2434
|
exitingMatches = mountPending
|
|
2438
2435
|
? currentMatches.filter(
|
|
2439
2436
|
(match) =>
|
|
2440
|
-
!this.stores.
|
|
2437
|
+
!this.stores.pendingMatchStores.has(match.id),
|
|
2441
2438
|
)
|
|
2442
2439
|
: null
|
|
2443
2440
|
|
|
2444
2441
|
// Lifecycle-hook identity: routeId only (route presence in tree)
|
|
2445
2442
|
// Build routeId sets from pools to avoid derived stores.
|
|
2446
2443
|
const pendingRouteIds = new Set<string>()
|
|
2447
|
-
for (const s of this.stores.
|
|
2444
|
+
for (const s of this.stores.pendingMatchStores.values()) {
|
|
2448
2445
|
if (s.routeId) pendingRouteIds.add(s.routeId)
|
|
2449
2446
|
}
|
|
2450
2447
|
const activeRouteIds = new Set<string>()
|
|
2451
|
-
for (const s of this.stores.
|
|
2448
|
+
for (const s of this.stores.matchStores.values()) {
|
|
2452
2449
|
if (s.routeId) activeRouteIds.add(s.routeId)
|
|
2453
2450
|
}
|
|
2454
2451
|
|
|
@@ -2477,10 +2474,10 @@ export class RouterCore<
|
|
|
2477
2474
|
* or reloads re-run their loaders instead of reusing the failed/not-found data.
|
|
2478
2475
|
*/
|
|
2479
2476
|
if (mountPending) {
|
|
2480
|
-
this.stores.
|
|
2481
|
-
this.stores.
|
|
2482
|
-
this.stores.
|
|
2483
|
-
...this.stores.
|
|
2477
|
+
this.stores.setMatches(pendingMatches)
|
|
2478
|
+
this.stores.setPending([])
|
|
2479
|
+
this.stores.setCached([
|
|
2480
|
+
...this.stores.cachedMatches.get(),
|
|
2484
2481
|
...exitingMatches!.filter(
|
|
2485
2482
|
(d) =>
|
|
2486
2483
|
d.status !== 'error' &&
|
|
@@ -2527,9 +2524,7 @@ export class RouterCore<
|
|
|
2527
2524
|
? redirect.status
|
|
2528
2525
|
: notFound
|
|
2529
2526
|
? 404
|
|
2530
|
-
: this.stores.
|
|
2531
|
-
.get()
|
|
2532
|
-
.some((d) => d.status === 'error')
|
|
2527
|
+
: this.stores.matches.get().some((d) => d.status === 'error')
|
|
2533
2528
|
? 500
|
|
2534
2529
|
: 200
|
|
2535
2530
|
|
|
@@ -2563,9 +2558,7 @@ export class RouterCore<
|
|
|
2563
2558
|
let newStatusCode: number | undefined = undefined
|
|
2564
2559
|
if (this.hasNotFoundMatch()) {
|
|
2565
2560
|
newStatusCode = 404
|
|
2566
|
-
} else if (
|
|
2567
|
-
this.stores.activeMatchesSnapshot.get().some((d) => d.status === 'error')
|
|
2568
|
-
) {
|
|
2561
|
+
} else if (this.stores.matches.get().some((d) => d.status === 'error')) {
|
|
2569
2562
|
newStatusCode = 500
|
|
2570
2563
|
}
|
|
2571
2564
|
if (newStatusCode !== undefined) {
|
|
@@ -2628,25 +2621,25 @@ export class RouterCore<
|
|
|
2628
2621
|
|
|
2629
2622
|
updateMatch: UpdateMatchFn = (id, updater) => {
|
|
2630
2623
|
this.startTransition(() => {
|
|
2631
|
-
const pendingMatch = this.stores.
|
|
2624
|
+
const pendingMatch = this.stores.pendingMatchStores.get(id)
|
|
2632
2625
|
if (pendingMatch) {
|
|
2633
2626
|
pendingMatch.set(updater)
|
|
2634
2627
|
return
|
|
2635
2628
|
}
|
|
2636
2629
|
|
|
2637
|
-
const activeMatch = this.stores.
|
|
2630
|
+
const activeMatch = this.stores.matchStores.get(id)
|
|
2638
2631
|
if (activeMatch) {
|
|
2639
2632
|
activeMatch.set(updater)
|
|
2640
2633
|
return
|
|
2641
2634
|
}
|
|
2642
2635
|
|
|
2643
|
-
const cachedMatch = this.stores.
|
|
2636
|
+
const cachedMatch = this.stores.cachedMatchStores.get(id)
|
|
2644
2637
|
if (cachedMatch) {
|
|
2645
2638
|
const next = updater(cachedMatch.get())
|
|
2646
2639
|
if (next.status === 'redirected') {
|
|
2647
|
-
const deleted = this.stores.
|
|
2640
|
+
const deleted = this.stores.cachedMatchStores.delete(id)
|
|
2648
2641
|
if (deleted) {
|
|
2649
|
-
this.stores.
|
|
2642
|
+
this.stores.cachedIds.set((prev) =>
|
|
2650
2643
|
prev.filter((matchId) => matchId !== id),
|
|
2651
2644
|
)
|
|
2652
2645
|
}
|
|
@@ -2659,9 +2652,9 @@ export class RouterCore<
|
|
|
2659
2652
|
|
|
2660
2653
|
getMatch: GetMatchFn = (matchId: string): AnyRouteMatch | undefined => {
|
|
2661
2654
|
return (
|
|
2662
|
-
this.stores.
|
|
2663
|
-
this.stores.
|
|
2664
|
-
this.stores.
|
|
2655
|
+
this.stores.cachedMatchStores.get(matchId)?.get() ??
|
|
2656
|
+
this.stores.pendingMatchStores.get(matchId)?.get() ??
|
|
2657
|
+
this.stores.matchStores.get(matchId)?.get()
|
|
2665
2658
|
)
|
|
2666
2659
|
}
|
|
2667
2660
|
|
|
@@ -2698,15 +2691,9 @@ export class RouterCore<
|
|
|
2698
2691
|
}
|
|
2699
2692
|
|
|
2700
2693
|
this.batch(() => {
|
|
2701
|
-
this.stores.
|
|
2702
|
-
|
|
2703
|
-
)
|
|
2704
|
-
this.stores.setCachedMatches(
|
|
2705
|
-
this.stores.cachedMatchesSnapshot.get().map(invalidate),
|
|
2706
|
-
)
|
|
2707
|
-
this.stores.setPendingMatches(
|
|
2708
|
-
this.stores.pendingMatchesSnapshot.get().map(invalidate),
|
|
2709
|
-
)
|
|
2694
|
+
this.stores.setMatches(this.stores.matches.get().map(invalidate))
|
|
2695
|
+
this.stores.setCached(this.stores.cachedMatches.get().map(invalidate))
|
|
2696
|
+
this.stores.setPending(this.stores.pendingMatches.get().map(invalidate))
|
|
2710
2697
|
})
|
|
2711
2698
|
|
|
2712
2699
|
this.shouldViewTransition = false
|
|
@@ -2764,13 +2751,13 @@ export class RouterCore<
|
|
|
2764
2751
|
clearCache: ClearCacheFn<this> = (opts) => {
|
|
2765
2752
|
const filter = opts?.filter
|
|
2766
2753
|
if (filter !== undefined) {
|
|
2767
|
-
this.stores.
|
|
2768
|
-
this.stores.
|
|
2754
|
+
this.stores.setCached(
|
|
2755
|
+
this.stores.cachedMatches
|
|
2769
2756
|
.get()
|
|
2770
2757
|
.filter((m) => !filter(m as MakeRouteMatchUnion<this>)),
|
|
2771
2758
|
)
|
|
2772
2759
|
} else {
|
|
2773
|
-
this.stores.
|
|
2760
|
+
this.stores.setCached([])
|
|
2774
2761
|
}
|
|
2775
2762
|
}
|
|
2776
2763
|
|
|
@@ -2819,12 +2806,12 @@ export class RouterCore<
|
|
|
2819
2806
|
|
|
2820
2807
|
const activeMatchIds = new Set([
|
|
2821
2808
|
...this.stores.matchesId.get(),
|
|
2822
|
-
...this.stores.
|
|
2809
|
+
...this.stores.pendingIds.get(),
|
|
2823
2810
|
])
|
|
2824
2811
|
|
|
2825
2812
|
const loadedMatchIds = new Set([
|
|
2826
2813
|
...activeMatchIds,
|
|
2827
|
-
...this.stores.
|
|
2814
|
+
...this.stores.cachedIds.get(),
|
|
2828
2815
|
])
|
|
2829
2816
|
|
|
2830
2817
|
// If the matches are already loaded, we need to add them to the cached matches.
|
|
@@ -2832,8 +2819,8 @@ export class RouterCore<
|
|
|
2832
2819
|
(match) => !loadedMatchIds.has(match.id),
|
|
2833
2820
|
)
|
|
2834
2821
|
if (matchesToCache.length) {
|
|
2835
|
-
const cachedMatches = this.stores.
|
|
2836
|
-
this.stores.
|
|
2822
|
+
const cachedMatches = this.stores.cachedMatches.get()
|
|
2823
|
+
this.stores.setCached([...cachedMatches, ...matchesToCache])
|
|
2837
2824
|
}
|
|
2838
2825
|
|
|
2839
2826
|
try {
|
|
@@ -2933,7 +2920,7 @@ export class RouterCore<
|
|
|
2933
2920
|
serverSsr?: ServerSsr
|
|
2934
2921
|
|
|
2935
2922
|
hasNotFoundMatch = () => {
|
|
2936
|
-
return this.stores.
|
|
2923
|
+
return this.stores.matches
|
|
2937
2924
|
.get()
|
|
2938
2925
|
.some((d) => d.status === 'notFound' || d.globalNotFound)
|
|
2939
2926
|
}
|
|
@@ -78,7 +78,7 @@ export function createRequestHandler<TRouter extends AnyRouter>({
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
function getRequestHeaders(opts: { router: AnyRouter }): Headers {
|
|
81
|
-
const matchHeaders = opts.router.stores.
|
|
81
|
+
const matchHeaders = opts.router.stores.matches
|
|
82
82
|
.get()
|
|
83
83
|
.map<AnyHeaders>((match) => match.headers)
|
|
84
84
|
|
package/src/ssr/ssr-client.ts
CHANGED
|
@@ -162,7 +162,7 @@ export async function hydrate(router: AnyRouter): Promise<any> {
|
|
|
162
162
|
}
|
|
163
163
|
})
|
|
164
164
|
|
|
165
|
-
router.stores.
|
|
165
|
+
router.stores.setMatches(matches)
|
|
166
166
|
|
|
167
167
|
// Allow the user to handle custom hydration data
|
|
168
168
|
await router.options.hydrate?.(dehydratedData)
|
|
@@ -170,7 +170,7 @@ export async function hydrate(router: AnyRouter): Promise<any> {
|
|
|
170
170
|
// now that all necessary data is hydrated:
|
|
171
171
|
// 1) fully reconstruct the route context
|
|
172
172
|
// 2) execute `head()` and `scripts()` for each match
|
|
173
|
-
const activeMatches = router.stores.
|
|
173
|
+
const activeMatches = router.stores.matches.get()
|
|
174
174
|
const location = router.stores.location.get()
|
|
175
175
|
await Promise.all(
|
|
176
176
|
activeMatches.map(async (match) => {
|
package/src/ssr/ssr-server.ts
CHANGED
|
@@ -228,7 +228,7 @@ export function attachRouterServerSsrUtils({
|
|
|
228
228
|
|
|
229
229
|
invariant()
|
|
230
230
|
}
|
|
231
|
-
let matchesToDehydrate = router.stores.
|
|
231
|
+
let matchesToDehydrate = router.stores.matches.get()
|
|
232
232
|
if (router.isShell()) {
|
|
233
233
|
// In SPA mode we only want to dehydrate the root match
|
|
234
234
|
matchesToDehydrate = matchesToDehydrate.slice(0, 1)
|
package/src/stores.ts
CHANGED
|
@@ -81,24 +81,24 @@ export interface RouterStores<in out TRouteTree extends AnyRoute> {
|
|
|
81
81
|
statusCode: RouterWritableStore<number>
|
|
82
82
|
redirect: RouterWritableStore<AnyRedirect | undefined>
|
|
83
83
|
matchesId: RouterWritableStore<Array<string>>
|
|
84
|
-
|
|
84
|
+
pendingIds: RouterWritableStore<Array<string>>
|
|
85
85
|
/** @internal */
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
cachedIds: RouterWritableStore<Array<string>>
|
|
87
|
+
matches: ReadableStore<Array<AnyRouteMatch>>
|
|
88
|
+
pendingMatches: ReadableStore<Array<AnyRouteMatch>>
|
|
89
|
+
cachedMatches: ReadableStore<Array<AnyRouteMatch>>
|
|
90
|
+
firstId: ReadableStore<string | undefined>
|
|
91
|
+
hasPending: ReadableStore<boolean>
|
|
92
|
+
matchRouteDeps: ReadableStore<{
|
|
93
93
|
locationHref: string
|
|
94
94
|
resolvedLocationHref: string | undefined
|
|
95
95
|
status: RouterState<TRouteTree>['status']
|
|
96
96
|
}>
|
|
97
97
|
__store: RouterReadableStore<RouterState<TRouteTree>>
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
matchStores: Map<string, MatchStore>
|
|
100
|
+
pendingMatchStores: Map<string, MatchStore>
|
|
101
|
+
cachedMatchStores: Map<string, MatchStore>
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Get a computed store that resolves a routeId to its current match state.
|
|
@@ -106,13 +106,13 @@ export interface RouterStores<in out TRouteTree extends AnyRoute> {
|
|
|
106
106
|
* The computed depends on matchesId + the individual match store, so
|
|
107
107
|
* subscribers are only notified when the resolved match state changes.
|
|
108
108
|
*/
|
|
109
|
-
|
|
109
|
+
getRouteMatchStore: (
|
|
110
110
|
routeId: string,
|
|
111
111
|
) => RouterReadableStore<AnyRouteMatch | undefined>
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
setMatches: (nextMatches: Array<AnyRouteMatch>) => void
|
|
114
|
+
setPending: (nextMatches: Array<AnyRouteMatch>) => void
|
|
115
|
+
setCached: (nextMatches: Array<AnyRouteMatch>) => void
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
export function createRouterStores<TRouteTree extends AnyRoute>(
|
|
@@ -122,9 +122,9 @@ export function createRouterStores<TRouteTree extends AnyRoute>(
|
|
|
122
122
|
const { createMutableStore, createReadonlyStore, batch, init } = config
|
|
123
123
|
|
|
124
124
|
// non reactive utilities
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
const
|
|
125
|
+
const matchStores = new Map<string, MatchStore>()
|
|
126
|
+
const pendingMatchStores = new Map<string, MatchStore>()
|
|
127
|
+
const cachedMatchStores = new Map<string, MatchStore>()
|
|
128
128
|
|
|
129
129
|
// atoms
|
|
130
130
|
const status = createMutableStore(initialState.status)
|
|
@@ -136,27 +136,27 @@ export function createRouterStores<TRouteTree extends AnyRoute>(
|
|
|
136
136
|
const statusCode = createMutableStore(initialState.statusCode)
|
|
137
137
|
const redirect = createMutableStore(initialState.redirect)
|
|
138
138
|
const matchesId = createMutableStore<Array<string>>([])
|
|
139
|
-
const
|
|
140
|
-
const
|
|
139
|
+
const pendingIds = createMutableStore<Array<string>>([])
|
|
140
|
+
const cachedIds = createMutableStore<Array<string>>([])
|
|
141
141
|
|
|
142
142
|
// 1st order derived stores
|
|
143
|
-
const
|
|
144
|
-
readPoolMatches(
|
|
143
|
+
const matches = createReadonlyStore(() =>
|
|
144
|
+
readPoolMatches(matchStores, matchesId.get()),
|
|
145
145
|
)
|
|
146
|
-
const
|
|
147
|
-
readPoolMatches(
|
|
146
|
+
const pendingMatches = createReadonlyStore(() =>
|
|
147
|
+
readPoolMatches(pendingMatchStores, pendingIds.get()),
|
|
148
148
|
)
|
|
149
|
-
const
|
|
150
|
-
readPoolMatches(
|
|
149
|
+
const cachedMatches = createReadonlyStore(() =>
|
|
150
|
+
readPoolMatches(cachedMatchStores, cachedIds.get()),
|
|
151
151
|
)
|
|
152
|
-
const
|
|
153
|
-
const
|
|
152
|
+
const firstId = createReadonlyStore(() => matchesId.get()[0])
|
|
153
|
+
const hasPending = createReadonlyStore(() =>
|
|
154
154
|
matchesId.get().some((matchId) => {
|
|
155
|
-
const store =
|
|
155
|
+
const store = matchStores.get(matchId)
|
|
156
156
|
return store?.get().status === 'pending'
|
|
157
157
|
}),
|
|
158
158
|
)
|
|
159
|
-
const
|
|
159
|
+
const matchRouteDeps = createReadonlyStore(() => ({
|
|
160
160
|
locationHref: location.get().href,
|
|
161
161
|
resolvedLocationHref: resolvedLocation.get()?.href,
|
|
162
162
|
status: status.get(),
|
|
@@ -168,7 +168,7 @@ export function createRouterStores<TRouteTree extends AnyRoute>(
|
|
|
168
168
|
loadedAt: loadedAt.get(),
|
|
169
169
|
isLoading: isLoading.get(),
|
|
170
170
|
isTransitioning: isTransitioning.get(),
|
|
171
|
-
matches:
|
|
171
|
+
matches: matches.get(),
|
|
172
172
|
location: location.get(),
|
|
173
173
|
resolvedLocation: resolvedLocation.get(),
|
|
174
174
|
statusCode: statusCode.get(),
|
|
@@ -188,7 +188,7 @@ export function createRouterStores<TRouteTree extends AnyRoute>(
|
|
|
188
188
|
RouterReadableStore<AnyRouteMatch | undefined>
|
|
189
189
|
>(64)
|
|
190
190
|
|
|
191
|
-
function
|
|
191
|
+
function getRouteMatchStore(
|
|
192
192
|
routeId: string,
|
|
193
193
|
): RouterReadableStore<AnyRouteMatch | undefined> {
|
|
194
194
|
let cached = matchStoreByRouteIdCache.get(routeId)
|
|
@@ -198,7 +198,7 @@ export function createRouterStores<TRouteTree extends AnyRoute>(
|
|
|
198
198
|
// When matchesId changes (navigation), this computed re-evaluates.
|
|
199
199
|
const ids = matchesId.get()
|
|
200
200
|
for (const id of ids) {
|
|
201
|
-
const matchStore =
|
|
201
|
+
const matchStore = matchStores.get(id)
|
|
202
202
|
if (matchStore && matchStore.routeId === routeId) {
|
|
203
203
|
// Reading matchStore.get() tracks it as a dependency.
|
|
204
204
|
// When the match store's state changes, this re-evaluates.
|
|
@@ -223,64 +223,64 @@ export function createRouterStores<TRouteTree extends AnyRoute>(
|
|
|
223
223
|
statusCode,
|
|
224
224
|
redirect,
|
|
225
225
|
matchesId,
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
pendingIds,
|
|
227
|
+
cachedIds,
|
|
228
228
|
|
|
229
229
|
// derived
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
matches,
|
|
231
|
+
pendingMatches,
|
|
232
|
+
cachedMatches,
|
|
233
|
+
firstId,
|
|
234
|
+
hasPending,
|
|
235
|
+
matchRouteDeps,
|
|
236
236
|
|
|
237
237
|
// non-reactive state
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
matchStores,
|
|
239
|
+
pendingMatchStores,
|
|
240
|
+
cachedMatchStores,
|
|
241
241
|
|
|
242
242
|
// compatibility "big" state
|
|
243
243
|
__store,
|
|
244
244
|
|
|
245
245
|
// per-key computed stores
|
|
246
|
-
|
|
246
|
+
getRouteMatchStore,
|
|
247
247
|
|
|
248
248
|
// methods
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
setMatches,
|
|
250
|
+
setPending,
|
|
251
|
+
setCached,
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
// initialize the active matches
|
|
255
|
-
|
|
255
|
+
setMatches(initialState.matches as Array<AnyRouteMatch>)
|
|
256
256
|
init?.(store)
|
|
257
257
|
|
|
258
258
|
// setters to update non-reactive utilities in sync with the reactive stores
|
|
259
|
-
function
|
|
259
|
+
function setMatches(nextMatches: Array<AnyRouteMatch>) {
|
|
260
260
|
reconcileMatchPool(
|
|
261
261
|
nextMatches,
|
|
262
|
-
|
|
262
|
+
matchStores,
|
|
263
263
|
matchesId,
|
|
264
264
|
createMutableStore,
|
|
265
265
|
batch,
|
|
266
266
|
)
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
function
|
|
269
|
+
function setPending(nextMatches: Array<AnyRouteMatch>) {
|
|
270
270
|
reconcileMatchPool(
|
|
271
271
|
nextMatches,
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
pendingMatchStores,
|
|
273
|
+
pendingIds,
|
|
274
274
|
createMutableStore,
|
|
275
275
|
batch,
|
|
276
276
|
)
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
-
function
|
|
279
|
+
function setCached(nextMatches: Array<AnyRouteMatch>) {
|
|
280
280
|
reconcileMatchPool(
|
|
281
281
|
nextMatches,
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
cachedMatchStores,
|
|
283
|
+
cachedIds,
|
|
284
284
|
createMutableStore,
|
|
285
285
|
batch,
|
|
286
286
|
)
|