@tanstack/react-router 1.92.11 → 1.93.0
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 +23 -12
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +6 -2
- package/dist/esm/router.d.ts +6 -2
- package/dist/esm/router.js +23 -12
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +29 -11
package/dist/cjs/router.cjs
CHANGED
|
@@ -617,7 +617,7 @@ class Router {
|
|
|
617
617
|
to
|
|
618
618
|
});
|
|
619
619
|
};
|
|
620
|
-
this.load = async () => {
|
|
620
|
+
this.load = async (opts) => {
|
|
621
621
|
this.latestLocation = this.parseLocation(this.latestLocation);
|
|
622
622
|
let redirect;
|
|
623
623
|
let notFound$1;
|
|
@@ -663,6 +663,7 @@ class Router {
|
|
|
663
663
|
hrefChanged
|
|
664
664
|
});
|
|
665
665
|
await this.loadMatches({
|
|
666
|
+
sync: opts == null ? void 0 : opts.sync,
|
|
666
667
|
matches: pendingMatches,
|
|
667
668
|
location: next,
|
|
668
669
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -794,7 +795,8 @@ class Router {
|
|
|
794
795
|
matches,
|
|
795
796
|
preload: allPreload,
|
|
796
797
|
onReady,
|
|
797
|
-
updateMatch = this.updateMatch
|
|
798
|
+
updateMatch = this.updateMatch,
|
|
799
|
+
sync
|
|
798
800
|
}) => {
|
|
799
801
|
let firstBadMatchIndex;
|
|
800
802
|
let rendered = false;
|
|
@@ -940,8 +942,7 @@ class Router {
|
|
|
940
942
|
pendingTimeout,
|
|
941
943
|
context: {
|
|
942
944
|
...getParentMatchContext(),
|
|
943
|
-
...prev.__routeContext
|
|
944
|
-
...prev.__beforeLoadContext
|
|
945
|
+
...prev.__routeContext
|
|
945
946
|
}
|
|
946
947
|
}));
|
|
947
948
|
const { search, params, context, cause } = this.getMatch(matchId);
|
|
@@ -1004,7 +1005,8 @@ class Router {
|
|
|
1004
1005
|
matchPromises.push(
|
|
1005
1006
|
(async () => {
|
|
1006
1007
|
const { loaderPromise: prevLoaderPromise } = this.getMatch(matchId);
|
|
1007
|
-
let
|
|
1008
|
+
let loaderShouldRunAsync = false;
|
|
1009
|
+
let loaderIsRunningAsync = false;
|
|
1008
1010
|
if (prevLoaderPromise) {
|
|
1009
1011
|
await prevLoaderPromise;
|
|
1010
1012
|
} else {
|
|
@@ -1128,30 +1130,39 @@ class Router {
|
|
|
1128
1130
|
}
|
|
1129
1131
|
};
|
|
1130
1132
|
const { status, invalid } = this.getMatch(matchId);
|
|
1131
|
-
|
|
1133
|
+
loaderShouldRunAsync = status === "success" && (invalid || (shouldReload ?? age > staleAge));
|
|
1132
1134
|
if (preload && route.options.preload === false) {
|
|
1133
|
-
} else if (
|
|
1134
|
-
;
|
|
1135
|
+
} else if (loaderShouldRunAsync && !sync) {
|
|
1136
|
+
loaderIsRunningAsync = true;
|
|
1135
1137
|
(async () => {
|
|
1136
1138
|
try {
|
|
1137
1139
|
await runLoader();
|
|
1140
|
+
const { loaderPromise, loadPromise } = this.getMatch(matchId);
|
|
1141
|
+
loaderPromise == null ? void 0 : loaderPromise.resolve();
|
|
1142
|
+
loadPromise == null ? void 0 : loadPromise.resolve();
|
|
1143
|
+
updateMatch(matchId, (prev) => ({
|
|
1144
|
+
...prev,
|
|
1145
|
+
loaderPromise: void 0
|
|
1146
|
+
}));
|
|
1138
1147
|
} catch (err) {
|
|
1139
1148
|
if (redirects.isResolvedRedirect(err)) {
|
|
1140
1149
|
await this.navigate(err);
|
|
1141
1150
|
}
|
|
1142
1151
|
}
|
|
1143
1152
|
})();
|
|
1144
|
-
} else if (status !== "success") {
|
|
1153
|
+
} else if (status !== "success" || loaderShouldRunAsync && sync) {
|
|
1145
1154
|
await runLoader();
|
|
1146
1155
|
}
|
|
1156
|
+
}
|
|
1157
|
+
if (!loaderIsRunningAsync) {
|
|
1147
1158
|
const { loaderPromise, loadPromise } = this.getMatch(matchId);
|
|
1148
1159
|
loaderPromise == null ? void 0 : loaderPromise.resolve();
|
|
1149
1160
|
loadPromise == null ? void 0 : loadPromise.resolve();
|
|
1150
1161
|
}
|
|
1151
1162
|
updateMatch(matchId, (prev) => ({
|
|
1152
1163
|
...prev,
|
|
1153
|
-
isFetching:
|
|
1154
|
-
loaderPromise: void 0,
|
|
1164
|
+
isFetching: loaderIsRunningAsync ? prev.isFetching : false,
|
|
1165
|
+
loaderPromise: loaderIsRunningAsync ? prev.loaderPromise : void 0,
|
|
1155
1166
|
invalid: false
|
|
1156
1167
|
}));
|
|
1157
1168
|
return this.getMatch(matchId);
|
|
@@ -1197,7 +1208,7 @@ class Router {
|
|
|
1197
1208
|
pendingMatches: (_a = s.pendingMatches) == null ? void 0 : _a.map(invalidate)
|
|
1198
1209
|
};
|
|
1199
1210
|
});
|
|
1200
|
-
return this.load();
|
|
1211
|
+
return this.load({ sync: opts == null ? void 0 : opts.sync });
|
|
1201
1212
|
};
|
|
1202
1213
|
this.resolveRedirect = (err) => {
|
|
1203
1214
|
const redirect = err;
|