@tanstack/router-core 1.131.7 → 1.131.13
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 +76 -66
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -3
- package/dist/esm/router.d.ts +1 -3
- package/dist/esm/router.js +76 -66
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +102 -84
package/dist/cjs/router.d.cts
CHANGED
|
@@ -549,9 +549,7 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
|
|
|
549
549
|
manifest: Manifest | undefined;
|
|
550
550
|
};
|
|
551
551
|
serverSsr?: ServerSsr;
|
|
552
|
-
_handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError,
|
|
553
|
-
updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
|
|
554
|
-
}) => void;
|
|
552
|
+
_handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError, updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void) => void;
|
|
555
553
|
hasNotFoundMatch: () => boolean;
|
|
556
554
|
}
|
|
557
555
|
export declare class SearchParamError extends Error {
|
package/dist/esm/router.d.ts
CHANGED
|
@@ -549,9 +549,7 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
|
|
|
549
549
|
manifest: Manifest | undefined;
|
|
550
550
|
};
|
|
551
551
|
serverSsr?: ServerSsr;
|
|
552
|
-
_handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError,
|
|
553
|
-
updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
|
|
554
|
-
}) => void;
|
|
552
|
+
_handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError, updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void) => void;
|
|
555
553
|
hasNotFoundMatch: () => boolean;
|
|
556
554
|
}
|
|
557
555
|
export declare class SearchParamError extends Error {
|
package/dist/esm/router.js
CHANGED
|
@@ -217,8 +217,8 @@ class RouterCore {
|
|
|
217
217
|
const match = this.getMatch(id);
|
|
218
218
|
if (!match) return;
|
|
219
219
|
match.abortController.abort();
|
|
220
|
-
match._nonReactive.pendingTimeout = void 0;
|
|
221
220
|
clearTimeout(match._nonReactive.pendingTimeout);
|
|
221
|
+
match._nonReactive.pendingTimeout = void 0;
|
|
222
222
|
};
|
|
223
223
|
this.cancelMatches = () => {
|
|
224
224
|
var _a;
|
|
@@ -727,40 +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
|
-
}
|
|
730
|
+
if (!isRedirect(err) && !isNotFound(err)) return;
|
|
731
|
+
if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {
|
|
732
|
+
throw err;
|
|
733
|
+
}
|
|
734
|
+
if (match) {
|
|
738
735
|
(_a = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a.resolve();
|
|
739
736
|
(_b = match._nonReactive.loaderPromise) == null ? void 0 : _b.resolve();
|
|
740
737
|
match._nonReactive.beforeLoadPromise = void 0;
|
|
741
738
|
match._nonReactive.loaderPromise = void 0;
|
|
739
|
+
const status = isRedirect(err) ? "redirected" : "notFound";
|
|
742
740
|
updateMatch(match.id, (prev) => ({
|
|
743
741
|
...prev,
|
|
744
|
-
status
|
|
742
|
+
status,
|
|
745
743
|
isFetching: false,
|
|
746
744
|
error: err
|
|
747
745
|
}));
|
|
748
|
-
if (!err.routeId) {
|
|
746
|
+
if (isNotFound(err) && !err.routeId) {
|
|
749
747
|
err.routeId = match.routeId;
|
|
750
748
|
}
|
|
751
749
|
(_c = match._nonReactive.loadPromise) == null ? void 0 : _c.resolve();
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
throw err;
|
|
763
|
-
}
|
|
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;
|
|
764
760
|
}
|
|
765
761
|
};
|
|
766
762
|
const shouldSkipLoader = (matchId) => {
|
|
@@ -979,33 +975,39 @@ class RouterCore {
|
|
|
979
975
|
let loaderShouldRunAsync = false;
|
|
980
976
|
let loaderIsRunningAsync = false;
|
|
981
977
|
const route = this.looseRoutesById[routeId];
|
|
982
|
-
const executeHead =
|
|
978
|
+
const executeHead = () => {
|
|
983
979
|
var _a3, _b3, _c2, _d2, _e, _f;
|
|
984
980
|
const match = this.getMatch(matchId);
|
|
985
981
|
if (!match) {
|
|
986
982
|
return;
|
|
987
983
|
}
|
|
984
|
+
if (!route.options.head && !route.options.scripts && !route.options.headers) {
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
988
987
|
const assetContext = {
|
|
989
988
|
matches,
|
|
990
989
|
match,
|
|
991
990
|
params: match.params,
|
|
992
991
|
loaderData: match.loaderData
|
|
993
992
|
};
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
993
|
+
return Promise.all([
|
|
994
|
+
(_b3 = (_a3 = route.options).head) == null ? void 0 : _b3.call(_a3, assetContext),
|
|
995
|
+
(_d2 = (_c2 = route.options).scripts) == null ? void 0 : _d2.call(_c2, assetContext),
|
|
996
|
+
(_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, assetContext)
|
|
997
|
+
]).then(([headFnContent, scripts, headers]) => {
|
|
998
|
+
const meta = headFnContent == null ? void 0 : headFnContent.meta;
|
|
999
|
+
const links = headFnContent == null ? void 0 : headFnContent.links;
|
|
1000
|
+
const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
|
|
1001
|
+
const styles = headFnContent == null ? void 0 : headFnContent.styles;
|
|
1002
|
+
return {
|
|
1003
|
+
meta,
|
|
1004
|
+
links,
|
|
1005
|
+
headScripts,
|
|
1006
|
+
headers,
|
|
1007
|
+
scripts,
|
|
1008
|
+
styles
|
|
1009
|
+
};
|
|
1010
|
+
});
|
|
1009
1011
|
};
|
|
1010
1012
|
const potentialPendingMinPromise = async () => {
|
|
1011
1013
|
const latestMatch = this.getMatch(matchId);
|
|
@@ -1016,11 +1018,14 @@ class RouterCore {
|
|
|
1016
1018
|
const prevMatch = this.getMatch(matchId);
|
|
1017
1019
|
if (shouldSkipLoader(matchId)) {
|
|
1018
1020
|
if (this.isServer) {
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1021
|
+
const headResult = executeHead();
|
|
1022
|
+
if (headResult) {
|
|
1023
|
+
const head = await headResult;
|
|
1024
|
+
updateMatch(matchId, (prev) => ({
|
|
1025
|
+
...prev,
|
|
1026
|
+
...head
|
|
1027
|
+
}));
|
|
1028
|
+
}
|
|
1024
1029
|
return this.getMatch(matchId);
|
|
1025
1030
|
}
|
|
1026
1031
|
} else if (prevMatch._nonReactive.loaderPromise) {
|
|
@@ -1089,7 +1094,8 @@ class RouterCore {
|
|
|
1089
1094
|
loaderData
|
|
1090
1095
|
}));
|
|
1091
1096
|
await route._lazyPromise;
|
|
1092
|
-
const
|
|
1097
|
+
const headResult = executeHead();
|
|
1098
|
+
const head = headResult ? await headResult : void 0;
|
|
1093
1099
|
await potentialPendingMinPromise();
|
|
1094
1100
|
await route._componentsPromise;
|
|
1095
1101
|
updateMatch(matchId, (prev) => ({
|
|
@@ -1113,7 +1119,8 @@ class RouterCore {
|
|
|
1113
1119
|
onErrorError
|
|
1114
1120
|
);
|
|
1115
1121
|
}
|
|
1116
|
-
const
|
|
1122
|
+
const headResult = executeHead();
|
|
1123
|
+
const head = headResult ? await headResult : void 0;
|
|
1117
1124
|
updateMatch(matchId, (prev) => ({
|
|
1118
1125
|
...prev,
|
|
1119
1126
|
error,
|
|
@@ -1123,15 +1130,19 @@ class RouterCore {
|
|
|
1123
1130
|
}));
|
|
1124
1131
|
}
|
|
1125
1132
|
} catch (err) {
|
|
1126
|
-
const
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1133
|
+
const match = this.getMatch(matchId);
|
|
1134
|
+
if (match) {
|
|
1135
|
+
const headResult = executeHead();
|
|
1136
|
+
if (headResult) {
|
|
1137
|
+
const head = await headResult;
|
|
1138
|
+
updateMatch(matchId, (prev) => ({
|
|
1139
|
+
...prev,
|
|
1140
|
+
...head
|
|
1141
|
+
}));
|
|
1142
|
+
}
|
|
1143
|
+
match._nonReactive.loaderPromise = void 0;
|
|
1144
|
+
}
|
|
1145
|
+
handleRedirectAndNotFound(match, err);
|
|
1135
1146
|
}
|
|
1136
1147
|
};
|
|
1137
1148
|
const { status, invalid } = this.getMatch(matchId);
|
|
@@ -1156,11 +1167,14 @@ class RouterCore {
|
|
|
1156
1167
|
} else if (status !== "success" || loaderShouldRunAsync && sync) {
|
|
1157
1168
|
await runLoader();
|
|
1158
1169
|
} else {
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1170
|
+
const headResult = executeHead();
|
|
1171
|
+
if (headResult) {
|
|
1172
|
+
const head = await headResult;
|
|
1173
|
+
updateMatch(matchId, (prev) => ({
|
|
1174
|
+
...prev,
|
|
1175
|
+
...head
|
|
1176
|
+
}));
|
|
1177
|
+
}
|
|
1164
1178
|
}
|
|
1165
1179
|
}
|
|
1166
1180
|
if (!loaderIsRunningAsync) {
|
|
@@ -1389,9 +1403,7 @@ class RouterCore {
|
|
|
1389
1403
|
}
|
|
1390
1404
|
return match;
|
|
1391
1405
|
};
|
|
1392
|
-
this._handleNotFound = (matches, err, {
|
|
1393
|
-
updateMatch = this.updateMatch
|
|
1394
|
-
} = {}) => {
|
|
1406
|
+
this._handleNotFound = (matches, err, updateMatch = this.updateMatch) => {
|
|
1395
1407
|
var _a;
|
|
1396
1408
|
const routeCursor = this.routesById[err.routeId ?? ""] ?? this.routeTree;
|
|
1397
1409
|
const matchesByRouteId = {};
|
|
@@ -1418,9 +1430,7 @@ class RouterCore {
|
|
|
1418
1430
|
}));
|
|
1419
1431
|
if (err.routerCode === "BEFORE_LOAD" && routeCursor.parentRoute) {
|
|
1420
1432
|
err.routeId = routeCursor.parentRoute.id;
|
|
1421
|
-
this._handleNotFound(matches, err,
|
|
1422
|
-
updateMatch
|
|
1423
|
-
});
|
|
1433
|
+
this._handleNotFound(matches, err, updateMatch);
|
|
1424
1434
|
}
|
|
1425
1435
|
};
|
|
1426
1436
|
this.hasNotFoundMatch = () => {
|