@tanstack/router-core 1.131.16 → 1.131.18
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 +130 -108
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/router.js +130 -108
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +137 -114
package/dist/cjs/router.cjs
CHANGED
|
@@ -861,10 +861,7 @@ class RouterCore {
|
|
|
861
861
|
const match = this.getMatch(matchId);
|
|
862
862
|
if (shouldPending && match._nonReactive.pendingTimeout === void 0) {
|
|
863
863
|
const pendingTimeout = setTimeout(() => {
|
|
864
|
-
|
|
865
|
-
this.triggerOnReady(innerLoadContext);
|
|
866
|
-
} catch {
|
|
867
|
-
}
|
|
864
|
+
this.triggerOnReady(innerLoadContext);
|
|
868
865
|
}, pendingMs);
|
|
869
866
|
match._nonReactive.pendingTimeout = pendingTimeout;
|
|
870
867
|
}
|
|
@@ -887,103 +884,122 @@ class RouterCore {
|
|
|
887
884
|
return existingMatch._nonReactive.beforeLoadPromise ? existingMatch._nonReactive.beforeLoadPromise.then(then) : then();
|
|
888
885
|
};
|
|
889
886
|
this.executeBeforeLoad = (innerLoadContext, matchId, index, route) => {
|
|
890
|
-
var _a
|
|
887
|
+
var _a;
|
|
888
|
+
const match = this.getMatch(matchId);
|
|
889
|
+
match._nonReactive.beforeLoadPromise = utils.createControlledPromise();
|
|
890
|
+
const prevLoadPromise = match._nonReactive.loadPromise;
|
|
891
|
+
match._nonReactive.loadPromise = utils.createControlledPromise(() => {
|
|
892
|
+
prevLoadPromise == null ? void 0 : prevLoadPromise.resolve();
|
|
893
|
+
});
|
|
894
|
+
const { paramsError, searchError } = match;
|
|
895
|
+
if (paramsError) {
|
|
896
|
+
this.handleSerialError(
|
|
897
|
+
innerLoadContext,
|
|
898
|
+
index,
|
|
899
|
+
paramsError,
|
|
900
|
+
"PARSE_PARAMS"
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
if (searchError) {
|
|
904
|
+
this.handleSerialError(
|
|
905
|
+
innerLoadContext,
|
|
906
|
+
index,
|
|
907
|
+
searchError,
|
|
908
|
+
"VALIDATE_SEARCH"
|
|
909
|
+
);
|
|
910
|
+
}
|
|
911
|
+
this.setupPendingTimeout(innerLoadContext, matchId, route);
|
|
912
|
+
const abortController = new AbortController();
|
|
913
|
+
const parentMatchId = (_a = innerLoadContext.matches[index - 1]) == null ? void 0 : _a.id;
|
|
914
|
+
const parentMatch = parentMatchId ? this.getMatch(parentMatchId) : void 0;
|
|
915
|
+
const parentMatchContext = (parentMatch == null ? void 0 : parentMatch.context) ?? this.options.context ?? void 0;
|
|
916
|
+
const context = { ...parentMatchContext, ...match.__routeContext };
|
|
917
|
+
let isPending = false;
|
|
918
|
+
const pending = () => {
|
|
919
|
+
if (isPending) return;
|
|
920
|
+
isPending = true;
|
|
921
|
+
innerLoadContext.updateMatch(matchId, (prev) => ({
|
|
922
|
+
...prev,
|
|
923
|
+
isFetching: "beforeLoad",
|
|
924
|
+
fetchCount: prev.fetchCount + 1,
|
|
925
|
+
abortController,
|
|
926
|
+
context
|
|
927
|
+
}));
|
|
928
|
+
};
|
|
891
929
|
const resolve = () => {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
};
|
|
900
|
-
});
|
|
930
|
+
var _a2;
|
|
931
|
+
(_a2 = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a2.resolve();
|
|
932
|
+
match._nonReactive.beforeLoadPromise = void 0;
|
|
933
|
+
innerLoadContext.updateMatch(matchId, (prev) => ({
|
|
934
|
+
...prev,
|
|
935
|
+
isFetching: false
|
|
936
|
+
}));
|
|
901
937
|
};
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
match._nonReactive.loadPromise = utils.createControlledPromise(() => {
|
|
907
|
-
prevLoadPromise == null ? void 0 : prevLoadPromise.resolve();
|
|
938
|
+
if (!route.options.beforeLoad) {
|
|
939
|
+
store.batch(() => {
|
|
940
|
+
pending();
|
|
941
|
+
resolve();
|
|
908
942
|
});
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
const { search, params, cause } = match;
|
|
946
|
+
const preload = this.resolvePreload(innerLoadContext, matchId);
|
|
947
|
+
const beforeLoadFnContext = {
|
|
948
|
+
search,
|
|
949
|
+
abortController,
|
|
950
|
+
params,
|
|
951
|
+
preload,
|
|
952
|
+
context,
|
|
953
|
+
location: innerLoadContext.location,
|
|
954
|
+
navigate: (opts) => this.navigate({ ...opts, _fromLocation: innerLoadContext.location }),
|
|
955
|
+
buildLocation: this.buildLocation,
|
|
956
|
+
cause: preload ? "preload" : cause,
|
|
957
|
+
matches: innerLoadContext.matches
|
|
958
|
+
};
|
|
959
|
+
const updateContext = (beforeLoadContext2) => {
|
|
960
|
+
if (beforeLoadContext2 === void 0) {
|
|
961
|
+
store.batch(() => {
|
|
962
|
+
pending();
|
|
963
|
+
resolve();
|
|
964
|
+
});
|
|
965
|
+
return;
|
|
917
966
|
}
|
|
918
|
-
if (
|
|
967
|
+
if (redirect.isRedirect(beforeLoadContext2) || notFound.isNotFound(beforeLoadContext2)) {
|
|
968
|
+
pending();
|
|
919
969
|
this.handleSerialError(
|
|
920
970
|
innerLoadContext,
|
|
921
971
|
index,
|
|
922
|
-
|
|
923
|
-
"
|
|
972
|
+
beforeLoadContext2,
|
|
973
|
+
"BEFORE_LOAD"
|
|
924
974
|
);
|
|
925
975
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
const parentMatchId = (_a = innerLoadContext.matches[index - 1]) == null ? void 0 : _a.id;
|
|
929
|
-
const parentMatch = parentMatchId ? this.getMatch(parentMatchId) : void 0;
|
|
930
|
-
const parentMatchContext = (parentMatch == null ? void 0 : parentMatch.context) ?? this.options.context ?? void 0;
|
|
931
|
-
innerLoadContext.updateMatch(matchId, (prev) => ({
|
|
932
|
-
...prev,
|
|
933
|
-
isFetching: "beforeLoad",
|
|
934
|
-
fetchCount: prev.fetchCount + 1,
|
|
935
|
-
abortController,
|
|
936
|
-
context: {
|
|
937
|
-
...parentMatchContext,
|
|
938
|
-
...prev.__routeContext
|
|
939
|
-
}
|
|
940
|
-
}));
|
|
941
|
-
const { search, params, context, cause } = this.getMatch(matchId);
|
|
942
|
-
const preload = this.resolvePreload(innerLoadContext, matchId);
|
|
943
|
-
const beforeLoadFnContext = {
|
|
944
|
-
search,
|
|
945
|
-
abortController,
|
|
946
|
-
params,
|
|
947
|
-
preload,
|
|
948
|
-
context,
|
|
949
|
-
location: innerLoadContext.location,
|
|
950
|
-
navigate: (opts) => this.navigate({ ...opts, _fromLocation: innerLoadContext.location }),
|
|
951
|
-
buildLocation: this.buildLocation,
|
|
952
|
-
cause: preload ? "preload" : cause,
|
|
953
|
-
matches: innerLoadContext.matches
|
|
954
|
-
};
|
|
955
|
-
const updateContext = (beforeLoadContext2) => {
|
|
956
|
-
if (redirect.isRedirect(beforeLoadContext2) || notFound.isNotFound(beforeLoadContext2)) {
|
|
957
|
-
this.handleSerialError(
|
|
958
|
-
innerLoadContext,
|
|
959
|
-
index,
|
|
960
|
-
beforeLoadContext2,
|
|
961
|
-
"BEFORE_LOAD"
|
|
962
|
-
);
|
|
963
|
-
}
|
|
976
|
+
store.batch(() => {
|
|
977
|
+
pending();
|
|
964
978
|
innerLoadContext.updateMatch(matchId, (prev) => ({
|
|
965
979
|
...prev,
|
|
966
980
|
__beforeLoadContext: beforeLoadContext2,
|
|
967
981
|
context: {
|
|
968
|
-
...
|
|
969
|
-
...prev.__routeContext,
|
|
982
|
+
...prev.context,
|
|
970
983
|
...beforeLoadContext2
|
|
971
|
-
}
|
|
972
|
-
abortController
|
|
984
|
+
}
|
|
973
985
|
}));
|
|
974
|
-
|
|
975
|
-
|
|
986
|
+
resolve();
|
|
987
|
+
});
|
|
988
|
+
};
|
|
989
|
+
let beforeLoadContext;
|
|
990
|
+
try {
|
|
991
|
+
beforeLoadContext = route.options.beforeLoad(beforeLoadFnContext);
|
|
976
992
|
if (utils.isPromise(beforeLoadContext)) {
|
|
977
|
-
|
|
993
|
+
pending();
|
|
994
|
+
return beforeLoadContext.catch((err) => {
|
|
978
995
|
this.handleSerialError(innerLoadContext, index, err, "BEFORE_LOAD");
|
|
979
|
-
}).then(
|
|
980
|
-
} else {
|
|
981
|
-
updateContext(beforeLoadContext);
|
|
996
|
+
}).then(updateContext);
|
|
982
997
|
}
|
|
983
998
|
} catch (err) {
|
|
999
|
+
pending();
|
|
984
1000
|
this.handleSerialError(innerLoadContext, index, err, "BEFORE_LOAD");
|
|
985
1001
|
}
|
|
986
|
-
|
|
1002
|
+
updateContext(beforeLoadContext);
|
|
987
1003
|
return;
|
|
988
1004
|
};
|
|
989
1005
|
this.handleBeforeLoad = (innerLoadContext, index) => {
|
|
@@ -1099,10 +1115,12 @@ class RouterCore {
|
|
|
1099
1115
|
this.getMatch(matchId),
|
|
1100
1116
|
loaderData
|
|
1101
1117
|
);
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1118
|
+
if (loaderData !== void 0) {
|
|
1119
|
+
innerLoadContext.updateMatch(matchId, (prev) => ({
|
|
1120
|
+
...prev,
|
|
1121
|
+
loaderData
|
|
1122
|
+
}));
|
|
1123
|
+
}
|
|
1106
1124
|
}
|
|
1107
1125
|
if (route._lazyPromise) await route._lazyPromise;
|
|
1108
1126
|
const headResult = this.executeHead(innerLoadContext, matchId, route);
|
|
@@ -1120,7 +1138,8 @@ class RouterCore {
|
|
|
1120
1138
|
}));
|
|
1121
1139
|
} catch (e) {
|
|
1122
1140
|
let error = e;
|
|
1123
|
-
|
|
1141
|
+
const pendingPromise = this.potentialPendingMinPromise(matchId);
|
|
1142
|
+
if (pendingPromise) await pendingPromise;
|
|
1124
1143
|
this.handleRedirectAndNotFound(
|
|
1125
1144
|
innerLoadContext,
|
|
1126
1145
|
this.getMatch(matchId),
|
|
@@ -1186,9 +1205,9 @@ class RouterCore {
|
|
|
1186
1205
|
return this.getMatch(matchId);
|
|
1187
1206
|
}
|
|
1188
1207
|
await prevMatch._nonReactive.loaderPromise;
|
|
1189
|
-
const
|
|
1190
|
-
if (
|
|
1191
|
-
this.handleRedirectAndNotFound(innerLoadContext,
|
|
1208
|
+
const match2 = this.getMatch(matchId);
|
|
1209
|
+
if (match2.error) {
|
|
1210
|
+
this.handleRedirectAndNotFound(innerLoadContext, match2, match2.error);
|
|
1192
1211
|
}
|
|
1193
1212
|
} else {
|
|
1194
1213
|
const age = Date.now() - this.getMatch(matchId).updatedAt;
|
|
@@ -1198,13 +1217,15 @@ class RouterCore {
|
|
|
1198
1217
|
const shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(
|
|
1199
1218
|
this.getLoaderContext(innerLoadContext, matchId, index, route)
|
|
1200
1219
|
) : shouldReloadOption;
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1220
|
+
const nextPreload = !!preload && !this.state.matches.some((d) => d.id === matchId);
|
|
1221
|
+
const match2 = this.getMatch(matchId);
|
|
1222
|
+
match2._nonReactive.loaderPromise = utils.createControlledPromise();
|
|
1223
|
+
if (nextPreload !== match2.preload) {
|
|
1224
|
+
innerLoadContext.updateMatch(matchId, (prev) => ({
|
|
1204
1225
|
...prev,
|
|
1205
|
-
preload:
|
|
1206
|
-
};
|
|
1207
|
-
}
|
|
1226
|
+
preload: nextPreload
|
|
1227
|
+
}));
|
|
1228
|
+
}
|
|
1208
1229
|
const { status, invalid } = this.getMatch(matchId);
|
|
1209
1230
|
loaderShouldRunAsync = status === "success" && (invalid || (shouldReload ?? age > staleAge));
|
|
1210
1231
|
if (preload && route.options.preload === false) ;
|
|
@@ -1214,10 +1235,10 @@ class RouterCore {
|
|
|
1214
1235
|
var _a2, _b2;
|
|
1215
1236
|
try {
|
|
1216
1237
|
await this.runLoader(innerLoadContext, matchId, index, route);
|
|
1217
|
-
const
|
|
1218
|
-
(_a2 =
|
|
1219
|
-
(_b2 =
|
|
1220
|
-
|
|
1238
|
+
const match3 = this.getMatch(matchId);
|
|
1239
|
+
(_a2 = match3._nonReactive.loaderPromise) == null ? void 0 : _a2.resolve();
|
|
1240
|
+
(_b2 = match3._nonReactive.loadPromise) == null ? void 0 : _b2.resolve();
|
|
1241
|
+
match3._nonReactive.loaderPromise = void 0;
|
|
1221
1242
|
} catch (err) {
|
|
1222
1243
|
if (redirect.isRedirect(err)) {
|
|
1223
1244
|
await this.navigate(err.options);
|
|
@@ -1237,22 +1258,23 @@ class RouterCore {
|
|
|
1237
1258
|
}
|
|
1238
1259
|
}
|
|
1239
1260
|
}
|
|
1261
|
+
const match = this.getMatch(matchId);
|
|
1240
1262
|
if (!loaderIsRunningAsync) {
|
|
1241
|
-
const match = this.getMatch(matchId);
|
|
1242
1263
|
(_a = match._nonReactive.loaderPromise) == null ? void 0 : _a.resolve();
|
|
1243
1264
|
(_b = match._nonReactive.loadPromise) == null ? void 0 : _b.resolve();
|
|
1244
1265
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1266
|
+
clearTimeout(match._nonReactive.pendingTimeout);
|
|
1267
|
+
match._nonReactive.pendingTimeout = void 0;
|
|
1268
|
+
if (!loaderIsRunningAsync) match._nonReactive.loaderPromise = void 0;
|
|
1269
|
+
match._nonReactive.dehydrated = void 0;
|
|
1270
|
+
const nextIsFetching = loaderIsRunningAsync ? match.isFetching : false;
|
|
1271
|
+
if (nextIsFetching !== match.isFetching || match.invalid !== false) {
|
|
1272
|
+
innerLoadContext.updateMatch(matchId, (prev) => ({
|
|
1251
1273
|
...prev,
|
|
1252
|
-
isFetching:
|
|
1274
|
+
isFetching: nextIsFetching,
|
|
1253
1275
|
invalid: false
|
|
1254
|
-
};
|
|
1255
|
-
}
|
|
1276
|
+
}));
|
|
1277
|
+
}
|
|
1256
1278
|
return this.getMatch(matchId);
|
|
1257
1279
|
};
|
|
1258
1280
|
this.loadMatches = async (baseContext) => {
|