@tanstack/react-router 1.98.0 → 1.98.3
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/Match.cjs +60 -22
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +4 -1
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/ScriptOnce.cjs +1 -1
- package/dist/cjs/ScriptOnce.cjs.map +1 -1
- package/dist/cjs/ScrollRestoration.cjs +39 -0
- package/dist/cjs/ScrollRestoration.cjs.map +1 -0
- package/dist/cjs/ScrollRestoration.d.cts +15 -0
- package/dist/cjs/Transitioner.cjs +3 -33
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/index.cjs +3 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -2
- package/dist/cjs/router.cjs +14 -12
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +26 -26
- package/dist/cjs/scroll-restoration.cjs +166 -165
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +25 -15
- package/dist/esm/Match.js +62 -24
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.js +4 -1
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/ScriptOnce.js +1 -1
- package/dist/esm/ScriptOnce.js.map +1 -1
- package/dist/esm/ScrollRestoration.d.ts +15 -0
- package/dist/esm/ScrollRestoration.js +39 -0
- package/dist/esm/ScrollRestoration.js.map +1 -0
- package/dist/esm/Transitioner.js +4 -34
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/router.d.ts +26 -26
- package/dist/esm/router.js +15 -13
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +25 -15
- package/dist/esm/scroll-restoration.js +166 -148
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/package.json +3 -3
- package/src/Match.tsx +79 -48
- package/src/Matches.tsx +1 -1
- package/src/ScriptOnce.tsx +1 -1
- package/src/ScrollRestoration.tsx +65 -0
- package/src/Transitioner.tsx +4 -40
- package/src/index.tsx +1 -3
- package/src/router.ts +43 -38
- package/src/scroll-restoration.tsx +268 -182
package/dist/esm/router.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createMemoryHistory, createBrowserHistory, parseHref } from "@tanstack/history";
|
|
2
2
|
import { Store, batch } from "@tanstack/react-store";
|
|
3
3
|
import invariant from "tiny-invariant";
|
|
4
|
-
import { trimPath, trimPathLeft, parsePathname, resolvePath, cleanPath, trimPathRight, rootRouteId, pick, createControlledPromise, matchPathname, deepEqual, defaultStringifySearch, defaultParseSearch, interpolatePath, replaceEqualDeep, joinPaths, last, functionalUpdate } from "@tanstack/router-core";
|
|
4
|
+
import { trimPath, trimPathLeft, parsePathname, resolvePath, cleanPath, trimPathRight, rootRouteId, pick, createControlledPromise, getLocationChangeInfo, matchPathname, deepEqual, defaultStringifySearch, defaultParseSearch, interpolatePath, replaceEqualDeep, joinPaths, last, functionalUpdate } from "@tanstack/router-core";
|
|
5
5
|
import { isResolvedRedirect, isRedirect } from "./redirects.js";
|
|
6
6
|
import { isNotFound } from "./not-found.js";
|
|
7
|
+
import { setupScrollRestoration } from "./scroll-restoration.js";
|
|
7
8
|
const componentTypes = [
|
|
8
9
|
"component",
|
|
9
10
|
"errorComponent",
|
|
@@ -54,6 +55,8 @@ class Router {
|
|
|
54
55
|
this.shouldViewTransition = void 0;
|
|
55
56
|
this.isViewTransitionTypesSupported = void 0;
|
|
56
57
|
this.subscribers = /* @__PURE__ */ new Set();
|
|
58
|
+
this.isScrollRestoring = false;
|
|
59
|
+
this.isScrollRestorationSetup = false;
|
|
57
60
|
this.startReactTransition = (fn) => fn();
|
|
58
61
|
this.update = (newOptions) => {
|
|
59
62
|
var _a;
|
|
@@ -105,6 +108,7 @@ class Router {
|
|
|
105
108
|
};
|
|
106
109
|
}
|
|
107
110
|
});
|
|
111
|
+
setupScrollRestoration(this);
|
|
108
112
|
}
|
|
109
113
|
if (typeof window !== "undefined" && "CSS" in window && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
110
114
|
typeof ((_a = window.CSS) == null ? void 0 : _a.supports) === "function") {
|
|
@@ -629,8 +633,6 @@ class Router {
|
|
|
629
633
|
try {
|
|
630
634
|
const next = this.latestLocation;
|
|
631
635
|
const prevLocation = this.state.resolvedLocation;
|
|
632
|
-
const hrefChanged = prevLocation.href !== next.href;
|
|
633
|
-
const pathChanged = prevLocation.pathname !== next.pathname;
|
|
634
636
|
this.cancelMatches();
|
|
635
637
|
let pendingMatches;
|
|
636
638
|
batch(() => {
|
|
@@ -650,18 +652,18 @@ class Router {
|
|
|
650
652
|
if (!this.state.redirect) {
|
|
651
653
|
this.emit({
|
|
652
654
|
type: "onBeforeNavigate",
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
655
|
+
...getLocationChangeInfo({
|
|
656
|
+
resolvedLocation: prevLocation,
|
|
657
|
+
location: next
|
|
658
|
+
})
|
|
657
659
|
});
|
|
658
660
|
}
|
|
659
661
|
this.emit({
|
|
660
662
|
type: "onBeforeLoad",
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
663
|
+
...getLocationChangeInfo({
|
|
664
|
+
resolvedLocation: prevLocation,
|
|
665
|
+
location: next
|
|
666
|
+
})
|
|
665
667
|
});
|
|
666
668
|
await this.loadMatches({
|
|
667
669
|
sync: opts == null ? void 0 : opts.sync,
|
|
@@ -1337,7 +1339,7 @@ class Router {
|
|
|
1337
1339
|
return false;
|
|
1338
1340
|
}
|
|
1339
1341
|
const pending = (opts == null ? void 0 : opts.pending) === void 0 ? !this.state.isLoading : opts.pending;
|
|
1340
|
-
const baseLocation = pending ? this.latestLocation : this.state.resolvedLocation;
|
|
1342
|
+
const baseLocation = pending ? this.latestLocation : this.state.resolvedLocation || this.state.location;
|
|
1341
1343
|
const match = matchPathname(this.basepath, baseLocation.pathname, {
|
|
1342
1344
|
...opts,
|
|
1343
1345
|
to: next.pathname
|
|
@@ -1647,7 +1649,7 @@ function getInitialRouterState(location) {
|
|
|
1647
1649
|
isLoading: false,
|
|
1648
1650
|
isTransitioning: false,
|
|
1649
1651
|
status: "idle",
|
|
1650
|
-
resolvedLocation:
|
|
1652
|
+
resolvedLocation: void 0,
|
|
1651
1653
|
location,
|
|
1652
1654
|
matches: [],
|
|
1653
1655
|
pendingMatches: [],
|