@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.cjs
CHANGED
|
@@ -219,8 +219,8 @@ class RouterCore {
|
|
|
219
219
|
const match = this.getMatch(id);
|
|
220
220
|
if (!match) return;
|
|
221
221
|
match.abortController.abort();
|
|
222
|
-
match._nonReactive.pendingTimeout = void 0;
|
|
223
222
|
clearTimeout(match._nonReactive.pendingTimeout);
|
|
223
|
+
match._nonReactive.pendingTimeout = void 0;
|
|
224
224
|
};
|
|
225
225
|
this.cancelMatches = () => {
|
|
226
226
|
var _a;
|
|
@@ -729,40 +729,36 @@ class RouterCore {
|
|
|
729
729
|
}
|
|
730
730
|
const handleRedirectAndNotFound = (match, err) => {
|
|
731
731
|
var _a, _b, _c;
|
|
732
|
-
if (redirect.isRedirect(err)
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}
|
|
732
|
+
if (!redirect.isRedirect(err) && !notFound.isNotFound(err)) return;
|
|
733
|
+
if (redirect.isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {
|
|
734
|
+
throw err;
|
|
735
|
+
}
|
|
736
|
+
if (match) {
|
|
740
737
|
(_a = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a.resolve();
|
|
741
738
|
(_b = match._nonReactive.loaderPromise) == null ? void 0 : _b.resolve();
|
|
742
739
|
match._nonReactive.beforeLoadPromise = void 0;
|
|
743
740
|
match._nonReactive.loaderPromise = void 0;
|
|
741
|
+
const status = redirect.isRedirect(err) ? "redirected" : "notFound";
|
|
744
742
|
updateMatch(match.id, (prev) => ({
|
|
745
743
|
...prev,
|
|
746
|
-
status
|
|
744
|
+
status,
|
|
747
745
|
isFetching: false,
|
|
748
746
|
error: err
|
|
749
747
|
}));
|
|
750
|
-
if (!err.routeId) {
|
|
748
|
+
if (notFound.isNotFound(err) && !err.routeId) {
|
|
751
749
|
err.routeId = match.routeId;
|
|
752
750
|
}
|
|
753
751
|
(_c = match._nonReactive.loadPromise) == null ? void 0 : _c.resolve();
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
throw err;
|
|
765
|
-
}
|
|
752
|
+
}
|
|
753
|
+
if (redirect.isRedirect(err)) {
|
|
754
|
+
rendered = true;
|
|
755
|
+
err.options._fromLocation = location;
|
|
756
|
+
err.redirectHandled = true;
|
|
757
|
+
err = this.resolveRedirect(err);
|
|
758
|
+
throw err;
|
|
759
|
+
} else {
|
|
760
|
+
this._handleNotFound(matches, err, updateMatch);
|
|
761
|
+
throw err;
|
|
766
762
|
}
|
|
767
763
|
};
|
|
768
764
|
const shouldSkipLoader = (matchId) => {
|
|
@@ -981,33 +977,39 @@ class RouterCore {
|
|
|
981
977
|
let loaderShouldRunAsync = false;
|
|
982
978
|
let loaderIsRunningAsync = false;
|
|
983
979
|
const route = this.looseRoutesById[routeId];
|
|
984
|
-
const executeHead =
|
|
980
|
+
const executeHead = () => {
|
|
985
981
|
var _a3, _b3, _c2, _d2, _e, _f;
|
|
986
982
|
const match = this.getMatch(matchId);
|
|
987
983
|
if (!match) {
|
|
988
984
|
return;
|
|
989
985
|
}
|
|
986
|
+
if (!route.options.head && !route.options.scripts && !route.options.headers) {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
990
989
|
const assetContext = {
|
|
991
990
|
matches,
|
|
992
991
|
match,
|
|
993
992
|
params: match.params,
|
|
994
993
|
loaderData: match.loaderData
|
|
995
994
|
};
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
995
|
+
return Promise.all([
|
|
996
|
+
(_b3 = (_a3 = route.options).head) == null ? void 0 : _b3.call(_a3, assetContext),
|
|
997
|
+
(_d2 = (_c2 = route.options).scripts) == null ? void 0 : _d2.call(_c2, assetContext),
|
|
998
|
+
(_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, assetContext)
|
|
999
|
+
]).then(([headFnContent, scripts, headers]) => {
|
|
1000
|
+
const meta = headFnContent == null ? void 0 : headFnContent.meta;
|
|
1001
|
+
const links = headFnContent == null ? void 0 : headFnContent.links;
|
|
1002
|
+
const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
|
|
1003
|
+
const styles = headFnContent == null ? void 0 : headFnContent.styles;
|
|
1004
|
+
return {
|
|
1005
|
+
meta,
|
|
1006
|
+
links,
|
|
1007
|
+
headScripts,
|
|
1008
|
+
headers,
|
|
1009
|
+
scripts,
|
|
1010
|
+
styles
|
|
1011
|
+
};
|
|
1012
|
+
});
|
|
1011
1013
|
};
|
|
1012
1014
|
const potentialPendingMinPromise = async () => {
|
|
1013
1015
|
const latestMatch = this.getMatch(matchId);
|
|
@@ -1018,11 +1020,14 @@ class RouterCore {
|
|
|
1018
1020
|
const prevMatch = this.getMatch(matchId);
|
|
1019
1021
|
if (shouldSkipLoader(matchId)) {
|
|
1020
1022
|
if (this.isServer) {
|
|
1021
|
-
const
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1023
|
+
const headResult = executeHead();
|
|
1024
|
+
if (headResult) {
|
|
1025
|
+
const head = await headResult;
|
|
1026
|
+
updateMatch(matchId, (prev) => ({
|
|
1027
|
+
...prev,
|
|
1028
|
+
...head
|
|
1029
|
+
}));
|
|
1030
|
+
}
|
|
1026
1031
|
return this.getMatch(matchId);
|
|
1027
1032
|
}
|
|
1028
1033
|
} else if (prevMatch._nonReactive.loaderPromise) {
|
|
@@ -1091,7 +1096,8 @@ class RouterCore {
|
|
|
1091
1096
|
loaderData
|
|
1092
1097
|
}));
|
|
1093
1098
|
await route._lazyPromise;
|
|
1094
|
-
const
|
|
1099
|
+
const headResult = executeHead();
|
|
1100
|
+
const head = headResult ? await headResult : void 0;
|
|
1095
1101
|
await potentialPendingMinPromise();
|
|
1096
1102
|
await route._componentsPromise;
|
|
1097
1103
|
updateMatch(matchId, (prev) => ({
|
|
@@ -1115,7 +1121,8 @@ class RouterCore {
|
|
|
1115
1121
|
onErrorError
|
|
1116
1122
|
);
|
|
1117
1123
|
}
|
|
1118
|
-
const
|
|
1124
|
+
const headResult = executeHead();
|
|
1125
|
+
const head = headResult ? await headResult : void 0;
|
|
1119
1126
|
updateMatch(matchId, (prev) => ({
|
|
1120
1127
|
...prev,
|
|
1121
1128
|
error,
|
|
@@ -1125,15 +1132,19 @@ class RouterCore {
|
|
|
1125
1132
|
}));
|
|
1126
1133
|
}
|
|
1127
1134
|
} catch (err) {
|
|
1128
|
-
const
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1135
|
+
const match = this.getMatch(matchId);
|
|
1136
|
+
if (match) {
|
|
1137
|
+
const headResult = executeHead();
|
|
1138
|
+
if (headResult) {
|
|
1139
|
+
const head = await headResult;
|
|
1140
|
+
updateMatch(matchId, (prev) => ({
|
|
1141
|
+
...prev,
|
|
1142
|
+
...head
|
|
1143
|
+
}));
|
|
1144
|
+
}
|
|
1145
|
+
match._nonReactive.loaderPromise = void 0;
|
|
1146
|
+
}
|
|
1147
|
+
handleRedirectAndNotFound(match, err);
|
|
1137
1148
|
}
|
|
1138
1149
|
};
|
|
1139
1150
|
const { status, invalid } = this.getMatch(matchId);
|
|
@@ -1158,11 +1169,14 @@ class RouterCore {
|
|
|
1158
1169
|
} else if (status !== "success" || loaderShouldRunAsync && sync) {
|
|
1159
1170
|
await runLoader();
|
|
1160
1171
|
} else {
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1172
|
+
const headResult = executeHead();
|
|
1173
|
+
if (headResult) {
|
|
1174
|
+
const head = await headResult;
|
|
1175
|
+
updateMatch(matchId, (prev) => ({
|
|
1176
|
+
...prev,
|
|
1177
|
+
...head
|
|
1178
|
+
}));
|
|
1179
|
+
}
|
|
1166
1180
|
}
|
|
1167
1181
|
}
|
|
1168
1182
|
if (!loaderIsRunningAsync) {
|
|
@@ -1391,9 +1405,7 @@ class RouterCore {
|
|
|
1391
1405
|
}
|
|
1392
1406
|
return match;
|
|
1393
1407
|
};
|
|
1394
|
-
this._handleNotFound = (matches, err, {
|
|
1395
|
-
updateMatch = this.updateMatch
|
|
1396
|
-
} = {}) => {
|
|
1408
|
+
this._handleNotFound = (matches, err, updateMatch = this.updateMatch) => {
|
|
1397
1409
|
var _a;
|
|
1398
1410
|
const routeCursor = this.routesById[err.routeId ?? ""] ?? this.routeTree;
|
|
1399
1411
|
const matchesByRouteId = {};
|
|
@@ -1420,9 +1432,7 @@ class RouterCore {
|
|
|
1420
1432
|
}));
|
|
1421
1433
|
if (err.routerCode === "BEFORE_LOAD" && routeCursor.parentRoute) {
|
|
1422
1434
|
err.routeId = routeCursor.parentRoute.id;
|
|
1423
|
-
this._handleNotFound(matches, err,
|
|
1424
|
-
updateMatch
|
|
1425
|
-
});
|
|
1435
|
+
this._handleNotFound(matches, err, updateMatch);
|
|
1426
1436
|
}
|
|
1427
1437
|
};
|
|
1428
1438
|
this.hasNotFoundMatch = () => {
|