@tanstack/react-router 1.30.1 → 1.31.1
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/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +10 -10
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/RouterProvider.d.cts +7 -7
- package/dist/cjs/fileRoute.d.cts +1 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +42 -42
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/redirects.d.cts +5 -6
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +6 -6
- package/dist/cjs/routeInfo.d.cts +19 -2
- package/dist/cjs/router.cjs +69 -52
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +15 -15
- package/dist/cjs/routerContext.cjs.map +1 -1
- package/dist/cjs/routerContext.d.cts +1 -1
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useNavigate.d.cts +3 -4
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/cjs/useRouter.d.cts +3 -4
- package/dist/cjs/useRouterState.cjs.map +1 -1
- package/dist/cjs/useRouterState.d.cts +3 -4
- package/dist/esm/Matches.d.ts +10 -10
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +7 -7
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +1 -1
- package/dist/esm/link.d.ts +42 -42
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/redirects.d.ts +5 -6
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +6 -6
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +19 -2
- package/dist/esm/router.d.ts +15 -15
- package/dist/esm/router.js +69 -52
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/routerContext.d.ts +1 -1
- package/dist/esm/routerContext.js.map +1 -1
- package/dist/esm/useNavigate.d.ts +3 -4
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useRouter.d.ts +3 -4
- package/dist/esm/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.d.ts +3 -4
- package/dist/esm/useRouterState.js.map +1 -1
- package/package.json +1 -1
- package/src/Matches.tsx +40 -22
- package/src/RouterProvider.tsx +34 -11
- package/src/link.tsx +124 -139
- package/src/redirects.ts +14 -14
- package/src/route.ts +3 -3
- package/src/routeInfo.ts +72 -4
- package/src/router.ts +132 -68
- package/src/routerContext.tsx +1 -1
- package/src/useNavigate.tsx +9 -10
- package/src/useRouter.tsx +4 -5
- package/src/useRouterState.tsx +5 -6
package/dist/cjs/router.cjs
CHANGED
|
@@ -30,7 +30,6 @@ class Router {
|
|
|
30
30
|
)}`;
|
|
31
31
|
this.resetNextScroll = true;
|
|
32
32
|
this.shouldViewTransition = void 0;
|
|
33
|
-
this.navigateTimeout = null;
|
|
34
33
|
this.latestLoadPromise = Promise.resolve();
|
|
35
34
|
this.subscribers = /* @__PURE__ */ new Set();
|
|
36
35
|
this.injectedHtml = [];
|
|
@@ -398,20 +397,20 @@ class Router {
|
|
|
398
397
|
};
|
|
399
398
|
this.buildLocation = (opts) => {
|
|
400
399
|
const build = (dest = {}, matches) => {
|
|
401
|
-
var _a, _b, _c
|
|
402
|
-
|
|
403
|
-
let fromSearch =
|
|
404
|
-
const fromMatches = this.matchRoutes(
|
|
400
|
+
var _a, _b, _c;
|
|
401
|
+
let fromPath = this.latestLocation.pathname;
|
|
402
|
+
let fromSearch = dest.fromSearch || this.latestLocation.search;
|
|
403
|
+
const fromMatches = this.matchRoutes(
|
|
404
|
+
this.latestLocation.pathname,
|
|
405
|
+
fromSearch
|
|
406
|
+
);
|
|
407
|
+
fromPath = ((_a = fromMatches.find((d) => d.id === dest.from)) == null ? void 0 : _a.pathname) || fromPath;
|
|
405
408
|
fromSearch = ((_b = utils.last(fromMatches)) == null ? void 0 : _b.search) || this.latestLocation.search;
|
|
406
409
|
const stayingMatches = matches == null ? void 0 : matches.filter(
|
|
407
410
|
(d) => fromMatches.find((e) => e.routeId === d.routeId)
|
|
408
411
|
);
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
dest.from ?? this.latestLocation.pathname,
|
|
412
|
-
`${dest.to}`
|
|
413
|
-
) : this.resolvePathWithBase(fromRoute == null ? void 0 : fromRoute.fullPath, fromRoute == null ? void 0 : fromRoute.fullPath);
|
|
414
|
-
const prevParams = { ...(_d = utils.last(fromMatches)) == null ? void 0 : _d.params };
|
|
412
|
+
let pathname = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, fromPath);
|
|
413
|
+
const prevParams = { ...(_c = utils.last(fromMatches)) == null ? void 0 : _c.params };
|
|
415
414
|
let nextParams = (dest.params ?? true) === true ? prevParams : { ...prevParams, ...utils.functionalUpdate(dest.params, prevParams) };
|
|
416
415
|
if (Object.keys(nextParams).length > 0) {
|
|
417
416
|
matches == null ? void 0 : matches.map((d) => this.looseRoutesById[d.routeId].options.stringifyParams).filter(Boolean).forEach((fn) => {
|
|
@@ -505,8 +504,6 @@ class Router {
|
|
|
505
504
|
viewTransition,
|
|
506
505
|
...next
|
|
507
506
|
}) => {
|
|
508
|
-
if (this.navigateTimeout)
|
|
509
|
-
clearTimeout(this.navigateTimeout);
|
|
510
507
|
const isSameUrl = this.latestLocation.href === next.href;
|
|
511
508
|
if (!isSameUrl) {
|
|
512
509
|
let { maskedLocation, ...nextHistory } = next;
|
|
@@ -620,14 +617,10 @@ class Router {
|
|
|
620
617
|
err.routeId = match.routeId;
|
|
621
618
|
}
|
|
622
619
|
if (redirects.isRedirect(err)) {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
this.navigate({ ...redirect, replace: true });
|
|
626
|
-
}
|
|
627
|
-
throw redirect;
|
|
620
|
+
err = this.resolveRedirect(err);
|
|
621
|
+
throw err;
|
|
628
622
|
} else if (notFound.isNotFound(err)) {
|
|
629
|
-
|
|
630
|
-
this.handleNotFound(matches, err);
|
|
623
|
+
this.handleNotFound(matches, err);
|
|
631
624
|
throw err;
|
|
632
625
|
}
|
|
633
626
|
}
|
|
@@ -636,6 +629,20 @@ class Router {
|
|
|
636
629
|
const parentMatch = matches[index - 1];
|
|
637
630
|
const route2 = this.looseRoutesById[match.routeId];
|
|
638
631
|
const abortController = new AbortController();
|
|
632
|
+
let loadPromise = match.loadPromise;
|
|
633
|
+
if (match.isFetching) {
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
const previousResolve = loadPromise.resolve;
|
|
637
|
+
loadPromise = utils.createControlledPromise(
|
|
638
|
+
// Resolve the old when we we resolve the new one
|
|
639
|
+
previousResolve
|
|
640
|
+
);
|
|
641
|
+
matches[index] = match = updateMatch(match.id, (prev) => ({
|
|
642
|
+
...prev,
|
|
643
|
+
isFetching: "beforeLoad",
|
|
644
|
+
loadPromise
|
|
645
|
+
}));
|
|
639
646
|
const handleSerialError = (err, routerCode) => {
|
|
640
647
|
var _a2, _b2;
|
|
641
648
|
err.routerCode = routerCode;
|
|
@@ -687,6 +694,8 @@ class Router {
|
|
|
687
694
|
buildLocation: this.buildLocation,
|
|
688
695
|
cause: preload ? "preload" : match.cause
|
|
689
696
|
})) ?? {};
|
|
697
|
+
if (latestPromise = checkLatest())
|
|
698
|
+
return latestPromise;
|
|
690
699
|
if (redirects.isRedirect(beforeLoadContext) || notFound.isNotFound(beforeLoadContext)) {
|
|
691
700
|
handleSerialError(beforeLoadContext, "BEFORE_LOAD");
|
|
692
701
|
}
|
|
@@ -710,6 +719,8 @@ class Router {
|
|
|
710
719
|
updateMatch(match.id, () => match);
|
|
711
720
|
}
|
|
712
721
|
}
|
|
722
|
+
if (latestPromise = checkLatest())
|
|
723
|
+
return latestPromise;
|
|
713
724
|
const validResolvedMatches = matches.slice(0, firstBadMatchIndex);
|
|
714
725
|
const matchPromises = [];
|
|
715
726
|
await Promise.all(
|
|
@@ -734,7 +745,6 @@ class Router {
|
|
|
734
745
|
let lazyPromise = Promise.resolve();
|
|
735
746
|
let componentsPromise = Promise.resolve();
|
|
736
747
|
let loaderPromise = existing.loaderPromise;
|
|
737
|
-
let loadPromise = existing.loadPromise;
|
|
738
748
|
const potentialPendingMinPromise = async () => {
|
|
739
749
|
const latestMatch = RouterProvider.getRouteMatch(this.state, match.id);
|
|
740
750
|
if (latestMatch == null ? void 0 : latestMatch.minPendingPromise) {
|
|
@@ -748,12 +758,15 @@ class Router {
|
|
|
748
758
|
}
|
|
749
759
|
};
|
|
750
760
|
try {
|
|
751
|
-
if (
|
|
752
|
-
matches[index] = match =
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
761
|
+
if (match.isFetching === "beforeLoad") {
|
|
762
|
+
matches[index] = match = updateMatch(
|
|
763
|
+
match.id,
|
|
764
|
+
(prev) => ({
|
|
765
|
+
...prev,
|
|
766
|
+
isFetching: "loader",
|
|
767
|
+
fetchCount: match.fetchCount + 1
|
|
768
|
+
})
|
|
769
|
+
);
|
|
757
770
|
lazyPromise = ((_a2 = route2.lazyFn) == null ? void 0 : _a2.call(route2).then((lazyRoute) => {
|
|
758
771
|
Object.assign(route2.options, lazyRoute.options);
|
|
759
772
|
})) || Promise.resolve();
|
|
@@ -771,17 +784,14 @@ class Router {
|
|
|
771
784
|
if (latestPromise = checkLatest())
|
|
772
785
|
return await latestPromise;
|
|
773
786
|
loaderPromise = (_c = (_b2 = route2.options).loader) == null ? void 0 : _c.call(_b2, loaderContext);
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
787
|
+
matches[index] = match = updateMatch(
|
|
788
|
+
match.id,
|
|
789
|
+
(prev) => ({
|
|
790
|
+
...prev,
|
|
791
|
+
loaderPromise
|
|
792
|
+
})
|
|
778
793
|
);
|
|
779
794
|
}
|
|
780
|
-
matches[index] = match = updateMatch(match.id, (prev) => ({
|
|
781
|
-
...prev,
|
|
782
|
-
loaderPromise,
|
|
783
|
-
loadPromise
|
|
784
|
-
}));
|
|
785
795
|
const loaderData = await loaderPromise;
|
|
786
796
|
if (latestPromise = checkLatest())
|
|
787
797
|
return await latestPromise;
|
|
@@ -832,7 +842,7 @@ class Router {
|
|
|
832
842
|
await componentsPromise;
|
|
833
843
|
if (latestPromise = checkLatest())
|
|
834
844
|
return await latestPromise;
|
|
835
|
-
loadPromise.resolve();
|
|
845
|
+
match.loadPromise.resolve();
|
|
836
846
|
};
|
|
837
847
|
const age = Date.now() - match.updatedAt;
|
|
838
848
|
const staleAge = preload ? route2.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route2.options.staleTime ?? this.options.defaultStaleTime ?? 0;
|
|
@@ -932,21 +942,28 @@ class Router {
|
|
|
932
942
|
});
|
|
933
943
|
let redirect;
|
|
934
944
|
let notFound$1;
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
await
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
945
|
+
const loadMatches = () => this.loadMatches({
|
|
946
|
+
matches: pendingMatches,
|
|
947
|
+
location: next,
|
|
948
|
+
checkLatest: () => this.checkLatest(promise)
|
|
949
|
+
});
|
|
950
|
+
if (previousMatches.length || this.isServer) {
|
|
951
|
+
try {
|
|
952
|
+
await loadMatches();
|
|
953
|
+
} catch (err) {
|
|
954
|
+
if (redirects.isRedirect(err)) {
|
|
955
|
+
redirect = err;
|
|
956
|
+
} else if (notFound.isNotFound(err)) {
|
|
957
|
+
notFound$1 = err;
|
|
958
|
+
}
|
|
949
959
|
}
|
|
960
|
+
} else {
|
|
961
|
+
loadMatches().catch((err) => {
|
|
962
|
+
if (redirects.isRedirect(err)) {
|
|
963
|
+
this.navigate({ ...err, replace: true });
|
|
964
|
+
}
|
|
965
|
+
this.load();
|
|
966
|
+
});
|
|
950
967
|
}
|
|
951
968
|
if (latestPromise = this.checkLatest(promise)) {
|
|
952
969
|
return latestPromise;
|
|
@@ -1063,7 +1080,7 @@ class Router {
|
|
|
1063
1080
|
} catch (err) {
|
|
1064
1081
|
if (redirects.isRedirect(err)) {
|
|
1065
1082
|
return await this.preloadRoute({
|
|
1066
|
-
|
|
1083
|
+
fromSearch: next.search,
|
|
1067
1084
|
from: next.pathname,
|
|
1068
1085
|
...err
|
|
1069
1086
|
});
|