@tanstack/router-core 1.131.21 → 1.131.23
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 +70 -74
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/router.cjs +2 -2
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/utils.cjs +8 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +1 -0
- package/dist/esm/load-matches.js +70 -74
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/router.js +3 -3
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js +8 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/load-matches.ts +102 -112
- package/src/router.ts +5 -6
- package/src/utils.ts +11 -0
|
@@ -19,10 +19,6 @@ const resolvePreload = (inner, matchId) => {
|
|
|
19
19
|
const _handleNotFound = (inner, err) => {
|
|
20
20
|
var _a;
|
|
21
21
|
const routeCursor = inner.router.routesById[err.routeId ?? ""] ?? inner.router.routeTree;
|
|
22
|
-
const matchesByRouteId = {};
|
|
23
|
-
for (const match of inner.matches) {
|
|
24
|
-
matchesByRouteId[match.routeId] = match;
|
|
25
|
-
}
|
|
26
22
|
if (!routeCursor.options.notFoundComponent && ((_a = inner.router.options) == null ? void 0 : _a.defaultNotFoundComponent)) {
|
|
27
23
|
routeCursor.options.notFoundComponent = inner.router.options.defaultNotFoundComponent;
|
|
28
24
|
}
|
|
@@ -30,7 +26,7 @@ const _handleNotFound = (inner, err) => {
|
|
|
30
26
|
routeCursor.options.notFoundComponent,
|
|
31
27
|
"No notFoundComponent found. Please set a notFoundComponent on your route or provide a defaultNotFoundComponent to the router."
|
|
32
28
|
);
|
|
33
|
-
const matchForRoute =
|
|
29
|
+
const matchForRoute = inner.matches.find((m) => m.routeId === routeCursor.id);
|
|
34
30
|
invariant(matchForRoute, "Could not find match for route: " + routeCursor.id);
|
|
35
31
|
inner.updateMatch(matchForRoute.id, (prev) => ({
|
|
36
32
|
...prev,
|
|
@@ -148,7 +144,7 @@ const isBeforeLoadSsr = (inner, matchId, index, route) => {
|
|
|
148
144
|
existingMatch.ssr = parentOverride(route.options.ssr);
|
|
149
145
|
return;
|
|
150
146
|
}
|
|
151
|
-
const { search, params } =
|
|
147
|
+
const { search, params } = existingMatch;
|
|
152
148
|
const ssrFnContext = {
|
|
153
149
|
search: makeMaybe(search, existingMatch.searchError),
|
|
154
150
|
params: makeMaybe(params, existingMatch.paramsError),
|
|
@@ -174,9 +170,8 @@ const isBeforeLoadSsr = (inner, matchId, index, route) => {
|
|
|
174
170
|
existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr);
|
|
175
171
|
return;
|
|
176
172
|
};
|
|
177
|
-
const setupPendingTimeout = (inner, matchId, route) => {
|
|
173
|
+
const setupPendingTimeout = (inner, matchId, route, match) => {
|
|
178
174
|
var _a;
|
|
179
|
-
const match = inner.router.getMatch(matchId);
|
|
180
175
|
if (match._nonReactive.pendingTimeout !== void 0) return;
|
|
181
176
|
const pendingMs = route.options.pendingMs ?? inner.router.options.defaultPendingMs;
|
|
182
177
|
const shouldPending = !!(inner.onReady && !inner.router.isServer && !resolvePreload(inner, matchId) && (route.options.loader || route.options.beforeLoad || routeNeedsPreload(route)) && typeof pendingMs === "number" && pendingMs !== Infinity && (route.options.pendingComponent ?? ((_a = inner.router.options) == null ? void 0 : _a.defaultPendingComponent)));
|
|
@@ -191,23 +186,22 @@ const shouldExecuteBeforeLoad = (inner, matchId, route) => {
|
|
|
191
186
|
const existingMatch = inner.router.getMatch(matchId);
|
|
192
187
|
if (!existingMatch._nonReactive.beforeLoadPromise && !existingMatch._nonReactive.loaderPromise)
|
|
193
188
|
return true;
|
|
194
|
-
setupPendingTimeout(inner, matchId, route);
|
|
189
|
+
setupPendingTimeout(inner, matchId, route, existingMatch);
|
|
195
190
|
const then = () => {
|
|
196
|
-
let
|
|
191
|
+
let result = true;
|
|
197
192
|
const match = inner.router.getMatch(matchId);
|
|
198
193
|
if (match.status === "error") {
|
|
199
|
-
|
|
194
|
+
result = true;
|
|
200
195
|
} else if (match.preload && (match.status === "redirected" || match.status === "notFound")) {
|
|
201
196
|
handleRedirectAndNotFound(inner, match, match.error);
|
|
202
197
|
}
|
|
203
|
-
return
|
|
198
|
+
return result;
|
|
204
199
|
};
|
|
205
200
|
return existingMatch._nonReactive.beforeLoadPromise ? existingMatch._nonReactive.beforeLoadPromise.then(then) : then();
|
|
206
201
|
};
|
|
207
202
|
const executeBeforeLoad = (inner, matchId, index, route) => {
|
|
208
203
|
var _a;
|
|
209
204
|
const match = inner.router.getMatch(matchId);
|
|
210
|
-
match._nonReactive.beforeLoadPromise = utils.createControlledPromise();
|
|
211
205
|
const prevLoadPromise = match._nonReactive.loadPromise;
|
|
212
206
|
match._nonReactive.loadPromise = utils.createControlledPromise(() => {
|
|
213
207
|
prevLoadPromise == null ? void 0 : prevLoadPromise.resolve();
|
|
@@ -219,7 +213,7 @@ const executeBeforeLoad = (inner, matchId, index, route) => {
|
|
|
219
213
|
if (searchError) {
|
|
220
214
|
handleSerialError(inner, index, searchError, "VALIDATE_SEARCH");
|
|
221
215
|
}
|
|
222
|
-
setupPendingTimeout(inner, matchId, route);
|
|
216
|
+
setupPendingTimeout(inner, matchId, route, match);
|
|
223
217
|
const abortController = new AbortController();
|
|
224
218
|
const parentMatchId = (_a = inner.matches[index - 1]) == null ? void 0 : _a.id;
|
|
225
219
|
const parentMatch = parentMatchId ? inner.router.getMatch(parentMatchId) : void 0;
|
|
@@ -253,6 +247,7 @@ const executeBeforeLoad = (inner, matchId, index, route) => {
|
|
|
253
247
|
});
|
|
254
248
|
return;
|
|
255
249
|
}
|
|
250
|
+
match._nonReactive.beforeLoadPromise = utils.createControlledPromise();
|
|
256
251
|
const { search, params, cause } = match;
|
|
257
252
|
const preload = resolvePreload(inner, matchId);
|
|
258
253
|
const beforeLoadFnContext = {
|
|
@@ -330,8 +325,8 @@ const handleBeforeLoad = (inner, index) => {
|
|
|
330
325
|
);
|
|
331
326
|
return utils.isPromise(shouldExecuteBeforeLoadResult) ? shouldExecuteBeforeLoadResult.then(execute) : execute(shouldExecuteBeforeLoadResult);
|
|
332
327
|
};
|
|
333
|
-
const execute = (
|
|
334
|
-
if (
|
|
328
|
+
const execute = (shouldExec) => {
|
|
329
|
+
if (shouldExec) {
|
|
335
330
|
return executeBeforeLoad(inner, matchId, index, route);
|
|
336
331
|
}
|
|
337
332
|
return;
|
|
@@ -372,10 +367,6 @@ const executeHead = (inner, matchId, route) => {
|
|
|
372
367
|
};
|
|
373
368
|
});
|
|
374
369
|
};
|
|
375
|
-
const potentialPendingMinPromise = (inner, matchId) => {
|
|
376
|
-
const latestMatch = inner.router.getMatch(matchId);
|
|
377
|
-
return latestMatch._nonReactive.minPendingPromise;
|
|
378
|
-
};
|
|
379
370
|
const getLoaderContext = (inner, matchId, index, route) => {
|
|
380
371
|
const parentMatchPromise = inner.matchPromises[index - 1];
|
|
381
372
|
const { params, loaderDeps, abortController, context, cause } = inner.router.getMatch(matchId);
|
|
@@ -399,8 +390,9 @@ const getLoaderContext = (inner, matchId, index, route) => {
|
|
|
399
390
|
const runLoader = async (inner, matchId, index, route) => {
|
|
400
391
|
var _a, _b, _c, _d;
|
|
401
392
|
try {
|
|
393
|
+
const match = inner.router.getMatch(matchId);
|
|
402
394
|
try {
|
|
403
|
-
if (!inner.router.isServer ||
|
|
395
|
+
if (!inner.router.isServer || match.ssr === true) {
|
|
404
396
|
loadRouteChunk(route);
|
|
405
397
|
}
|
|
406
398
|
const loaderResult = (_b = (_a = route.options).loader) == null ? void 0 : _b.call(
|
|
@@ -408,7 +400,7 @@ const runLoader = async (inner, matchId, index, route) => {
|
|
|
408
400
|
getLoaderContext(inner, matchId, index, route)
|
|
409
401
|
);
|
|
410
402
|
const loaderResultIsPromise = route.options.loader && utils.isPromise(loaderResult);
|
|
411
|
-
const willLoadSomething = !!(loaderResultIsPromise || route._lazyPromise || route._componentsPromise || route.options.head || route.options.scripts || route.options.headers ||
|
|
403
|
+
const willLoadSomething = !!(loaderResultIsPromise || route._lazyPromise || route._componentsPromise || route.options.head || route.options.scripts || route.options.headers || match._nonReactive.minPendingPromise);
|
|
412
404
|
if (willLoadSomething) {
|
|
413
405
|
inner.updateMatch(matchId, (prev) => ({
|
|
414
406
|
...prev,
|
|
@@ -432,7 +424,7 @@ const runLoader = async (inner, matchId, index, route) => {
|
|
|
432
424
|
if (route._lazyPromise) await route._lazyPromise;
|
|
433
425
|
const headResult = executeHead(inner, matchId, route);
|
|
434
426
|
const head = headResult ? await headResult : void 0;
|
|
435
|
-
const pendingPromise =
|
|
427
|
+
const pendingPromise = match._nonReactive.minPendingPromise;
|
|
436
428
|
if (pendingPromise) await pendingPromise;
|
|
437
429
|
if (route._componentsPromise) await route._componentsPromise;
|
|
438
430
|
inner.updateMatch(matchId, (prev) => ({
|
|
@@ -445,7 +437,7 @@ const runLoader = async (inner, matchId, index, route) => {
|
|
|
445
437
|
}));
|
|
446
438
|
} catch (e) {
|
|
447
439
|
let error = e;
|
|
448
|
-
const pendingPromise =
|
|
440
|
+
const pendingPromise = match._nonReactive.minPendingPromise;
|
|
449
441
|
if (pendingPromise) await pendingPromise;
|
|
450
442
|
handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), e);
|
|
451
443
|
try {
|
|
@@ -490,7 +482,6 @@ const loadRouteMatch = async (inner, index) => {
|
|
|
490
482
|
let loaderShouldRunAsync = false;
|
|
491
483
|
let loaderIsRunningAsync = false;
|
|
492
484
|
const route = inner.router.looseRoutesById[routeId];
|
|
493
|
-
const prevMatch = inner.router.getMatch(matchId);
|
|
494
485
|
if (shouldSkipLoader(inner, matchId)) {
|
|
495
486
|
if (inner.router.isServer) {
|
|
496
487
|
const headResult = executeHead(inner, matchId, route);
|
|
@@ -503,60 +494,63 @@ const loadRouteMatch = async (inner, index) => {
|
|
|
503
494
|
}
|
|
504
495
|
return inner.router.getMatch(matchId);
|
|
505
496
|
}
|
|
506
|
-
} else if (prevMatch._nonReactive.loaderPromise) {
|
|
507
|
-
if (prevMatch.status === "success" && !inner.sync && !prevMatch.preload) {
|
|
508
|
-
return inner.router.getMatch(matchId);
|
|
509
|
-
}
|
|
510
|
-
await prevMatch._nonReactive.loaderPromise;
|
|
511
|
-
const match2 = inner.router.getMatch(matchId);
|
|
512
|
-
if (match2.error) {
|
|
513
|
-
handleRedirectAndNotFound(inner, match2, match2.error);
|
|
514
|
-
}
|
|
515
497
|
} else {
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
...prev,
|
|
527
|
-
preload: nextPreload
|
|
528
|
-
}));
|
|
529
|
-
}
|
|
530
|
-
const { status, invalid } = inner.router.getMatch(matchId);
|
|
531
|
-
loaderShouldRunAsync = status === "success" && (invalid || (shouldReload ?? age > staleAge));
|
|
532
|
-
if (preload && route.options.preload === false) ;
|
|
533
|
-
else if (loaderShouldRunAsync && !inner.sync) {
|
|
534
|
-
loaderIsRunningAsync = true;
|
|
535
|
-
(async () => {
|
|
536
|
-
var _a2, _b2;
|
|
537
|
-
try {
|
|
538
|
-
await runLoader(inner, matchId, index, route);
|
|
539
|
-
const match3 = inner.router.getMatch(matchId);
|
|
540
|
-
(_a2 = match3._nonReactive.loaderPromise) == null ? void 0 : _a2.resolve();
|
|
541
|
-
(_b2 = match3._nonReactive.loadPromise) == null ? void 0 : _b2.resolve();
|
|
542
|
-
match3._nonReactive.loaderPromise = void 0;
|
|
543
|
-
} catch (err) {
|
|
544
|
-
if (redirect.isRedirect(err)) {
|
|
545
|
-
await inner.router.navigate(err.options);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
})();
|
|
549
|
-
} else if (status !== "success" || loaderShouldRunAsync && inner.sync) {
|
|
550
|
-
await runLoader(inner, matchId, index, route);
|
|
498
|
+
const prevMatch = inner.router.getMatch(matchId);
|
|
499
|
+
if (prevMatch._nonReactive.loaderPromise) {
|
|
500
|
+
if (prevMatch.status === "success" && !inner.sync && !prevMatch.preload) {
|
|
501
|
+
return prevMatch;
|
|
502
|
+
}
|
|
503
|
+
await prevMatch._nonReactive.loaderPromise;
|
|
504
|
+
const match2 = inner.router.getMatch(matchId);
|
|
505
|
+
if (match2.error) {
|
|
506
|
+
handleRedirectAndNotFound(inner, match2, match2.error);
|
|
507
|
+
}
|
|
551
508
|
} else {
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
|
|
509
|
+
const age = Date.now() - prevMatch.updatedAt;
|
|
510
|
+
const preload = resolvePreload(inner, matchId);
|
|
511
|
+
const staleAge = preload ? route.options.preloadStaleTime ?? inner.router.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? inner.router.options.defaultStaleTime ?? 0;
|
|
512
|
+
const shouldReloadOption = route.options.shouldReload;
|
|
513
|
+
const shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(getLoaderContext(inner, matchId, index, route)) : shouldReloadOption;
|
|
514
|
+
const nextPreload = !!preload && !inner.router.state.matches.some((d) => d.id === matchId);
|
|
515
|
+
const match2 = inner.router.getMatch(matchId);
|
|
516
|
+
match2._nonReactive.loaderPromise = utils.createControlledPromise();
|
|
517
|
+
if (nextPreload !== match2.preload) {
|
|
555
518
|
inner.updateMatch(matchId, (prev) => ({
|
|
556
519
|
...prev,
|
|
557
|
-
|
|
520
|
+
preload: nextPreload
|
|
558
521
|
}));
|
|
559
522
|
}
|
|
523
|
+
const { status, invalid } = match2;
|
|
524
|
+
loaderShouldRunAsync = status === "success" && (invalid || (shouldReload ?? age > staleAge));
|
|
525
|
+
if (preload && route.options.preload === false) ;
|
|
526
|
+
else if (loaderShouldRunAsync && !inner.sync) {
|
|
527
|
+
loaderIsRunningAsync = true;
|
|
528
|
+
(async () => {
|
|
529
|
+
var _a2, _b2;
|
|
530
|
+
try {
|
|
531
|
+
await runLoader(inner, matchId, index, route);
|
|
532
|
+
const match3 = inner.router.getMatch(matchId);
|
|
533
|
+
(_a2 = match3._nonReactive.loaderPromise) == null ? void 0 : _a2.resolve();
|
|
534
|
+
(_b2 = match3._nonReactive.loadPromise) == null ? void 0 : _b2.resolve();
|
|
535
|
+
match3._nonReactive.loaderPromise = void 0;
|
|
536
|
+
} catch (err) {
|
|
537
|
+
if (redirect.isRedirect(err)) {
|
|
538
|
+
await inner.router.navigate(err.options);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
})();
|
|
542
|
+
} else if (status !== "success" || loaderShouldRunAsync && inner.sync) {
|
|
543
|
+
await runLoader(inner, matchId, index, route);
|
|
544
|
+
} else {
|
|
545
|
+
const headResult = executeHead(inner, matchId, route);
|
|
546
|
+
if (headResult) {
|
|
547
|
+
const head = await headResult;
|
|
548
|
+
inner.updateMatch(matchId, (prev) => ({
|
|
549
|
+
...prev,
|
|
550
|
+
...head
|
|
551
|
+
}));
|
|
552
|
+
}
|
|
553
|
+
}
|
|
560
554
|
}
|
|
561
555
|
}
|
|
562
556
|
const match = inner.router.getMatch(matchId);
|
|
@@ -575,8 +569,10 @@ const loadRouteMatch = async (inner, index) => {
|
|
|
575
569
|
isFetching: nextIsFetching,
|
|
576
570
|
invalid: false
|
|
577
571
|
}));
|
|
572
|
+
return inner.router.getMatch(matchId);
|
|
573
|
+
} else {
|
|
574
|
+
return match;
|
|
578
575
|
}
|
|
579
|
-
return inner.router.getMatch(matchId);
|
|
580
576
|
};
|
|
581
577
|
async function loadMatches(arg) {
|
|
582
578
|
const inner = Object.assign(arg, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-matches.cjs","sources":["../../src/load-matches.ts"],"sourcesContent":["import { batch } from '@tanstack/store'\nimport invariant from 'tiny-invariant'\nimport { createControlledPromise, isPromise } from './utils'\nimport { isNotFound } from './not-found'\nimport { rootRouteId } from './root'\nimport { isRedirect } from './redirect'\nimport type { NotFoundError } from './not-found'\nimport type { ControlledPromise } from './utils'\nimport type { ParsedLocation } from './location'\nimport type {\n AnyRoute,\n BeforeLoadContextOptions,\n LoaderFnContext,\n SsrContextOptions,\n} from './route'\nimport type { AnyRouteMatch, MakeRouteMatch } from './Matches'\nimport type { AnyRouter, UpdateMatchFn } from './router'\n\n/**\n * An object of this shape is created when calling `loadMatches`.\n * It contains everything we need for all other functions in this file\n * to work. (It's basically the function's argument, plus a few mutable states)\n */\ntype InnerLoadContext = {\n /** the calling router instance */\n router: AnyRouter\n location: ParsedLocation\n /** mutable state, scoped to a `loadMatches` call */\n firstBadMatchIndex?: number\n /** mutable state, scoped to a `loadMatches` call */\n rendered?: boolean\n updateMatch: UpdateMatchFn\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n sync?: boolean\n /** mutable state, scoped to a `loadMatches` call */\n matchPromises: Array<Promise<AnyRouteMatch>>\n}\n\nconst triggerOnReady = (inner: InnerLoadContext): void | Promise<void> => {\n if (!inner.rendered) {\n inner.rendered = true\n return inner.onReady?.()\n }\n}\n\nconst resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {\n return !!(\n inner.preload && !inner.router.state.matches.some((d) => d.id === matchId)\n )\n}\n\nconst _handleNotFound = (inner: InnerLoadContext, err: NotFoundError) => {\n // Find the route that should handle the not found error\n // First check if a specific route is requested to show the error\n const routeCursor =\n inner.router.routesById[err.routeId ?? ''] ?? inner.router.routeTree\n const matchesByRouteId: Record<string, AnyRouteMatch> = {}\n\n // Setup routesByRouteId object for quick access\n for (const match of inner.matches) {\n matchesByRouteId[match.routeId] = match\n }\n\n // Ensure a NotFoundComponent exists on the route\n if (\n !routeCursor.options.notFoundComponent &&\n (inner.router.options as any)?.defaultNotFoundComponent\n ) {\n routeCursor.options.notFoundComponent = (\n inner.router.options as any\n ).defaultNotFoundComponent\n }\n\n // Ensure we have a notFoundComponent\n invariant(\n routeCursor.options.notFoundComponent,\n 'No notFoundComponent found. Please set a notFoundComponent on your route or provide a defaultNotFoundComponent to the router.',\n )\n\n // Find the match for this route\n const matchForRoute = matchesByRouteId[routeCursor.id]\n\n invariant(matchForRoute, 'Could not find match for route: ' + routeCursor.id)\n\n // Assign the error to the match - using non-null assertion since we've checked with invariant\n inner.updateMatch(matchForRoute.id, (prev) => ({\n ...prev,\n status: 'notFound',\n error: err,\n isFetching: false,\n }))\n\n if ((err as any).routerCode === 'BEFORE_LOAD' && routeCursor.parentRoute) {\n err.routeId = routeCursor.parentRoute.id\n _handleNotFound(inner, err)\n }\n}\n\nconst handleRedirectAndNotFound = (\n inner: InnerLoadContext,\n match: AnyRouteMatch | undefined,\n err: unknown,\n): void => {\n if (!isRedirect(err) && !isNotFound(err)) return\n\n if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {\n throw err\n }\n\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n match._nonReactive.loaderPromise = undefined\n\n const status = isRedirect(err) ? 'redirected' : 'notFound'\n\n inner.updateMatch(match.id, (prev) => ({\n ...prev,\n status,\n isFetching: false,\n error: err,\n }))\n\n if (isNotFound(err) && !err.routeId) {\n err.routeId = match.routeId\n }\n\n match._nonReactive.loadPromise?.resolve()\n }\n\n if (isRedirect(err)) {\n inner.rendered = true\n err.options._fromLocation = inner.location\n err.redirectHandled = true\n err = inner.router.resolveRedirect(err)\n throw err\n } else {\n _handleNotFound(inner, err)\n throw err\n }\n}\n\nconst shouldSkipLoader = (\n inner: InnerLoadContext,\n matchId: string,\n): boolean => {\n const match = inner.router.getMatch(matchId)!\n // upon hydration, we skip the loader if the match has been dehydrated on the server\n if (!inner.router.isServer && match._nonReactive.dehydrated) {\n return true\n }\n\n if (inner.router.isServer) {\n if (match.ssr === false) {\n return true\n }\n }\n return false\n}\n\nconst handleSerialError = (\n inner: InnerLoadContext,\n index: number,\n err: any,\n routerCode: string,\n): void => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n // Much like suspense, we use a promise here to know if\n // we've been outdated by a new loadMatches call and\n // should abort the current async operation\n if (err instanceof Promise) {\n throw err\n }\n\n err.routerCode = routerCode\n inner.firstBadMatchIndex ??= index\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n\n try {\n route.options.onError?.(err)\n } catch (errorHandlerErr) {\n err = errorHandlerErr\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n }\n\n inner.updateMatch(matchId, (prev) => {\n prev._nonReactive.beforeLoadPromise?.resolve()\n prev._nonReactive.beforeLoadPromise = undefined\n prev._nonReactive.loadPromise?.resolve()\n\n return {\n ...prev,\n error: err,\n status: 'error',\n isFetching: false,\n updatedAt: Date.now(),\n abortController: new AbortController(),\n }\n })\n}\n\nconst isBeforeLoadSsr = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n\n // in SPA mode, only SSR the root route\n if (inner.router.isShell()) {\n existingMatch.ssr = matchId === rootRouteId\n return\n }\n\n if (parentMatch?.ssr === false) {\n existingMatch.ssr = false\n return\n }\n\n const parentOverride = (tempSsr: boolean | 'data-only') => {\n if (tempSsr === true && parentMatch?.ssr === 'data-only') {\n return 'data-only'\n }\n return tempSsr\n }\n\n const defaultSsr = inner.router.options.defaultSsr ?? true\n\n if (route.options.ssr === undefined) {\n existingMatch.ssr = parentOverride(defaultSsr)\n return\n }\n\n if (typeof route.options.ssr !== 'function') {\n existingMatch.ssr = parentOverride(route.options.ssr)\n return\n }\n const { search, params } = inner.router.getMatch(matchId)!\n\n const ssrFnContext: SsrContextOptions<any, any, any> = {\n search: makeMaybe(search, existingMatch.searchError),\n params: makeMaybe(params, existingMatch.paramsError),\n location: inner.location,\n matches: inner.matches.map((match) => ({\n index: match.index,\n pathname: match.pathname,\n fullPath: match.fullPath,\n staticData: match.staticData,\n id: match.id,\n routeId: match.routeId,\n search: makeMaybe(match.search, match.searchError),\n params: makeMaybe(match.params, match.paramsError),\n ssr: match.ssr,\n })),\n }\n\n const tempSsr = route.options.ssr(ssrFnContext)\n if (isPromise(tempSsr)) {\n return tempSsr.then((ssr) => {\n existingMatch.ssr = parentOverride(ssr ?? defaultSsr)\n })\n }\n\n existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr)\n return\n}\n\nconst setupPendingTimeout = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void => {\n const match = inner.router.getMatch(matchId)!\n if (match._nonReactive.pendingTimeout !== undefined) return\n\n const pendingMs =\n route.options.pendingMs ?? inner.router.options.defaultPendingMs\n const shouldPending = !!(\n inner.onReady &&\n !inner.router.isServer &&\n !resolvePreload(inner, matchId) &&\n (route.options.loader ||\n route.options.beforeLoad ||\n routeNeedsPreload(route)) &&\n typeof pendingMs === 'number' &&\n pendingMs !== Infinity &&\n (route.options.pendingComponent ??\n (inner.router.options as any)?.defaultPendingComponent)\n )\n\n if (shouldPending) {\n const pendingTimeout = setTimeout(() => {\n // Update the match and prematurely resolve the loadMatches promise so that\n // the pending component can start rendering\n triggerOnReady(inner)\n }, pendingMs)\n match._nonReactive.pendingTimeout = pendingTimeout\n }\n}\n\nconst shouldExecuteBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): boolean | Promise<boolean> => {\n const existingMatch = inner.router.getMatch(matchId)!\n\n // If we are in the middle of a load, either of these will be present\n // (not to be confused with `loadPromise`, which is always defined)\n if (\n !existingMatch._nonReactive.beforeLoadPromise &&\n !existingMatch._nonReactive.loaderPromise\n )\n return true\n\n setupPendingTimeout(inner, matchId, route)\n\n const then = () => {\n let shouldExecuteBeforeLoad = true\n const match = inner.router.getMatch(matchId)!\n if (match.status === 'error') {\n shouldExecuteBeforeLoad = true\n } else if (\n match.preload &&\n (match.status === 'redirected' || match.status === 'notFound')\n ) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n return shouldExecuteBeforeLoad\n }\n\n // Wait for the beforeLoad to resolve before we continue\n return existingMatch._nonReactive.beforeLoadPromise\n ? existingMatch._nonReactive.beforeLoadPromise.then(then)\n : then()\n}\n\nconst executeBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const match = inner.router.getMatch(matchId)!\n\n match._nonReactive.beforeLoadPromise = createControlledPromise<void>()\n // explicitly capture the previous loadPromise\n const prevLoadPromise = match._nonReactive.loadPromise\n match._nonReactive.loadPromise = createControlledPromise<void>(() => {\n prevLoadPromise?.resolve()\n })\n\n const { paramsError, searchError } = match\n\n if (paramsError) {\n handleSerialError(inner, index, paramsError, 'PARSE_PARAMS')\n }\n\n if (searchError) {\n handleSerialError(inner, index, searchError, 'VALIDATE_SEARCH')\n }\n\n setupPendingTimeout(inner, matchId, route)\n\n const abortController = new AbortController()\n\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n const parentMatchContext =\n parentMatch?.context ?? inner.router.options.context ?? undefined\n\n const context = { ...parentMatchContext, ...match.__routeContext }\n\n let isPending = false\n const pending = () => {\n if (isPending) return\n isPending = true\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'beforeLoad',\n fetchCount: prev.fetchCount + 1,\n abortController,\n context,\n }))\n }\n\n const resolve = () => {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: false,\n }))\n }\n\n // if there is no `beforeLoad` option, skip everything, batch update the store, return early\n if (!route.options.beforeLoad) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n\n const { search, params, cause } = match\n const preload = resolvePreload(inner, matchId)\n const beforeLoadFnContext: BeforeLoadContextOptions<any, any, any, any, any> =\n {\n search,\n abortController,\n params,\n preload,\n context,\n location: inner.location,\n navigate: (opts: any) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n buildLocation: inner.router.buildLocation,\n cause: preload ? 'preload' : cause,\n matches: inner.matches,\n }\n\n const updateContext = (beforeLoadContext: any) => {\n if (beforeLoadContext === undefined) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {\n pending()\n handleSerialError(inner, index, beforeLoadContext, 'BEFORE_LOAD')\n }\n\n batch(() => {\n pending()\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n __beforeLoadContext: beforeLoadContext,\n context: {\n ...prev.context,\n ...beforeLoadContext,\n },\n }))\n resolve()\n })\n }\n\n let beforeLoadContext\n try {\n beforeLoadContext = route.options.beforeLoad(beforeLoadFnContext)\n if (isPromise(beforeLoadContext)) {\n pending()\n return beforeLoadContext\n .catch((err) => {\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n })\n .then(updateContext)\n }\n } catch (err) {\n pending()\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n }\n\n updateContext(beforeLoadContext)\n return\n}\n\nconst handleBeforeLoad = (\n inner: InnerLoadContext,\n index: number,\n): void | Promise<void> => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n const serverSsr = () => {\n // on the server, determine whether SSR the current match or not\n if (inner.router.isServer) {\n const maybePromise = isBeforeLoadSsr(inner, matchId, index, route)\n if (isPromise(maybePromise)) return maybePromise.then(queueExecution)\n }\n return queueExecution()\n }\n\n const queueExecution = () => {\n if (shouldSkipLoader(inner, matchId)) return\n const shouldExecuteBeforeLoadResult = shouldExecuteBeforeLoad(\n inner,\n matchId,\n route,\n )\n return isPromise(shouldExecuteBeforeLoadResult)\n ? shouldExecuteBeforeLoadResult.then(execute)\n : execute(shouldExecuteBeforeLoadResult)\n }\n\n const execute = (shouldExecuteBeforeLoad: boolean) => {\n if (shouldExecuteBeforeLoad) {\n // If we are not in the middle of a load OR the previous load failed, start it\n return executeBeforeLoad(inner, matchId, index, route)\n }\n return\n }\n\n return serverSsr()\n}\n\nconst executeHead = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<\n Pick<\n AnyRouteMatch,\n 'meta' | 'links' | 'headScripts' | 'headers' | 'scripts' | 'styles'\n >\n> => {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (!match) {\n return\n }\n if (!route.options.head && !route.options.scripts && !route.options.headers) {\n return\n }\n const assetContext = {\n matches: inner.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n\n return Promise.all([\n route.options.head?.(assetContext),\n route.options.scripts?.(assetContext),\n route.options.headers?.(assetContext),\n ]).then(([headFnContent, scripts, headers]) => {\n const meta = headFnContent?.meta\n const links = headFnContent?.links\n const headScripts = headFnContent?.scripts\n const styles = headFnContent?.styles\n\n return {\n meta,\n links,\n headScripts,\n headers,\n scripts,\n styles,\n }\n })\n}\n\nconst potentialPendingMinPromise = (\n inner: InnerLoadContext,\n matchId: string,\n): void | ControlledPromise<void> => {\n const latestMatch = inner.router.getMatch(matchId)!\n return latestMatch._nonReactive.minPendingPromise\n}\n\nconst getLoaderContext = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): LoaderFnContext => {\n const parentMatchPromise = inner.matchPromises[index - 1] as any\n const { params, loaderDeps, abortController, context, cause } =\n inner.router.getMatch(matchId)!\n\n const preload = resolvePreload(inner, matchId)\n\n return {\n params,\n deps: loaderDeps,\n preload: !!preload,\n parentMatchPromise,\n abortController: abortController,\n context,\n location: inner.location,\n navigate: (opts) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n cause: preload ? 'preload' : cause,\n route,\n }\n}\n\nconst runLoader = async (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): Promise<void> => {\n try {\n // If the Matches component rendered\n // the pending component and needs to show it for\n // a minimum duration, we''ll wait for it to resolve\n // before committing to the match and resolving\n // the loadPromise\n\n // Actually run the loader and handle the result\n try {\n if (\n !inner.router.isServer ||\n inner.router.getMatch(matchId)!.ssr === true\n ) {\n loadRouteChunk(route)\n }\n\n // Kick off the loader!\n const loaderResult = route.options.loader?.(\n getLoaderContext(inner, matchId, index, route),\n )\n const loaderResultIsPromise =\n route.options.loader && isPromise(loaderResult)\n\n const willLoadSomething = !!(\n loaderResultIsPromise ||\n route._lazyPromise ||\n route._componentsPromise ||\n route.options.head ||\n route.options.scripts ||\n route.options.headers ||\n inner.router.getMatch(matchId)!._nonReactive.minPendingPromise\n )\n\n if (willLoadSomething) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'loader',\n }))\n }\n\n if (route.options.loader) {\n const loaderData = loaderResultIsPromise\n ? await loaderResult\n : loaderResult\n\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n loaderData,\n )\n if (loaderData !== undefined) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n loaderData,\n }))\n }\n }\n\n // Lazy option can modify the route options,\n // so we need to wait for it to resolve before\n // we can use the options\n if (route._lazyPromise) await route._lazyPromise\n const headResult = executeHead(inner, matchId, route)\n const head = headResult ? await headResult : undefined\n const pendingPromise = potentialPendingMinPromise(inner, matchId)\n if (pendingPromise) await pendingPromise\n\n // Last but not least, wait for the the components\n // to be preloaded before we resolve the match\n if (route._componentsPromise) await route._componentsPromise\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error: undefined,\n status: 'success',\n isFetching: false,\n updatedAt: Date.now(),\n ...head,\n }))\n } catch (e) {\n let error = e\n\n const pendingPromise = potentialPendingMinPromise(inner, matchId)\n if (pendingPromise) await pendingPromise\n\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), e)\n\n try {\n route.options.onError?.(e)\n } catch (onErrorError) {\n error = onErrorError\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n onErrorError,\n )\n }\n const headResult = executeHead(inner, matchId, route)\n const head = headResult ? await headResult : undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error,\n status: 'error',\n isFetching: false,\n ...head,\n }))\n }\n } catch (err) {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n match._nonReactive.loaderPromise = undefined\n }\n handleRedirectAndNotFound(inner, match, err)\n }\n}\n\nconst loadRouteMatch = async (\n inner: InnerLoadContext,\n index: number,\n): Promise<AnyRouteMatch> => {\n const { id: matchId, routeId } = inner.matches[index]!\n let loaderShouldRunAsync = false\n let loaderIsRunningAsync = false\n const route = inner.router.looseRoutesById[routeId]!\n\n const prevMatch = inner.router.getMatch(matchId)!\n if (shouldSkipLoader(inner, matchId)) {\n if (inner.router.isServer) {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n return inner.router.getMatch(matchId)!\n }\n }\n // there is a loaderPromise, so we are in the middle of a load\n else if (prevMatch._nonReactive.loaderPromise) {\n // do not block if we already have stale data we can show\n // but only if the ongoing load is not a preload since error handling is different for preloads\n // and we don't want to swallow errors\n if (prevMatch.status === 'success' && !inner.sync && !prevMatch.preload) {\n return inner.router.getMatch(matchId)!\n }\n await prevMatch._nonReactive.loaderPromise\n const match = inner.router.getMatch(matchId)!\n if (match.error) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n } else {\n // This is where all of the stale-while-revalidate magic happens\n const age = Date.now() - inner.router.getMatch(matchId)!.updatedAt\n\n const preload = resolvePreload(inner, matchId)\n\n const staleAge = preload\n ? (route.options.preloadStaleTime ??\n inner.router.options.defaultPreloadStaleTime ??\n 30_000) // 30 seconds for preloads by default\n : (route.options.staleTime ?? inner.router.options.defaultStaleTime ?? 0)\n\n const shouldReloadOption = route.options.shouldReload\n\n // Default to reloading the route all the time\n // Allow shouldReload to get the last say,\n // if provided.\n const shouldReload =\n typeof shouldReloadOption === 'function'\n ? shouldReloadOption(getLoaderContext(inner, matchId, index, route))\n : shouldReloadOption\n\n const nextPreload =\n !!preload && !inner.router.state.matches.some((d) => d.id === matchId)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise = createControlledPromise<void>()\n if (nextPreload !== match.preload) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n preload: nextPreload,\n }))\n }\n\n // If the route is successful and still fresh, just resolve\n const { status, invalid } = inner.router.getMatch(matchId)!\n loaderShouldRunAsync =\n status === 'success' && (invalid || (shouldReload ?? age > staleAge))\n if (preload && route.options.preload === false) {\n // Do nothing\n } else if (loaderShouldRunAsync && !inner.sync) {\n loaderIsRunningAsync = true\n ;(async () => {\n try {\n await runLoader(inner, matchId, index, route)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n match._nonReactive.loaderPromise = undefined\n } catch (err) {\n if (isRedirect(err)) {\n await inner.router.navigate(err.options)\n }\n }\n })()\n } else if (status !== 'success' || (loaderShouldRunAsync && inner.sync)) {\n await runLoader(inner, matchId, index, route)\n } else {\n // if the loader did not run, still update head.\n // reason: parent's beforeLoad may have changed the route context\n // and only now do we know the route context (and that the loader would not run)\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n }\n }\n const match = inner.router.getMatch(matchId)!\n if (!loaderIsRunningAsync) {\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n }\n\n clearTimeout(match._nonReactive.pendingTimeout)\n match._nonReactive.pendingTimeout = undefined\n if (!loaderIsRunningAsync) match._nonReactive.loaderPromise = undefined\n match._nonReactive.dehydrated = undefined\n const nextIsFetching = loaderIsRunningAsync ? match.isFetching : false\n if (nextIsFetching !== match.isFetching || match.invalid !== false) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: nextIsFetching,\n invalid: false,\n }))\n }\n return inner.router.getMatch(matchId)!\n}\n\nexport async function loadMatches(arg: {\n router: AnyRouter\n location: ParsedLocation\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n updateMatch: UpdateMatchFn\n sync?: boolean\n}): Promise<Array<MakeRouteMatch>> {\n const inner: InnerLoadContext = Object.assign(arg, {\n matchPromises: [],\n })\n\n // make sure the pending component is immediately rendered when hydrating a match that is not SSRed\n // the pending component was already rendered on the server and we want to keep it shown on the client until minPendingMs is reached\n if (\n !inner.router.isServer &&\n inner.router.state.matches.some((d) => d._forcePending)\n ) {\n triggerOnReady(inner)\n }\n\n try {\n // Execute all beforeLoads one by one\n for (let i = 0; i < inner.matches.length; i++) {\n const beforeLoad = handleBeforeLoad(inner, i)\n if (isPromise(beforeLoad)) await beforeLoad\n }\n\n // Execute all loaders in parallel\n const max = inner.firstBadMatchIndex ?? inner.matches.length\n for (let i = 0; i < max; i++) {\n inner.matchPromises.push(loadRouteMatch(inner, i))\n }\n await Promise.all(inner.matchPromises)\n\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n } catch (err) {\n if (isNotFound(err) && !inner.preload) {\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n throw err\n }\n if (isRedirect(err)) {\n throw err\n }\n }\n\n return inner.matches\n}\n\nexport async function loadRouteChunk(route: AnyRoute) {\n if (!route._lazyLoaded && route._lazyPromise === undefined) {\n if (route.lazyFn) {\n route._lazyPromise = route.lazyFn().then((lazyRoute) => {\n // explicitly don't copy over the lazy route's id\n const { id: _id, ...options } = lazyRoute.options\n Object.assign(route.options, options)\n route._lazyLoaded = true\n route._lazyPromise = undefined // gc promise, we won't need it anymore\n })\n } else {\n route._lazyLoaded = true\n }\n }\n\n // If for some reason lazy resolves more lazy components...\n // We'll wait for that before we attempt to preload the\n // components themselves.\n if (!route._componentsLoaded && route._componentsPromise === undefined) {\n const loadComponents = () => {\n const preloads = []\n for (const type of componentTypes) {\n const preload = (route.options[type] as any)?.preload\n if (preload) preloads.push(preload())\n }\n if (preloads.length)\n return Promise.all(preloads).then(() => {\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n })\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n return\n }\n route._componentsPromise = route._lazyPromise\n ? route._lazyPromise.then(loadComponents)\n : loadComponents()\n }\n return route._componentsPromise\n}\n\nfunction makeMaybe<TValue, TError>(\n value: TValue,\n error: TError,\n): { status: 'success'; value: TValue } | { status: 'error'; error: TError } {\n if (error) {\n return { status: 'error' as const, error }\n }\n return { status: 'success' as const, value }\n}\n\nexport function routeNeedsPreload(route: AnyRoute) {\n for (const componentType of componentTypes) {\n if ((route.options[componentType] as any)?.preload) {\n return true\n }\n }\n return false\n}\n\nexport const componentTypes = [\n 'component',\n 'errorComponent',\n 'pendingComponent',\n 'notFoundComponent',\n] as const\n"],"names":["isRedirect","isNotFound","_a","_b","rootRouteId","tempSsr","isPromise","shouldExecuteBeforeLoad","createControlledPromise","batch","beforeLoadContext","match"],"mappings":";;;;;;;;AAwCA,MAAM,iBAAiB,CAAC,UAAkD;;AACpE,MAAA,CAAC,MAAM,UAAU;AACnB,UAAM,WAAW;AACjB,YAAO,WAAM,YAAN;AAAA,EAAgB;AAE3B;AAEA,MAAM,iBAAiB,CAAC,OAAyB,YAA6B;AAC5E,SAAO,CAAC,EACN,MAAM,WAAW,CAAC,MAAM,OAAO,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO;AAE7E;AAEA,MAAM,kBAAkB,CAAC,OAAyB,QAAuB;;AAGjE,QAAA,cACJ,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AAA,EACA;AAAA,EACA;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"load-matches.cjs","sources":["../../src/load-matches.ts"],"sourcesContent":["import { batch } from '@tanstack/store'\nimport invariant from 'tiny-invariant'\nimport { createControlledPromise, isPromise } from './utils'\nimport { isNotFound } from './not-found'\nimport { rootRouteId } from './root'\nimport { isRedirect } from './redirect'\nimport type { NotFoundError } from './not-found'\nimport type { ParsedLocation } from './location'\nimport type {\n AnyRoute,\n BeforeLoadContextOptions,\n LoaderFnContext,\n SsrContextOptions,\n} from './route'\nimport type { AnyRouteMatch, MakeRouteMatch } from './Matches'\nimport type { AnyRouter, UpdateMatchFn } from './router'\n\n/**\n * An object of this shape is created when calling `loadMatches`.\n * It contains everything we need for all other functions in this file\n * to work. (It's basically the function's argument, plus a few mutable states)\n */\ntype InnerLoadContext = {\n /** the calling router instance */\n router: AnyRouter\n location: ParsedLocation\n /** mutable state, scoped to a `loadMatches` call */\n firstBadMatchIndex?: number\n /** mutable state, scoped to a `loadMatches` call */\n rendered?: boolean\n updateMatch: UpdateMatchFn\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n sync?: boolean\n /** mutable state, scoped to a `loadMatches` call */\n matchPromises: Array<Promise<AnyRouteMatch>>\n}\n\nconst triggerOnReady = (inner: InnerLoadContext): void | Promise<void> => {\n if (!inner.rendered) {\n inner.rendered = true\n return inner.onReady?.()\n }\n}\n\nconst resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {\n return !!(\n inner.preload && !inner.router.state.matches.some((d) => d.id === matchId)\n )\n}\n\nconst _handleNotFound = (inner: InnerLoadContext, err: NotFoundError) => {\n // Find the route that should handle the not found error\n // First check if a specific route is requested to show the error\n const routeCursor =\n inner.router.routesById[err.routeId ?? ''] ?? inner.router.routeTree\n\n // Ensure a NotFoundComponent exists on the route\n if (\n !routeCursor.options.notFoundComponent &&\n (inner.router.options as any)?.defaultNotFoundComponent\n ) {\n routeCursor.options.notFoundComponent = (\n inner.router.options as any\n ).defaultNotFoundComponent\n }\n\n // Ensure we have a notFoundComponent\n invariant(\n routeCursor.options.notFoundComponent,\n 'No notFoundComponent found. Please set a notFoundComponent on your route or provide a defaultNotFoundComponent to the router.',\n )\n\n // Find the match for this route\n const matchForRoute = inner.matches.find((m) => m.routeId === routeCursor.id)\n\n invariant(matchForRoute, 'Could not find match for route: ' + routeCursor.id)\n\n // Assign the error to the match - using non-null assertion since we've checked with invariant\n inner.updateMatch(matchForRoute.id, (prev) => ({\n ...prev,\n status: 'notFound',\n error: err,\n isFetching: false,\n }))\n\n if ((err as any).routerCode === 'BEFORE_LOAD' && routeCursor.parentRoute) {\n err.routeId = routeCursor.parentRoute.id\n _handleNotFound(inner, err)\n }\n}\n\nconst handleRedirectAndNotFound = (\n inner: InnerLoadContext,\n match: AnyRouteMatch | undefined,\n err: unknown,\n): void => {\n if (!isRedirect(err) && !isNotFound(err)) return\n\n if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {\n throw err\n }\n\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n match._nonReactive.loaderPromise = undefined\n\n const status = isRedirect(err) ? 'redirected' : 'notFound'\n\n inner.updateMatch(match.id, (prev) => ({\n ...prev,\n status,\n isFetching: false,\n error: err,\n }))\n\n if (isNotFound(err) && !err.routeId) {\n err.routeId = match.routeId\n }\n\n match._nonReactive.loadPromise?.resolve()\n }\n\n if (isRedirect(err)) {\n inner.rendered = true\n err.options._fromLocation = inner.location\n err.redirectHandled = true\n err = inner.router.resolveRedirect(err)\n throw err\n } else {\n _handleNotFound(inner, err)\n throw err\n }\n}\n\nconst shouldSkipLoader = (\n inner: InnerLoadContext,\n matchId: string,\n): boolean => {\n const match = inner.router.getMatch(matchId)!\n // upon hydration, we skip the loader if the match has been dehydrated on the server\n if (!inner.router.isServer && match._nonReactive.dehydrated) {\n return true\n }\n\n if (inner.router.isServer) {\n if (match.ssr === false) {\n return true\n }\n }\n return false\n}\n\nconst handleSerialError = (\n inner: InnerLoadContext,\n index: number,\n err: any,\n routerCode: string,\n): void => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n // Much like suspense, we use a promise here to know if\n // we've been outdated by a new loadMatches call and\n // should abort the current async operation\n if (err instanceof Promise) {\n throw err\n }\n\n err.routerCode = routerCode\n inner.firstBadMatchIndex ??= index\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n\n try {\n route.options.onError?.(err)\n } catch (errorHandlerErr) {\n err = errorHandlerErr\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n }\n\n inner.updateMatch(matchId, (prev) => {\n prev._nonReactive.beforeLoadPromise?.resolve()\n prev._nonReactive.beforeLoadPromise = undefined\n prev._nonReactive.loadPromise?.resolve()\n\n return {\n ...prev,\n error: err,\n status: 'error',\n isFetching: false,\n updatedAt: Date.now(),\n abortController: new AbortController(),\n }\n })\n}\n\nconst isBeforeLoadSsr = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n\n // in SPA mode, only SSR the root route\n if (inner.router.isShell()) {\n existingMatch.ssr = matchId === rootRouteId\n return\n }\n\n if (parentMatch?.ssr === false) {\n existingMatch.ssr = false\n return\n }\n\n const parentOverride = (tempSsr: boolean | 'data-only') => {\n if (tempSsr === true && parentMatch?.ssr === 'data-only') {\n return 'data-only'\n }\n return tempSsr\n }\n\n const defaultSsr = inner.router.options.defaultSsr ?? true\n\n if (route.options.ssr === undefined) {\n existingMatch.ssr = parentOverride(defaultSsr)\n return\n }\n\n if (typeof route.options.ssr !== 'function') {\n existingMatch.ssr = parentOverride(route.options.ssr)\n return\n }\n const { search, params } = existingMatch\n\n const ssrFnContext: SsrContextOptions<any, any, any> = {\n search: makeMaybe(search, existingMatch.searchError),\n params: makeMaybe(params, existingMatch.paramsError),\n location: inner.location,\n matches: inner.matches.map((match) => ({\n index: match.index,\n pathname: match.pathname,\n fullPath: match.fullPath,\n staticData: match.staticData,\n id: match.id,\n routeId: match.routeId,\n search: makeMaybe(match.search, match.searchError),\n params: makeMaybe(match.params, match.paramsError),\n ssr: match.ssr,\n })),\n }\n\n const tempSsr = route.options.ssr(ssrFnContext)\n if (isPromise(tempSsr)) {\n return tempSsr.then((ssr) => {\n existingMatch.ssr = parentOverride(ssr ?? defaultSsr)\n })\n }\n\n existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr)\n return\n}\n\nconst setupPendingTimeout = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n match: AnyRouteMatch,\n): void => {\n if (match._nonReactive.pendingTimeout !== undefined) return\n\n const pendingMs =\n route.options.pendingMs ?? inner.router.options.defaultPendingMs\n const shouldPending = !!(\n inner.onReady &&\n !inner.router.isServer &&\n !resolvePreload(inner, matchId) &&\n (route.options.loader ||\n route.options.beforeLoad ||\n routeNeedsPreload(route)) &&\n typeof pendingMs === 'number' &&\n pendingMs !== Infinity &&\n (route.options.pendingComponent ??\n (inner.router.options as any)?.defaultPendingComponent)\n )\n\n if (shouldPending) {\n const pendingTimeout = setTimeout(() => {\n // Update the match and prematurely resolve the loadMatches promise so that\n // the pending component can start rendering\n triggerOnReady(inner)\n }, pendingMs)\n match._nonReactive.pendingTimeout = pendingTimeout\n }\n}\n\nconst shouldExecuteBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): boolean | Promise<boolean> => {\n const existingMatch = inner.router.getMatch(matchId)!\n\n // If we are in the middle of a load, either of these will be present\n // (not to be confused with `loadPromise`, which is always defined)\n if (\n !existingMatch._nonReactive.beforeLoadPromise &&\n !existingMatch._nonReactive.loaderPromise\n )\n return true\n\n setupPendingTimeout(inner, matchId, route, existingMatch)\n\n const then = () => {\n let result = true\n const match = inner.router.getMatch(matchId)!\n if (match.status === 'error') {\n result = true\n } else if (\n match.preload &&\n (match.status === 'redirected' || match.status === 'notFound')\n ) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n return result\n }\n\n // Wait for the beforeLoad to resolve before we continue\n return existingMatch._nonReactive.beforeLoadPromise\n ? existingMatch._nonReactive.beforeLoadPromise.then(then)\n : then()\n}\n\nconst executeBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const match = inner.router.getMatch(matchId)!\n\n // explicitly capture the previous loadPromise\n const prevLoadPromise = match._nonReactive.loadPromise\n match._nonReactive.loadPromise = createControlledPromise<void>(() => {\n prevLoadPromise?.resolve()\n })\n\n const { paramsError, searchError } = match\n\n if (paramsError) {\n handleSerialError(inner, index, paramsError, 'PARSE_PARAMS')\n }\n\n if (searchError) {\n handleSerialError(inner, index, searchError, 'VALIDATE_SEARCH')\n }\n\n setupPendingTimeout(inner, matchId, route, match)\n\n const abortController = new AbortController()\n\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n const parentMatchContext =\n parentMatch?.context ?? inner.router.options.context ?? undefined\n\n const context = { ...parentMatchContext, ...match.__routeContext }\n\n let isPending = false\n const pending = () => {\n if (isPending) return\n isPending = true\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'beforeLoad',\n fetchCount: prev.fetchCount + 1,\n abortController,\n context,\n }))\n }\n\n const resolve = () => {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: false,\n }))\n }\n\n // if there is no `beforeLoad` option, skip everything, batch update the store, return early\n if (!route.options.beforeLoad) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n\n match._nonReactive.beforeLoadPromise = createControlledPromise<void>()\n\n const { search, params, cause } = match\n const preload = resolvePreload(inner, matchId)\n const beforeLoadFnContext: BeforeLoadContextOptions<any, any, any, any, any> =\n {\n search,\n abortController,\n params,\n preload,\n context,\n location: inner.location,\n navigate: (opts: any) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n buildLocation: inner.router.buildLocation,\n cause: preload ? 'preload' : cause,\n matches: inner.matches,\n }\n\n const updateContext = (beforeLoadContext: any) => {\n if (beforeLoadContext === undefined) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {\n pending()\n handleSerialError(inner, index, beforeLoadContext, 'BEFORE_LOAD')\n }\n\n batch(() => {\n pending()\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n __beforeLoadContext: beforeLoadContext,\n context: {\n ...prev.context,\n ...beforeLoadContext,\n },\n }))\n resolve()\n })\n }\n\n let beforeLoadContext\n try {\n beforeLoadContext = route.options.beforeLoad(beforeLoadFnContext)\n if (isPromise(beforeLoadContext)) {\n pending()\n return beforeLoadContext\n .catch((err) => {\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n })\n .then(updateContext)\n }\n } catch (err) {\n pending()\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n }\n\n updateContext(beforeLoadContext)\n return\n}\n\nconst handleBeforeLoad = (\n inner: InnerLoadContext,\n index: number,\n): void | Promise<void> => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n const serverSsr = () => {\n // on the server, determine whether SSR the current match or not\n if (inner.router.isServer) {\n const maybePromise = isBeforeLoadSsr(inner, matchId, index, route)\n if (isPromise(maybePromise)) return maybePromise.then(queueExecution)\n }\n return queueExecution()\n }\n\n const queueExecution = () => {\n if (shouldSkipLoader(inner, matchId)) return\n const shouldExecuteBeforeLoadResult = shouldExecuteBeforeLoad(\n inner,\n matchId,\n route,\n )\n return isPromise(shouldExecuteBeforeLoadResult)\n ? shouldExecuteBeforeLoadResult.then(execute)\n : execute(shouldExecuteBeforeLoadResult)\n }\n\n const execute = (shouldExec: boolean) => {\n if (shouldExec) {\n // If we are not in the middle of a load OR the previous load failed, start it\n return executeBeforeLoad(inner, matchId, index, route)\n }\n return\n }\n\n return serverSsr()\n}\n\nconst executeHead = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<\n Pick<\n AnyRouteMatch,\n 'meta' | 'links' | 'headScripts' | 'headers' | 'scripts' | 'styles'\n >\n> => {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (!match) {\n return\n }\n if (!route.options.head && !route.options.scripts && !route.options.headers) {\n return\n }\n const assetContext = {\n matches: inner.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n\n return Promise.all([\n route.options.head?.(assetContext),\n route.options.scripts?.(assetContext),\n route.options.headers?.(assetContext),\n ]).then(([headFnContent, scripts, headers]) => {\n const meta = headFnContent?.meta\n const links = headFnContent?.links\n const headScripts = headFnContent?.scripts\n const styles = headFnContent?.styles\n\n return {\n meta,\n links,\n headScripts,\n headers,\n scripts,\n styles,\n }\n })\n}\n\nconst getLoaderContext = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): LoaderFnContext => {\n const parentMatchPromise = inner.matchPromises[index - 1] as any\n const { params, loaderDeps, abortController, context, cause } =\n inner.router.getMatch(matchId)!\n\n const preload = resolvePreload(inner, matchId)\n\n return {\n params,\n deps: loaderDeps,\n preload: !!preload,\n parentMatchPromise,\n abortController,\n context,\n location: inner.location,\n navigate: (opts) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n cause: preload ? 'preload' : cause,\n route,\n }\n}\n\nconst runLoader = async (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): Promise<void> => {\n try {\n // If the Matches component rendered\n // the pending component and needs to show it for\n // a minimum duration, we''ll wait for it to resolve\n // before committing to the match and resolving\n // the loadPromise\n\n const match = inner.router.getMatch(matchId)!\n\n // Actually run the loader and handle the result\n try {\n if (!inner.router.isServer || match.ssr === true) {\n loadRouteChunk(route)\n }\n\n // Kick off the loader!\n const loaderResult = route.options.loader?.(\n getLoaderContext(inner, matchId, index, route),\n )\n const loaderResultIsPromise =\n route.options.loader && isPromise(loaderResult)\n\n const willLoadSomething = !!(\n loaderResultIsPromise ||\n route._lazyPromise ||\n route._componentsPromise ||\n route.options.head ||\n route.options.scripts ||\n route.options.headers ||\n match._nonReactive.minPendingPromise\n )\n\n if (willLoadSomething) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'loader',\n }))\n }\n\n if (route.options.loader) {\n const loaderData = loaderResultIsPromise\n ? await loaderResult\n : loaderResult\n\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n loaderData,\n )\n if (loaderData !== undefined) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n loaderData,\n }))\n }\n }\n\n // Lazy option can modify the route options,\n // so we need to wait for it to resolve before\n // we can use the options\n if (route._lazyPromise) await route._lazyPromise\n const headResult = executeHead(inner, matchId, route)\n const head = headResult ? await headResult : undefined\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n // Last but not least, wait for the the components\n // to be preloaded before we resolve the match\n if (route._componentsPromise) await route._componentsPromise\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error: undefined,\n status: 'success',\n isFetching: false,\n updatedAt: Date.now(),\n ...head,\n }))\n } catch (e) {\n let error = e\n\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), e)\n\n try {\n route.options.onError?.(e)\n } catch (onErrorError) {\n error = onErrorError\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n onErrorError,\n )\n }\n const headResult = executeHead(inner, matchId, route)\n const head = headResult ? await headResult : undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error,\n status: 'error',\n isFetching: false,\n ...head,\n }))\n }\n } catch (err) {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n match._nonReactive.loaderPromise = undefined\n }\n handleRedirectAndNotFound(inner, match, err)\n }\n}\n\nconst loadRouteMatch = async (\n inner: InnerLoadContext,\n index: number,\n): Promise<AnyRouteMatch> => {\n const { id: matchId, routeId } = inner.matches[index]!\n let loaderShouldRunAsync = false\n let loaderIsRunningAsync = false\n const route = inner.router.looseRoutesById[routeId]!\n\n if (shouldSkipLoader(inner, matchId)) {\n if (inner.router.isServer) {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n return inner.router.getMatch(matchId)!\n }\n } else {\n const prevMatch = inner.router.getMatch(matchId)!\n // there is a loaderPromise, so we are in the middle of a load\n if (prevMatch._nonReactive.loaderPromise) {\n // do not block if we already have stale data we can show\n // but only if the ongoing load is not a preload since error handling is different for preloads\n // and we don't want to swallow errors\n if (prevMatch.status === 'success' && !inner.sync && !prevMatch.preload) {\n return prevMatch\n }\n await prevMatch._nonReactive.loaderPromise\n const match = inner.router.getMatch(matchId)!\n if (match.error) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n } else {\n // This is where all of the stale-while-revalidate magic happens\n const age = Date.now() - prevMatch.updatedAt\n\n const preload = resolvePreload(inner, matchId)\n\n const staleAge = preload\n ? (route.options.preloadStaleTime ??\n inner.router.options.defaultPreloadStaleTime ??\n 30_000) // 30 seconds for preloads by default\n : (route.options.staleTime ??\n inner.router.options.defaultStaleTime ??\n 0)\n\n const shouldReloadOption = route.options.shouldReload\n\n // Default to reloading the route all the time\n // Allow shouldReload to get the last say,\n // if provided.\n const shouldReload =\n typeof shouldReloadOption === 'function'\n ? shouldReloadOption(getLoaderContext(inner, matchId, index, route))\n : shouldReloadOption\n\n const nextPreload =\n !!preload && !inner.router.state.matches.some((d) => d.id === matchId)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise = createControlledPromise<void>()\n if (nextPreload !== match.preload) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n preload: nextPreload,\n }))\n }\n\n // If the route is successful and still fresh, just resolve\n const { status, invalid } = match\n loaderShouldRunAsync =\n status === 'success' && (invalid || (shouldReload ?? age > staleAge))\n if (preload && route.options.preload === false) {\n // Do nothing\n } else if (loaderShouldRunAsync && !inner.sync) {\n loaderIsRunningAsync = true\n ;(async () => {\n try {\n await runLoader(inner, matchId, index, route)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n match._nonReactive.loaderPromise = undefined\n } catch (err) {\n if (isRedirect(err)) {\n await inner.router.navigate(err.options)\n }\n }\n })()\n } else if (status !== 'success' || (loaderShouldRunAsync && inner.sync)) {\n await runLoader(inner, matchId, index, route)\n } else {\n // if the loader did not run, still update head.\n // reason: parent's beforeLoad may have changed the route context\n // and only now do we know the route context (and that the loader would not run)\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n }\n }\n }\n const match = inner.router.getMatch(matchId)!\n if (!loaderIsRunningAsync) {\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n }\n\n clearTimeout(match._nonReactive.pendingTimeout)\n match._nonReactive.pendingTimeout = undefined\n if (!loaderIsRunningAsync) match._nonReactive.loaderPromise = undefined\n match._nonReactive.dehydrated = undefined\n const nextIsFetching = loaderIsRunningAsync ? match.isFetching : false\n if (nextIsFetching !== match.isFetching || match.invalid !== false) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: nextIsFetching,\n invalid: false,\n }))\n return inner.router.getMatch(matchId)!\n } else {\n return match\n }\n}\n\nexport async function loadMatches(arg: {\n router: AnyRouter\n location: ParsedLocation\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n updateMatch: UpdateMatchFn\n sync?: boolean\n}): Promise<Array<MakeRouteMatch>> {\n const inner: InnerLoadContext = Object.assign(arg, {\n matchPromises: [],\n })\n\n // make sure the pending component is immediately rendered when hydrating a match that is not SSRed\n // the pending component was already rendered on the server and we want to keep it shown on the client until minPendingMs is reached\n if (\n !inner.router.isServer &&\n inner.router.state.matches.some((d) => d._forcePending)\n ) {\n triggerOnReady(inner)\n }\n\n try {\n // Execute all beforeLoads one by one\n for (let i = 0; i < inner.matches.length; i++) {\n const beforeLoad = handleBeforeLoad(inner, i)\n if (isPromise(beforeLoad)) await beforeLoad\n }\n\n // Execute all loaders in parallel\n const max = inner.firstBadMatchIndex ?? inner.matches.length\n for (let i = 0; i < max; i++) {\n inner.matchPromises.push(loadRouteMatch(inner, i))\n }\n await Promise.all(inner.matchPromises)\n\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n } catch (err) {\n if (isNotFound(err) && !inner.preload) {\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n throw err\n }\n if (isRedirect(err)) {\n throw err\n }\n }\n\n return inner.matches\n}\n\nexport async function loadRouteChunk(route: AnyRoute) {\n if (!route._lazyLoaded && route._lazyPromise === undefined) {\n if (route.lazyFn) {\n route._lazyPromise = route.lazyFn().then((lazyRoute) => {\n // explicitly don't copy over the lazy route's id\n const { id: _id, ...options } = lazyRoute.options\n Object.assign(route.options, options)\n route._lazyLoaded = true\n route._lazyPromise = undefined // gc promise, we won't need it anymore\n })\n } else {\n route._lazyLoaded = true\n }\n }\n\n // If for some reason lazy resolves more lazy components...\n // We'll wait for that before we attempt to preload the\n // components themselves.\n if (!route._componentsLoaded && route._componentsPromise === undefined) {\n const loadComponents = () => {\n const preloads = []\n for (const type of componentTypes) {\n const preload = (route.options[type] as any)?.preload\n if (preload) preloads.push(preload())\n }\n if (preloads.length)\n return Promise.all(preloads).then(() => {\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n })\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n return\n }\n route._componentsPromise = route._lazyPromise\n ? route._lazyPromise.then(loadComponents)\n : loadComponents()\n }\n return route._componentsPromise\n}\n\nfunction makeMaybe<TValue, TError>(\n value: TValue,\n error: TError,\n): { status: 'success'; value: TValue } | { status: 'error'; error: TError } {\n if (error) {\n return { status: 'error' as const, error }\n }\n return { status: 'success' as const, value }\n}\n\nexport function routeNeedsPreload(route: AnyRoute) {\n for (const componentType of componentTypes) {\n if ((route.options[componentType] as any)?.preload) {\n return true\n }\n }\n return false\n}\n\nexport const componentTypes = [\n 'component',\n 'errorComponent',\n 'pendingComponent',\n 'notFoundComponent',\n] as const\n"],"names":["isRedirect","isNotFound","_a","_b","rootRouteId","tempSsr","isPromise","createControlledPromise","batch","beforeLoadContext","match"],"mappings":";;;;;;;;AAuCA,MAAM,iBAAiB,CAAC,UAAkD;;AACpE,MAAA,CAAC,MAAM,UAAU;AACnB,UAAM,WAAW;AACjB,YAAO,WAAM,YAAN;AAAA,EAAgB;AAE3B;AAEA,MAAM,iBAAiB,CAAC,OAAyB,YAA6B;AAC5E,SAAO,CAAC,EACN,MAAM,WAAW,CAAC,MAAM,OAAO,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO;AAE7E;AAEA,MAAM,kBAAkB,CAAC,OAAyB,QAAuB;;AAGjE,QAAA,cACJ,MAAM,OAAO,WAAW,IAAI,WAAW,EAAE,KAAK,MAAM,OAAO;AAG7D,MACE,CAAC,YAAY,QAAQ,uBACpB,WAAM,OAAO,YAAb,mBAA8B,2BAC/B;AACA,gBAAY,QAAQ,oBAClB,MAAM,OAAO,QACb;AAAA,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W,QAAQ,gBAAgB;AACjC,cAAM,WAAW,WAAM,QAAQ,IAAI,MAAlB,mBAA6B;AAC9C,YAAI,QAAS,UAAS,KAAK,QAAA,CAAS;AAAA,MAAA;AAEtC,UAAI,SAAS;AACX,eAAO,QAAQ,IAAI,QAAQ,EAAE,KAAK,MAAM;AACtC,gBAAM,oBAAoB;AAC1B,gBAAM,qBAAqB;AAAA,QAAA,CAC5B;AACH,YAAM,oBAAoB;AAC1B,YAAM,qBAAqB;AAC3B;AAAA,IACF;AACM,UAAA,qBAAqB,MAAM,eAC7B,MAAM,aAAa,KAAK,cAAc,IACtC,eAAe;AAAA,EAAA;AAErB,SAAO,MAAM;AACf;AAEA,SAAS,UACP,OACA,OAC2E;AAC3E,MAAI,OAAO;AACF,WAAA,EAAE,QAAQ,SAAkB,MAAM;AAAA,EAAA;AAEpC,SAAA,EAAE,QAAQ,WAAoB,MAAM;AAC7C;AAEO,SAAS,kBAAkB,OAAiB;;AACjD,aAAW,iBAAiB,gBAAgB;AAC1C,SAAK,WAAM,QAAQ,aAAa,MAA3B,mBAAsC,SAAS;AAC3C,aAAA;AAAA,IAAA;AAAA,EACT;AAEK,SAAA;AACT;AAEO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;;;"}
|
package/dist/cjs/router.cjs
CHANGED
|
@@ -249,10 +249,10 @@ class RouterCore {
|
|
|
249
249
|
dest.from,
|
|
250
250
|
void 0
|
|
251
251
|
).matchedRoutes;
|
|
252
|
-
const matchedFrom =
|
|
252
|
+
const matchedFrom = utils.findLast(allCurrentLocationMatches, (d) => {
|
|
253
253
|
return comparePaths(d.fullPath, fromPath);
|
|
254
254
|
});
|
|
255
|
-
const matchedCurrent =
|
|
255
|
+
const matchedCurrent = utils.findLast(allFromMatches, (d) => {
|
|
256
256
|
return comparePaths(d.fullPath, currentLocation.pathname);
|
|
257
257
|
});
|
|
258
258
|
if (!matchedFrom && !matchedCurrent) {
|