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