@tanstack/router-core 1.131.12 → 1.131.14
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/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +0 -4
- package/dist/cjs/router.cjs +81 -75
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +2 -4
- package/dist/cjs/utils.cjs +6 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +1 -0
- package/dist/esm/route.d.ts +0 -4
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +2 -4
- package/dist/esm/router.js +82 -76
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js +6 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/route.ts +10 -2
- package/src/router.ts +113 -91
- package/src/utils.ts +10 -0
package/dist/esm/router.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Store, batch } from "@tanstack/store";
|
|
2
2
|
import { createMemoryHistory, createBrowserHistory, parseHref } from "@tanstack/history";
|
|
3
3
|
import invariant from "tiny-invariant";
|
|
4
|
-
import { pick, createControlledPromise, deepEqual, replaceEqualDeep, last, functionalUpdate } from "./utils.js";
|
|
4
|
+
import { pick, createControlledPromise, isPromise, deepEqual, replaceEqualDeep, last, functionalUpdate } from "./utils.js";
|
|
5
5
|
import { trimPath, resolvePath, cleanPath, matchPathname, trimPathRight, interpolatePath, joinPaths, trimPathLeft, parsePathname, SEGMENT_TYPE_PARAM, SEGMENT_TYPE_OPTIONAL_PARAM, SEGMENT_TYPE_WILDCARD, SEGMENT_TYPE_PATHNAME } from "./path.js";
|
|
6
6
|
import { isNotFound } from "./not-found.js";
|
|
7
7
|
import { setupScrollRestoration } from "./scroll-restoration.js";
|
|
@@ -727,42 +727,36 @@ class RouterCore {
|
|
|
727
727
|
}
|
|
728
728
|
const handleRedirectAndNotFound = (match, err) => {
|
|
729
729
|
var _a, _b, _c;
|
|
730
|
-
if (isRedirect(err)
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
}));
|
|
749
|
-
if (!err.routeId) {
|
|
750
|
-
err.routeId = match.routeId;
|
|
751
|
-
}
|
|
752
|
-
(_c = match._nonReactive.loadPromise) == null ? void 0 : _c.resolve();
|
|
753
|
-
}
|
|
754
|
-
if (isRedirect(err)) {
|
|
755
|
-
rendered = true;
|
|
756
|
-
err.options._fromLocation = location;
|
|
757
|
-
err.redirectHandled = true;
|
|
758
|
-
err = this.resolveRedirect(err);
|
|
759
|
-
throw err;
|
|
760
|
-
} else if (isNotFound(err)) {
|
|
761
|
-
this._handleNotFound(matches, err, {
|
|
762
|
-
updateMatch
|
|
763
|
-
});
|
|
764
|
-
throw err;
|
|
730
|
+
if (!isRedirect(err) && !isNotFound(err)) return;
|
|
731
|
+
if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {
|
|
732
|
+
throw err;
|
|
733
|
+
}
|
|
734
|
+
if (match) {
|
|
735
|
+
(_a = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a.resolve();
|
|
736
|
+
(_b = match._nonReactive.loaderPromise) == null ? void 0 : _b.resolve();
|
|
737
|
+
match._nonReactive.beforeLoadPromise = void 0;
|
|
738
|
+
match._nonReactive.loaderPromise = void 0;
|
|
739
|
+
const status = isRedirect(err) ? "redirected" : "notFound";
|
|
740
|
+
updateMatch(match.id, (prev) => ({
|
|
741
|
+
...prev,
|
|
742
|
+
status,
|
|
743
|
+
isFetching: false,
|
|
744
|
+
error: err
|
|
745
|
+
}));
|
|
746
|
+
if (isNotFound(err) && !err.routeId) {
|
|
747
|
+
err.routeId = match.routeId;
|
|
765
748
|
}
|
|
749
|
+
(_c = match._nonReactive.loadPromise) == null ? void 0 : _c.resolve();
|
|
750
|
+
}
|
|
751
|
+
if (isRedirect(err)) {
|
|
752
|
+
rendered = true;
|
|
753
|
+
err.options._fromLocation = location;
|
|
754
|
+
err.redirectHandled = true;
|
|
755
|
+
err = this.resolveRedirect(err);
|
|
756
|
+
throw err;
|
|
757
|
+
} else {
|
|
758
|
+
this._handleNotFound(matches, err, updateMatch);
|
|
759
|
+
throw err;
|
|
766
760
|
}
|
|
767
761
|
};
|
|
768
762
|
const shouldSkipLoader = (matchId) => {
|
|
@@ -1015,11 +1009,9 @@ class RouterCore {
|
|
|
1015
1009
|
};
|
|
1016
1010
|
});
|
|
1017
1011
|
};
|
|
1018
|
-
const potentialPendingMinPromise =
|
|
1012
|
+
const potentialPendingMinPromise = () => {
|
|
1019
1013
|
const latestMatch = this.getMatch(matchId);
|
|
1020
|
-
|
|
1021
|
-
await latestMatch._nonReactive.minPendingPromise;
|
|
1022
|
-
}
|
|
1014
|
+
return latestMatch._nonReactive.minPendingPromise;
|
|
1023
1015
|
};
|
|
1024
1016
|
const prevMatch = this.getMatch(matchId);
|
|
1025
1017
|
if (shouldSkipLoader(matchId)) {
|
|
@@ -1083,27 +1075,36 @@ class RouterCore {
|
|
|
1083
1075
|
var _a3, _b3, _c2, _d2;
|
|
1084
1076
|
try {
|
|
1085
1077
|
try {
|
|
1086
|
-
if (!this.isServer || this.
|
|
1078
|
+
if (!this.isServer || this.getMatch(matchId).ssr === true) {
|
|
1087
1079
|
this.loadRouteChunk(route);
|
|
1088
1080
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1081
|
+
const loaderResult = (_b3 = (_a3 = route.options).loader) == null ? void 0 : _b3.call(_a3, getLoaderContext());
|
|
1082
|
+
const loaderResultIsPromise = route.options.loader && isPromise(loaderResult);
|
|
1083
|
+
const willLoadSomething = !!(loaderResultIsPromise || route._lazyPromise || route._componentsPromise || route.options.head || route.options.scripts || route.options.headers || this.getMatch(matchId)._nonReactive.minPendingPromise);
|
|
1084
|
+
if (willLoadSomething) {
|
|
1085
|
+
updateMatch(matchId, (prev) => ({
|
|
1086
|
+
...prev,
|
|
1087
|
+
isFetching: "loader"
|
|
1088
|
+
}));
|
|
1089
|
+
}
|
|
1090
|
+
if (route.options.loader) {
|
|
1091
|
+
const loaderData = loaderResultIsPromise ? await loaderResult : loaderResult;
|
|
1092
|
+
handleRedirectAndNotFound(
|
|
1093
|
+
this.getMatch(matchId),
|
|
1094
|
+
loaderData
|
|
1095
|
+
);
|
|
1096
|
+
updateMatch(matchId, (prev) => ({
|
|
1097
|
+
...prev,
|
|
1098
|
+
loaderData
|
|
1099
|
+
}));
|
|
1100
|
+
}
|
|
1101
|
+
if (route._lazyPromise) await route._lazyPromise;
|
|
1103
1102
|
const headResult = executeHead();
|
|
1104
1103
|
const head = headResult ? await headResult : void 0;
|
|
1105
|
-
|
|
1106
|
-
await
|
|
1104
|
+
const pendingPromise = potentialPendingMinPromise();
|
|
1105
|
+
if (pendingPromise) await pendingPromise;
|
|
1106
|
+
if (route._componentsPromise)
|
|
1107
|
+
await route._componentsPromise;
|
|
1107
1108
|
updateMatch(matchId, (prev) => ({
|
|
1108
1109
|
...prev,
|
|
1109
1110
|
error: void 0,
|
|
@@ -1291,27 +1292,36 @@ class RouterCore {
|
|
|
1291
1292
|
this.clearCache({ filter });
|
|
1292
1293
|
};
|
|
1293
1294
|
this.loadRouteChunk = (route) => {
|
|
1294
|
-
if (route._lazyPromise === void 0) {
|
|
1295
|
+
if (!route._lazyLoaded && route._lazyPromise === void 0) {
|
|
1295
1296
|
if (route.lazyFn) {
|
|
1296
1297
|
route._lazyPromise = route.lazyFn().then((lazyRoute) => {
|
|
1297
1298
|
const { id: _id, ...options2 } = lazyRoute.options;
|
|
1298
1299
|
Object.assign(route.options, options2);
|
|
1300
|
+
route._lazyLoaded = true;
|
|
1301
|
+
route._lazyPromise = void 0;
|
|
1299
1302
|
});
|
|
1300
1303
|
} else {
|
|
1301
|
-
route.
|
|
1304
|
+
route._lazyLoaded = true;
|
|
1302
1305
|
}
|
|
1303
1306
|
}
|
|
1304
|
-
if (route._componentsPromise === void 0) {
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1307
|
+
if (!route._componentsLoaded && route._componentsPromise === void 0) {
|
|
1308
|
+
const loadComponents = () => {
|
|
1309
|
+
var _a;
|
|
1310
|
+
const preloads = [];
|
|
1311
|
+
for (const type of componentTypes) {
|
|
1312
|
+
const preload = (_a = route.options[type]) == null ? void 0 : _a.preload;
|
|
1313
|
+
if (preload) preloads.push(preload());
|
|
1314
|
+
}
|
|
1315
|
+
if (preloads.length)
|
|
1316
|
+
return Promise.all(preloads).then(() => {
|
|
1317
|
+
route._componentsLoaded = true;
|
|
1318
|
+
route._componentsPromise = void 0;
|
|
1319
|
+
});
|
|
1320
|
+
route._componentsLoaded = true;
|
|
1321
|
+
route._componentsPromise = void 0;
|
|
1322
|
+
return;
|
|
1323
|
+
};
|
|
1324
|
+
route._componentsPromise = route._lazyPromise ? route._lazyPromise.then(loadComponents) : loadComponents();
|
|
1315
1325
|
}
|
|
1316
1326
|
return route._componentsPromise;
|
|
1317
1327
|
};
|
|
@@ -1409,9 +1419,7 @@ class RouterCore {
|
|
|
1409
1419
|
}
|
|
1410
1420
|
return match;
|
|
1411
1421
|
};
|
|
1412
|
-
this._handleNotFound = (matches, err, {
|
|
1413
|
-
updateMatch = this.updateMatch
|
|
1414
|
-
} = {}) => {
|
|
1422
|
+
this._handleNotFound = (matches, err, updateMatch = this.updateMatch) => {
|
|
1415
1423
|
var _a;
|
|
1416
1424
|
const routeCursor = this.routesById[err.routeId ?? ""] ?? this.routeTree;
|
|
1417
1425
|
const matchesByRouteId = {};
|
|
@@ -1438,9 +1446,7 @@ class RouterCore {
|
|
|
1438
1446
|
}));
|
|
1439
1447
|
if (err.routerCode === "BEFORE_LOAD" && routeCursor.parentRoute) {
|
|
1440
1448
|
err.routeId = routeCursor.parentRoute.id;
|
|
1441
|
-
this._handleNotFound(matches, err,
|
|
1442
|
-
updateMatch
|
|
1443
|
-
});
|
|
1449
|
+
this._handleNotFound(matches, err, updateMatch);
|
|
1444
1450
|
}
|
|
1445
1451
|
};
|
|
1446
1452
|
this.hasNotFoundMatch = () => {
|