@tanstack/router-core 1.131.7 → 1.131.12
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 +71 -51
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/router.js +71 -51
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +93 -65
package/package.json
CHANGED
package/src/router.ts
CHANGED
|
@@ -1393,8 +1393,8 @@ export class RouterCore<
|
|
|
1393
1393
|
if (!match) return
|
|
1394
1394
|
|
|
1395
1395
|
match.abortController.abort()
|
|
1396
|
-
match._nonReactive.pendingTimeout = undefined
|
|
1397
1396
|
clearTimeout(match._nonReactive.pendingTimeout)
|
|
1397
|
+
match._nonReactive.pendingTimeout = undefined
|
|
1398
1398
|
}
|
|
1399
1399
|
|
|
1400
1400
|
cancelMatches = () => {
|
|
@@ -2121,7 +2121,10 @@ export class RouterCore<
|
|
|
2121
2121
|
triggerOnReady()
|
|
2122
2122
|
}
|
|
2123
2123
|
|
|
2124
|
-
const handleRedirectAndNotFound = (
|
|
2124
|
+
const handleRedirectAndNotFound = (
|
|
2125
|
+
match: AnyRouteMatch | undefined,
|
|
2126
|
+
err: any,
|
|
2127
|
+
) => {
|
|
2125
2128
|
if (isRedirect(err) || isNotFound(err)) {
|
|
2126
2129
|
if (isRedirect(err)) {
|
|
2127
2130
|
if (err.redirectHandled) {
|
|
@@ -2131,27 +2134,30 @@ export class RouterCore<
|
|
|
2131
2134
|
}
|
|
2132
2135
|
}
|
|
2133
2136
|
|
|
2134
|
-
match
|
|
2135
|
-
match
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
:
|
|
2144
|
-
? '
|
|
2145
|
-
:
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2137
|
+
// in case of a redirecting match during preload, the match does not exist
|
|
2138
|
+
if (match) {
|
|
2139
|
+
match._nonReactive.beforeLoadPromise?.resolve()
|
|
2140
|
+
match._nonReactive.loaderPromise?.resolve()
|
|
2141
|
+
match._nonReactive.beforeLoadPromise = undefined
|
|
2142
|
+
match._nonReactive.loaderPromise = undefined
|
|
2143
|
+
|
|
2144
|
+
updateMatch(match.id, (prev) => ({
|
|
2145
|
+
...prev,
|
|
2146
|
+
status: isRedirect(err)
|
|
2147
|
+
? 'redirected'
|
|
2148
|
+
: isNotFound(err)
|
|
2149
|
+
? 'notFound'
|
|
2150
|
+
: 'error',
|
|
2151
|
+
isFetching: false,
|
|
2152
|
+
error: err,
|
|
2153
|
+
}))
|
|
2149
2154
|
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2155
|
+
if (!(err as any).routeId) {
|
|
2156
|
+
;(err as any).routeId = match.routeId
|
|
2157
|
+
}
|
|
2153
2158
|
|
|
2154
|
-
|
|
2159
|
+
match._nonReactive.loadPromise?.resolve()
|
|
2160
|
+
}
|
|
2155
2161
|
|
|
2156
2162
|
if (isRedirect(err)) {
|
|
2157
2163
|
rendered = true
|
|
@@ -2204,13 +2210,13 @@ export class RouterCore<
|
|
|
2204
2210
|
|
|
2205
2211
|
err.routerCode = routerCode
|
|
2206
2212
|
firstBadMatchIndex = firstBadMatchIndex ?? index
|
|
2207
|
-
handleRedirectAndNotFound(this.getMatch(matchId)
|
|
2213
|
+
handleRedirectAndNotFound(this.getMatch(matchId), err)
|
|
2208
2214
|
|
|
2209
2215
|
try {
|
|
2210
2216
|
route.options.onError?.(err)
|
|
2211
2217
|
} catch (errorHandlerErr) {
|
|
2212
2218
|
err = errorHandlerErr
|
|
2213
|
-
handleRedirectAndNotFound(this.getMatch(matchId)
|
|
2219
|
+
handleRedirectAndNotFound(this.getMatch(matchId), err)
|
|
2214
2220
|
}
|
|
2215
2221
|
|
|
2216
2222
|
updateMatch(matchId, (prev) => {
|
|
@@ -2465,35 +2471,45 @@ export class RouterCore<
|
|
|
2465
2471
|
let loaderIsRunningAsync = false
|
|
2466
2472
|
const route = this.looseRoutesById[routeId]!
|
|
2467
2473
|
|
|
2468
|
-
const executeHead =
|
|
2474
|
+
const executeHead = () => {
|
|
2469
2475
|
const match = this.getMatch(matchId)
|
|
2470
2476
|
// in case of a redirecting match during preload, the match does not exist
|
|
2471
2477
|
if (!match) {
|
|
2472
2478
|
return
|
|
2473
2479
|
}
|
|
2480
|
+
if (
|
|
2481
|
+
!route.options.head &&
|
|
2482
|
+
!route.options.scripts &&
|
|
2483
|
+
!route.options.headers
|
|
2484
|
+
) {
|
|
2485
|
+
return
|
|
2486
|
+
}
|
|
2474
2487
|
const assetContext = {
|
|
2475
2488
|
matches,
|
|
2476
2489
|
match,
|
|
2477
2490
|
params: match.params,
|
|
2478
2491
|
loaderData: match.loaderData,
|
|
2479
2492
|
}
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2493
|
+
|
|
2494
|
+
return Promise.all([
|
|
2495
|
+
route.options.head?.(assetContext),
|
|
2496
|
+
route.options.scripts?.(assetContext),
|
|
2497
|
+
route.options.headers?.(assetContext),
|
|
2498
|
+
]).then(([headFnContent, scripts, headers]) => {
|
|
2499
|
+
const meta = headFnContent?.meta
|
|
2500
|
+
const links = headFnContent?.links
|
|
2501
|
+
const headScripts = headFnContent?.scripts
|
|
2502
|
+
const styles = headFnContent?.styles
|
|
2503
|
+
|
|
2504
|
+
return {
|
|
2505
|
+
meta,
|
|
2506
|
+
links,
|
|
2507
|
+
headScripts,
|
|
2508
|
+
headers,
|
|
2509
|
+
scripts,
|
|
2510
|
+
styles,
|
|
2511
|
+
}
|
|
2512
|
+
})
|
|
2497
2513
|
}
|
|
2498
2514
|
|
|
2499
2515
|
const potentialPendingMinPromise = async () => {
|
|
@@ -2506,11 +2522,14 @@ export class RouterCore<
|
|
|
2506
2522
|
const prevMatch = this.getMatch(matchId)!
|
|
2507
2523
|
if (shouldSkipLoader(matchId)) {
|
|
2508
2524
|
if (this.isServer) {
|
|
2509
|
-
const
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2525
|
+
const headResult = executeHead()
|
|
2526
|
+
if (headResult) {
|
|
2527
|
+
const head = await headResult
|
|
2528
|
+
updateMatch(matchId, (prev) => ({
|
|
2529
|
+
...prev,
|
|
2530
|
+
...head,
|
|
2531
|
+
}))
|
|
2532
|
+
}
|
|
2514
2533
|
return this.getMatch(matchId)!
|
|
2515
2534
|
}
|
|
2516
2535
|
}
|
|
@@ -2622,7 +2641,7 @@ export class RouterCore<
|
|
|
2622
2641
|
await route.options.loader?.(getLoaderContext())
|
|
2623
2642
|
|
|
2624
2643
|
handleRedirectAndNotFound(
|
|
2625
|
-
this.getMatch(matchId)
|
|
2644
|
+
this.getMatch(matchId),
|
|
2626
2645
|
loaderData,
|
|
2627
2646
|
)
|
|
2628
2647
|
updateMatch(matchId, (prev) => ({
|
|
@@ -2634,7 +2653,8 @@ export class RouterCore<
|
|
|
2634
2653
|
// so we need to wait for it to resolve before
|
|
2635
2654
|
// we can use the options
|
|
2636
2655
|
await route._lazyPromise
|
|
2637
|
-
const
|
|
2656
|
+
const headResult = executeHead()
|
|
2657
|
+
const head = headResult ? await headResult : undefined
|
|
2638
2658
|
await potentialPendingMinPromise()
|
|
2639
2659
|
|
|
2640
2660
|
// Last but not least, wait for the the components
|
|
@@ -2653,18 +2673,19 @@ export class RouterCore<
|
|
|
2653
2673
|
|
|
2654
2674
|
await potentialPendingMinPromise()
|
|
2655
2675
|
|
|
2656
|
-
handleRedirectAndNotFound(this.getMatch(matchId)
|
|
2676
|
+
handleRedirectAndNotFound(this.getMatch(matchId), e)
|
|
2657
2677
|
|
|
2658
2678
|
try {
|
|
2659
2679
|
route.options.onError?.(e)
|
|
2660
2680
|
} catch (onErrorError) {
|
|
2661
2681
|
error = onErrorError
|
|
2662
2682
|
handleRedirectAndNotFound(
|
|
2663
|
-
this.getMatch(matchId)
|
|
2683
|
+
this.getMatch(matchId),
|
|
2664
2684
|
onErrorError,
|
|
2665
2685
|
)
|
|
2666
2686
|
}
|
|
2667
|
-
const
|
|
2687
|
+
const headResult = executeHead()
|
|
2688
|
+
const head = headResult ? await headResult : undefined
|
|
2668
2689
|
updateMatch(matchId, (prev) => ({
|
|
2669
2690
|
...prev,
|
|
2670
2691
|
error,
|
|
@@ -2674,16 +2695,20 @@ export class RouterCore<
|
|
|
2674
2695
|
}))
|
|
2675
2696
|
}
|
|
2676
2697
|
} catch (err) {
|
|
2677
|
-
const
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2698
|
+
const match = this.getMatch(matchId)
|
|
2699
|
+
// in case of a redirecting match during preload, the match does not exist
|
|
2700
|
+
if (match) {
|
|
2701
|
+
const headResult = executeHead()
|
|
2702
|
+
if (headResult) {
|
|
2703
|
+
const head = await headResult
|
|
2704
|
+
updateMatch(matchId, (prev) => ({
|
|
2705
|
+
...prev,
|
|
2706
|
+
...head,
|
|
2707
|
+
}))
|
|
2684
2708
|
}
|
|
2685
|
-
|
|
2686
|
-
|
|
2709
|
+
match._nonReactive.loaderPromise = undefined
|
|
2710
|
+
}
|
|
2711
|
+
handleRedirectAndNotFound(match, err)
|
|
2687
2712
|
}
|
|
2688
2713
|
}
|
|
2689
2714
|
|
|
@@ -2718,11 +2743,14 @@ export class RouterCore<
|
|
|
2718
2743
|
// if the loader did not run, still update head.
|
|
2719
2744
|
// reason: parent's beforeLoad may have changed the route context
|
|
2720
2745
|
// and only now do we know the route context (and that the loader would not run)
|
|
2721
|
-
const
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2746
|
+
const headResult = executeHead()
|
|
2747
|
+
if (headResult) {
|
|
2748
|
+
const head = await headResult
|
|
2749
|
+
updateMatch(matchId, (prev) => ({
|
|
2750
|
+
...prev,
|
|
2751
|
+
...head,
|
|
2752
|
+
}))
|
|
2753
|
+
}
|
|
2726
2754
|
}
|
|
2727
2755
|
}
|
|
2728
2756
|
if (!loaderIsRunningAsync) {
|