@tanstack/router-core 1.171.12 → 1.171.14
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 +13 -10
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +7 -3
- package/dist/cjs/scroll-restoration.cjs +26 -20
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/utils.cjs +13 -4
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/router.d.ts +7 -3
- package/dist/esm/router.js +13 -10
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.js +26 -20
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/utils.js +13 -4
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +39 -16
- package/src/scroll-restoration.ts +39 -29
- package/src/utils.ts +21 -9
package/dist/cjs/router.cjs
CHANGED
|
@@ -65,13 +65,12 @@ var RouterCore = class {
|
|
|
65
65
|
*/
|
|
66
66
|
constructor(options, getStoreConfig) {
|
|
67
67
|
this.tempLocationKey = `${Math.round(Math.random() * 1e7)}`;
|
|
68
|
-
this.
|
|
68
|
+
this._scroll = { next: true };
|
|
69
69
|
this.shouldViewTransition = void 0;
|
|
70
70
|
this.isViewTransitionTypesSupported = void 0;
|
|
71
71
|
this.subscribers = /* @__PURE__ */ new Set();
|
|
72
|
-
this.isScrollRestoring = false;
|
|
73
|
-
this.isScrollRestorationSetup = false;
|
|
74
72
|
this.routeBranchCache = /* @__PURE__ */ new WeakMap();
|
|
73
|
+
this.lightweightCache = /* @__PURE__ */ new WeakMap();
|
|
75
74
|
this.startTransition = (fn) => fn();
|
|
76
75
|
this.update = (newOptions) => {
|
|
77
76
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -427,7 +426,7 @@ var RouterCore = class {
|
|
|
427
426
|
historyAction = next.replace ? "REPLACE" : "PUSH";
|
|
428
427
|
this.history[historyAction === "REPLACE" ? "replace" : "push"](nextHistory.publicHref, nextHistory.state, { ignoreBlocker });
|
|
429
428
|
}
|
|
430
|
-
this.
|
|
429
|
+
this._scroll.next = next.resetScroll ?? true;
|
|
431
430
|
if (!this.history.subscribers.size) this.load(historyAction ? { action: { type: historyAction } } : void 0);
|
|
432
431
|
return this.commitLocationPromise;
|
|
433
432
|
};
|
|
@@ -453,7 +452,7 @@ var RouterCore = class {
|
|
|
453
452
|
hashScrollIntoView,
|
|
454
453
|
ignoreBlocker
|
|
455
454
|
});
|
|
456
|
-
|
|
455
|
+
queueMicrotask(() => {
|
|
457
456
|
if (this.pendingBuiltLocation === location) this.pendingBuiltLocation = void 0;
|
|
458
457
|
});
|
|
459
458
|
return commitPromise;
|
|
@@ -477,7 +476,7 @@ var RouterCore = class {
|
|
|
477
476
|
const reloadHref = !hrefIsUrl && publicHref ? publicHref : href;
|
|
478
477
|
if (require_utils.isDangerousProtocol(reloadHref, this.protocolAllowlist)) {
|
|
479
478
|
if (process.env.NODE_ENV !== "production") console.warn(`Blocked navigation to dangerous protocol: ${reloadHref}`);
|
|
480
|
-
return
|
|
479
|
+
return;
|
|
481
480
|
}
|
|
482
481
|
if (!rest.ignoreBlocker) {
|
|
483
482
|
const blockers = this.history.getBlockers?.() ?? [];
|
|
@@ -486,12 +485,12 @@ var RouterCore = class {
|
|
|
486
485
|
currentLocation: this.latestLocation,
|
|
487
486
|
nextLocation: this.latestLocation,
|
|
488
487
|
action: "PUSH"
|
|
489
|
-
})) return
|
|
488
|
+
})) return;
|
|
490
489
|
}
|
|
491
490
|
}
|
|
492
491
|
if (rest.replace) window.location.replace(reloadHref);
|
|
493
492
|
else window.location.href = reloadHref;
|
|
494
|
-
return
|
|
493
|
+
return;
|
|
495
494
|
}
|
|
496
495
|
return this.buildAndCommitLocation({
|
|
497
496
|
...rest,
|
|
@@ -1009,13 +1008,15 @@ var RouterCore = class {
|
|
|
1009
1008
|
* operations like AbortController, ControlledPromise, loaderDeps, and full match objects.
|
|
1010
1009
|
*/
|
|
1011
1010
|
matchRoutesLightweight(location) {
|
|
1011
|
+
const lastStateMatchId = require_utils.last(this.stores.matchesId.get());
|
|
1012
|
+
const cached = this.lightweightCache.get(location);
|
|
1013
|
+
if (cached && cached[0] === lastStateMatchId) return cached[1];
|
|
1012
1014
|
const { matchedRoutes, routeParams } = this.getMatchedRoutes(location.pathname);
|
|
1013
1015
|
const lastRoute = require_utils.last(matchedRoutes);
|
|
1014
1016
|
const accumulatedSearch = { ...location.search };
|
|
1015
1017
|
for (const route of matchedRoutes) try {
|
|
1016
1018
|
Object.assign(accumulatedSearch, validateSearch(route.options.validateSearch, accumulatedSearch));
|
|
1017
1019
|
} catch {}
|
|
1018
|
-
const lastStateMatchId = require_utils.last(this.stores.matchesId.get());
|
|
1019
1020
|
const lastStateMatch = lastStateMatchId && this.stores.matchStores.get(lastStateMatchId)?.get();
|
|
1020
1021
|
const canReuseParams = lastStateMatch && lastStateMatch.routeId === lastRoute.id && lastStateMatch.pathname === location.pathname;
|
|
1021
1022
|
let params;
|
|
@@ -1027,12 +1028,14 @@ var RouterCore = class {
|
|
|
1027
1028
|
} catch {}
|
|
1028
1029
|
params = strictParams;
|
|
1029
1030
|
}
|
|
1030
|
-
|
|
1031
|
+
const result = {
|
|
1031
1032
|
matchedRoutes,
|
|
1032
1033
|
fullPath: lastRoute.fullPath,
|
|
1033
1034
|
search: accumulatedSearch,
|
|
1034
1035
|
params
|
|
1035
1036
|
};
|
|
1037
|
+
this.lightweightCache.set(location, [lastStateMatchId, result]);
|
|
1038
|
+
return result;
|
|
1036
1039
|
}
|
|
1037
1040
|
};
|
|
1038
1041
|
/** Error thrown when search parameter validation fails. */
|