@tanstack/router-core 1.171.13 → 1.171.15

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.
@@ -49,7 +49,6 @@ function getLocationChangeInfo(location, resolvedLocation) {
49
49
  hashChanged: fromLocation?.hash !== toLocation.hash
50
50
  };
51
51
  }
52
- const locationHistoryActions = /* @__PURE__ */ new WeakMap();
53
52
  /**
54
53
  * Core, framework-agnostic router engine that powers TanStack Router.
55
54
  *
@@ -70,6 +69,7 @@ var RouterCore = class {
70
69
  this.isViewTransitionTypesSupported = void 0;
71
70
  this.subscribers = /* @__PURE__ */ new Set();
72
71
  this.routeBranchCache = /* @__PURE__ */ new WeakMap();
72
+ this.lightweightCache = /* @__PURE__ */ new WeakMap();
73
73
  this.startTransition = (fn) => fn();
74
74
  this.update = (newOptions) => {
75
75
  if (process.env.NODE_ENV !== "production") {
@@ -451,7 +451,7 @@ var RouterCore = class {
451
451
  hashScrollIntoView,
452
452
  ignoreBlocker
453
453
  });
454
- Promise.resolve().then(() => {
454
+ queueMicrotask(() => {
455
455
  if (this.pendingBuiltLocation === location) this.pendingBuiltLocation = void 0;
456
456
  });
457
457
  return commitPromise;
@@ -475,7 +475,7 @@ var RouterCore = class {
475
475
  const reloadHref = !hrefIsUrl && publicHref ? publicHref : href;
476
476
  if (require_utils.isDangerousProtocol(reloadHref, this.protocolAllowlist)) {
477
477
  if (process.env.NODE_ENV !== "production") console.warn(`Blocked navigation to dangerous protocol: ${reloadHref}`);
478
- return Promise.resolve();
478
+ return;
479
479
  }
480
480
  if (!rest.ignoreBlocker) {
481
481
  const blockers = this.history.getBlockers?.() ?? [];
@@ -484,12 +484,12 @@ var RouterCore = class {
484
484
  currentLocation: this.latestLocation,
485
485
  nextLocation: this.latestLocation,
486
486
  action: "PUSH"
487
- })) return Promise.resolve();
487
+ })) return;
488
488
  }
489
489
  }
490
490
  if (rest.replace) window.location.replace(reloadHref);
491
491
  else window.location.href = reloadHref;
492
- return Promise.resolve();
492
+ return;
493
493
  }
494
494
  return this.buildAndCommitLocation({
495
495
  ...rest,
@@ -540,8 +540,7 @@ var RouterCore = class {
540
540
  this.startTransition(async () => {
541
541
  try {
542
542
  this.beforeLoad();
543
- if (historyAction) locationHistoryActions.set(this.latestLocation, historyAction);
544
- else locationHistoryActions.delete(this.latestLocation);
543
+ if (historyAction) this._scroll.hash = historyAction === "PUSH" || historyAction === "REPLACE";
545
544
  const next = this.latestLocation;
546
545
  const locationChangeInfo = getLocationChangeInfo(next, this.stores.resolvedLocation.get());
547
546
  if (!this.stores.redirect.get()) this.emit({
@@ -1007,13 +1006,15 @@ var RouterCore = class {
1007
1006
  * operations like AbortController, ControlledPromise, loaderDeps, and full match objects.
1008
1007
  */
1009
1008
  matchRoutesLightweight(location) {
1009
+ const lastStateMatchId = require_utils.last(this.stores.matchesId.get());
1010
+ const cached = this.lightweightCache.get(location);
1011
+ if (cached && cached[0] === lastStateMatchId) return cached[1];
1010
1012
  const { matchedRoutes, routeParams } = this.getMatchedRoutes(location.pathname);
1011
1013
  const lastRoute = require_utils.last(matchedRoutes);
1012
1014
  const accumulatedSearch = { ...location.search };
1013
1015
  for (const route of matchedRoutes) try {
1014
1016
  Object.assign(accumulatedSearch, validateSearch(route.options.validateSearch, accumulatedSearch));
1015
1017
  } catch {}
1016
- const lastStateMatchId = require_utils.last(this.stores.matchesId.get());
1017
1018
  const lastStateMatch = lastStateMatchId && this.stores.matchStores.get(lastStateMatchId)?.get();
1018
1019
  const canReuseParams = lastStateMatch && lastStateMatch.routeId === lastRoute.id && lastStateMatch.pathname === location.pathname;
1019
1020
  let params;
@@ -1025,12 +1026,14 @@ var RouterCore = class {
1025
1026
  } catch {}
1026
1027
  params = strictParams;
1027
1028
  }
1028
- return {
1029
+ const result = {
1029
1030
  matchedRoutes,
1030
1031
  fullPath: lastRoute.fullPath,
1031
1032
  search: accumulatedSearch,
1032
1033
  params
1033
1034
  };
1035
+ this.lightweightCache.set(location, [lastStateMatchId, result]);
1036
+ return result;
1034
1037
  }
1035
1038
  };
1036
1039
  /** Error thrown when search parameter validation fails. */
@@ -1189,7 +1192,6 @@ exports.getInitialRouterState = getInitialRouterState;
1189
1192
  exports.getLocationChangeInfo = getLocationChangeInfo;
1190
1193
  exports.getMatchedRoutes = getMatchedRoutes;
1191
1194
  exports.lazyFn = lazyFn;
1192
- exports.locationHistoryActions = locationHistoryActions;
1193
1195
  exports.trailingSlashOptions = trailingSlashOptions;
1194
1196
 
1195
1197
  //# sourceMappingURL=router.cjs.map