@tanstack/react-router 1.92.13 → 1.93.0
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/router.cjs +22 -10
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +6 -2
- package/dist/esm/router.d.ts +6 -2
- package/dist/esm/router.js +22 -10
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +29 -10
package/package.json
CHANGED
package/src/router.ts
CHANGED
|
@@ -1937,7 +1937,7 @@ export class Router<
|
|
|
1937
1937
|
|
|
1938
1938
|
latestLoadPromise: undefined | Promise<void>
|
|
1939
1939
|
|
|
1940
|
-
load = async (): Promise<void> => {
|
|
1940
|
+
load = async (opts?: { sync?: boolean }): Promise<void> => {
|
|
1941
1941
|
this.latestLocation = this.parseLocation(this.latestLocation)
|
|
1942
1942
|
|
|
1943
1943
|
let redirect: ResolvedRedirect | undefined
|
|
@@ -2000,6 +2000,7 @@ export class Router<
|
|
|
2000
2000
|
})
|
|
2001
2001
|
|
|
2002
2002
|
await this.loadMatches({
|
|
2003
|
+
sync: opts?.sync,
|
|
2003
2004
|
matches: pendingMatches,
|
|
2004
2005
|
location: next,
|
|
2005
2006
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -2188,6 +2189,7 @@ export class Router<
|
|
|
2188
2189
|
preload: allPreload,
|
|
2189
2190
|
onReady,
|
|
2190
2191
|
updateMatch = this.updateMatch,
|
|
2192
|
+
sync,
|
|
2191
2193
|
}: {
|
|
2192
2194
|
location: ParsedLocation
|
|
2193
2195
|
matches: Array<AnyRouteMatch>
|
|
@@ -2198,6 +2200,7 @@ export class Router<
|
|
|
2198
2200
|
updater: (match: AnyRouteMatch) => AnyRouteMatch,
|
|
2199
2201
|
) => void
|
|
2200
2202
|
getMatch?: (matchId: string) => AnyRouteMatch | undefined
|
|
2203
|
+
sync?: boolean
|
|
2201
2204
|
}): Promise<Array<MakeRouteMatch>> => {
|
|
2202
2205
|
let firstBadMatchIndex: number | undefined
|
|
2203
2206
|
let rendered = false
|
|
@@ -2484,7 +2487,8 @@ export class Router<
|
|
|
2484
2487
|
const { loaderPromise: prevLoaderPromise } =
|
|
2485
2488
|
this.getMatch(matchId)!
|
|
2486
2489
|
|
|
2487
|
-
let
|
|
2490
|
+
let loaderShouldRunAsync = false
|
|
2491
|
+
let loaderIsRunningAsync = false
|
|
2488
2492
|
|
|
2489
2493
|
if (prevLoaderPromise) {
|
|
2490
2494
|
await prevLoaderPromise
|
|
@@ -2665,36 +2669,50 @@ export class Router<
|
|
|
2665
2669
|
|
|
2666
2670
|
// If the route is successful and still fresh, just resolve
|
|
2667
2671
|
const { status, invalid } = this.getMatch(matchId)!
|
|
2668
|
-
|
|
2672
|
+
loaderShouldRunAsync =
|
|
2669
2673
|
status === 'success' &&
|
|
2670
2674
|
(invalid || (shouldReload ?? age > staleAge))
|
|
2671
2675
|
if (preload && route.options.preload === false) {
|
|
2672
2676
|
// Do nothing
|
|
2673
|
-
} else if (
|
|
2677
|
+
} else if (loaderShouldRunAsync && !sync) {
|
|
2678
|
+
loaderIsRunningAsync = true
|
|
2674
2679
|
;(async () => {
|
|
2675
2680
|
try {
|
|
2676
2681
|
await runLoader()
|
|
2682
|
+
const { loaderPromise, loadPromise } =
|
|
2683
|
+
this.getMatch(matchId)!
|
|
2684
|
+
loaderPromise?.resolve()
|
|
2685
|
+
loadPromise?.resolve()
|
|
2686
|
+
updateMatch(matchId, (prev) => ({
|
|
2687
|
+
...prev,
|
|
2688
|
+
loaderPromise: undefined,
|
|
2689
|
+
}))
|
|
2677
2690
|
} catch (err) {
|
|
2678
2691
|
if (isResolvedRedirect(err)) {
|
|
2679
2692
|
await this.navigate(err)
|
|
2680
2693
|
}
|
|
2681
2694
|
}
|
|
2682
2695
|
})()
|
|
2683
|
-
} else if (
|
|
2696
|
+
} else if (
|
|
2697
|
+
status !== 'success' ||
|
|
2698
|
+
(loaderShouldRunAsync && sync)
|
|
2699
|
+
) {
|
|
2684
2700
|
await runLoader()
|
|
2685
2701
|
}
|
|
2686
|
-
|
|
2702
|
+
}
|
|
2703
|
+
if (!loaderIsRunningAsync) {
|
|
2687
2704
|
const { loaderPromise, loadPromise } =
|
|
2688
2705
|
this.getMatch(matchId)!
|
|
2689
|
-
|
|
2690
2706
|
loaderPromise?.resolve()
|
|
2691
2707
|
loadPromise?.resolve()
|
|
2692
2708
|
}
|
|
2693
2709
|
|
|
2694
2710
|
updateMatch(matchId, (prev) => ({
|
|
2695
2711
|
...prev,
|
|
2696
|
-
isFetching:
|
|
2697
|
-
loaderPromise:
|
|
2712
|
+
isFetching: loaderIsRunningAsync ? prev.isFetching : false,
|
|
2713
|
+
loaderPromise: loaderIsRunningAsync
|
|
2714
|
+
? prev.loaderPromise
|
|
2715
|
+
: undefined,
|
|
2698
2716
|
invalid: false,
|
|
2699
2717
|
}))
|
|
2700
2718
|
return this.getMatch(matchId)!
|
|
@@ -2725,6 +2743,7 @@ export class Router<
|
|
|
2725
2743
|
|
|
2726
2744
|
invalidate = <TRouter extends AnyRouter = typeof this>(opts?: {
|
|
2727
2745
|
filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean
|
|
2746
|
+
sync?: boolean
|
|
2728
2747
|
}) => {
|
|
2729
2748
|
const invalidate = (d: MakeRouteMatch<TRouteTree>) => {
|
|
2730
2749
|
if (opts?.filter?.(d as MakeRouteMatchUnion<TRouter>) ?? true) {
|
|
@@ -2746,7 +2765,7 @@ export class Router<
|
|
|
2746
2765
|
pendingMatches: s.pendingMatches?.map(invalidate),
|
|
2747
2766
|
}))
|
|
2748
2767
|
|
|
2749
|
-
return this.load()
|
|
2768
|
+
return this.load({ sync: opts?.sync })
|
|
2750
2769
|
}
|
|
2751
2770
|
|
|
2752
2771
|
resolveRedirect = (err: AnyRedirect): ResolvedRedirect => {
|