@tanstack/react-router 1.92.13 → 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 +22 -10
- 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 +22 -10
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +29 -10
package/dist/cjs/router.d.cts
CHANGED
|
@@ -554,20 +554,24 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
554
554
|
buildAndCommitLocation: ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, href, ...rest }?: BuildNextOptions & CommitLocationOptions) => Promise<void>;
|
|
555
555
|
navigate: NavigateFn;
|
|
556
556
|
latestLoadPromise: undefined | Promise<void>;
|
|
557
|
-
load: (
|
|
557
|
+
load: (opts?: {
|
|
558
|
+
sync?: boolean;
|
|
559
|
+
}) => Promise<void>;
|
|
558
560
|
startViewTransition: (fn: () => Promise<void>) => void;
|
|
559
561
|
updateMatch: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => AnyRouteMatch;
|
|
560
562
|
getMatch: (matchId: string) => import('./Matches.cjs').RouteMatch<any, any, any, any, any, any, any> | undefined;
|
|
561
|
-
loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, }: {
|
|
563
|
+
loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, sync, }: {
|
|
562
564
|
location: ParsedLocation;
|
|
563
565
|
matches: Array<AnyRouteMatch>;
|
|
564
566
|
preload?: boolean;
|
|
565
567
|
onReady?: () => Promise<void>;
|
|
566
568
|
updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
|
|
567
569
|
getMatch?: (matchId: string) => AnyRouteMatch | undefined;
|
|
570
|
+
sync?: boolean;
|
|
568
571
|
}) => Promise<Array<MakeRouteMatch>>;
|
|
569
572
|
invalidate: <TRouter extends AnyRouter = this>(opts?: {
|
|
570
573
|
filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean;
|
|
574
|
+
sync?: boolean;
|
|
571
575
|
}) => Promise<void>;
|
|
572
576
|
resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
|
|
573
577
|
clearCache: <TRouter extends AnyRouter = this>(opts?: {
|
package/dist/esm/router.d.ts
CHANGED
|
@@ -554,20 +554,24 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
554
554
|
buildAndCommitLocation: ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, href, ...rest }?: BuildNextOptions & CommitLocationOptions) => Promise<void>;
|
|
555
555
|
navigate: NavigateFn;
|
|
556
556
|
latestLoadPromise: undefined | Promise<void>;
|
|
557
|
-
load: (
|
|
557
|
+
load: (opts?: {
|
|
558
|
+
sync?: boolean;
|
|
559
|
+
}) => Promise<void>;
|
|
558
560
|
startViewTransition: (fn: () => Promise<void>) => void;
|
|
559
561
|
updateMatch: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => AnyRouteMatch;
|
|
560
562
|
getMatch: (matchId: string) => import('./Matches.js').RouteMatch<any, any, any, any, any, any, any> | undefined;
|
|
561
|
-
loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, }: {
|
|
563
|
+
loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, sync, }: {
|
|
562
564
|
location: ParsedLocation;
|
|
563
565
|
matches: Array<AnyRouteMatch>;
|
|
564
566
|
preload?: boolean;
|
|
565
567
|
onReady?: () => Promise<void>;
|
|
566
568
|
updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
|
|
567
569
|
getMatch?: (matchId: string) => AnyRouteMatch | undefined;
|
|
570
|
+
sync?: boolean;
|
|
568
571
|
}) => Promise<Array<MakeRouteMatch>>;
|
|
569
572
|
invalidate: <TRouter extends AnyRouter = this>(opts?: {
|
|
570
573
|
filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean;
|
|
574
|
+
sync?: boolean;
|
|
571
575
|
}) => Promise<void>;
|
|
572
576
|
resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
|
|
573
577
|
clearCache: <TRouter extends AnyRouter = this>(opts?: {
|
package/dist/esm/router.js
CHANGED
|
@@ -615,7 +615,7 @@ class Router {
|
|
|
615
615
|
to
|
|
616
616
|
});
|
|
617
617
|
};
|
|
618
|
-
this.load = async () => {
|
|
618
|
+
this.load = async (opts) => {
|
|
619
619
|
this.latestLocation = this.parseLocation(this.latestLocation);
|
|
620
620
|
let redirect;
|
|
621
621
|
let notFound;
|
|
@@ -661,6 +661,7 @@ class Router {
|
|
|
661
661
|
hrefChanged
|
|
662
662
|
});
|
|
663
663
|
await this.loadMatches({
|
|
664
|
+
sync: opts == null ? void 0 : opts.sync,
|
|
664
665
|
matches: pendingMatches,
|
|
665
666
|
location: next,
|
|
666
667
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -792,7 +793,8 @@ class Router {
|
|
|
792
793
|
matches,
|
|
793
794
|
preload: allPreload,
|
|
794
795
|
onReady,
|
|
795
|
-
updateMatch = this.updateMatch
|
|
796
|
+
updateMatch = this.updateMatch,
|
|
797
|
+
sync
|
|
796
798
|
}) => {
|
|
797
799
|
let firstBadMatchIndex;
|
|
798
800
|
let rendered = false;
|
|
@@ -1001,7 +1003,8 @@ class Router {
|
|
|
1001
1003
|
matchPromises.push(
|
|
1002
1004
|
(async () => {
|
|
1003
1005
|
const { loaderPromise: prevLoaderPromise } = this.getMatch(matchId);
|
|
1004
|
-
let
|
|
1006
|
+
let loaderShouldRunAsync = false;
|
|
1007
|
+
let loaderIsRunningAsync = false;
|
|
1005
1008
|
if (prevLoaderPromise) {
|
|
1006
1009
|
await prevLoaderPromise;
|
|
1007
1010
|
} else {
|
|
@@ -1125,30 +1128,39 @@ class Router {
|
|
|
1125
1128
|
}
|
|
1126
1129
|
};
|
|
1127
1130
|
const { status, invalid } = this.getMatch(matchId);
|
|
1128
|
-
|
|
1131
|
+
loaderShouldRunAsync = status === "success" && (invalid || (shouldReload ?? age > staleAge));
|
|
1129
1132
|
if (preload && route.options.preload === false) {
|
|
1130
|
-
} else if (
|
|
1131
|
-
;
|
|
1133
|
+
} else if (loaderShouldRunAsync && !sync) {
|
|
1134
|
+
loaderIsRunningAsync = true;
|
|
1132
1135
|
(async () => {
|
|
1133
1136
|
try {
|
|
1134
1137
|
await runLoader();
|
|
1138
|
+
const { loaderPromise, loadPromise } = this.getMatch(matchId);
|
|
1139
|
+
loaderPromise == null ? void 0 : loaderPromise.resolve();
|
|
1140
|
+
loadPromise == null ? void 0 : loadPromise.resolve();
|
|
1141
|
+
updateMatch(matchId, (prev) => ({
|
|
1142
|
+
...prev,
|
|
1143
|
+
loaderPromise: void 0
|
|
1144
|
+
}));
|
|
1135
1145
|
} catch (err) {
|
|
1136
1146
|
if (isResolvedRedirect(err)) {
|
|
1137
1147
|
await this.navigate(err);
|
|
1138
1148
|
}
|
|
1139
1149
|
}
|
|
1140
1150
|
})();
|
|
1141
|
-
} else if (status !== "success") {
|
|
1151
|
+
} else if (status !== "success" || loaderShouldRunAsync && sync) {
|
|
1142
1152
|
await runLoader();
|
|
1143
1153
|
}
|
|
1154
|
+
}
|
|
1155
|
+
if (!loaderIsRunningAsync) {
|
|
1144
1156
|
const { loaderPromise, loadPromise } = this.getMatch(matchId);
|
|
1145
1157
|
loaderPromise == null ? void 0 : loaderPromise.resolve();
|
|
1146
1158
|
loadPromise == null ? void 0 : loadPromise.resolve();
|
|
1147
1159
|
}
|
|
1148
1160
|
updateMatch(matchId, (prev) => ({
|
|
1149
1161
|
...prev,
|
|
1150
|
-
isFetching:
|
|
1151
|
-
loaderPromise: void 0,
|
|
1162
|
+
isFetching: loaderIsRunningAsync ? prev.isFetching : false,
|
|
1163
|
+
loaderPromise: loaderIsRunningAsync ? prev.loaderPromise : void 0,
|
|
1152
1164
|
invalid: false
|
|
1153
1165
|
}));
|
|
1154
1166
|
return this.getMatch(matchId);
|
|
@@ -1194,7 +1206,7 @@ class Router {
|
|
|
1194
1206
|
pendingMatches: (_a = s.pendingMatches) == null ? void 0 : _a.map(invalidate)
|
|
1195
1207
|
};
|
|
1196
1208
|
});
|
|
1197
|
-
return this.load();
|
|
1209
|
+
return this.load({ sync: opts == null ? void 0 : opts.sync });
|
|
1198
1210
|
};
|
|
1199
1211
|
this.resolveRedirect = (err) => {
|
|
1200
1212
|
const redirect = err;
|