@tanstack/router-core 1.171.3 → 1.171.4

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.
Files changed (46) hide show
  1. package/dist/cjs/index.cjs +0 -3
  2. package/dist/cjs/index.d.cts +1 -2
  3. package/dist/cjs/rewrite.cjs +1 -6
  4. package/dist/cjs/rewrite.cjs.map +1 -1
  5. package/dist/cjs/rewrite.d.cts +0 -4
  6. package/dist/cjs/router.cjs +9 -2
  7. package/dist/cjs/router.cjs.map +1 -1
  8. package/dist/cjs/router.d.cts +5 -1
  9. package/dist/cjs/scroll-restoration-inline.cjs +1 -1
  10. package/dist/cjs/scroll-restoration-inline.cjs.map +1 -1
  11. package/dist/cjs/scroll-restoration-inline.d.cts +0 -2
  12. package/dist/cjs/scroll-restoration-script/server.cjs +2 -6
  13. package/dist/cjs/scroll-restoration-script/server.cjs.map +1 -1
  14. package/dist/cjs/scroll-restoration.cjs +113 -107
  15. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  16. package/dist/cjs/scroll-restoration.d.cts +0 -10
  17. package/dist/esm/index.d.ts +1 -2
  18. package/dist/esm/index.js +2 -3
  19. package/dist/esm/rewrite.d.ts +0 -4
  20. package/dist/esm/rewrite.js +1 -6
  21. package/dist/esm/rewrite.js.map +1 -1
  22. package/dist/esm/router.d.ts +5 -1
  23. package/dist/esm/router.js +9 -3
  24. package/dist/esm/router.js.map +1 -1
  25. package/dist/esm/scroll-restoration-inline.d.ts +0 -2
  26. package/dist/esm/scroll-restoration-inline.js +1 -1
  27. package/dist/esm/scroll-restoration-inline.js.map +1 -1
  28. package/dist/esm/scroll-restoration-script/server.js +2 -6
  29. package/dist/esm/scroll-restoration-script/server.js.map +1 -1
  30. package/dist/esm/scroll-restoration.d.ts +0 -10
  31. package/dist/esm/scroll-restoration.js +114 -107
  32. package/dist/esm/scroll-restoration.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/index.ts +0 -3
  35. package/src/rewrite.ts +1 -8
  36. package/src/router.ts +28 -4
  37. package/src/scroll-restoration-inline.ts +7 -16
  38. package/src/scroll-restoration-script/server.ts +1 -10
  39. package/src/scroll-restoration.ts +188 -167
  40. package/dist/cjs/hash-scroll.cjs +0 -20
  41. package/dist/cjs/hash-scroll.cjs.map +0 -1
  42. package/dist/cjs/hash-scroll.d.cts +0 -7
  43. package/dist/esm/hash-scroll.d.ts +0 -7
  44. package/dist/esm/hash-scroll.js +0 -20
  45. package/dist/esm/hash-scroll.js.map +0 -1
  46. package/src/hash-scroll.ts +0 -21
@@ -3,7 +3,7 @@ import { LRUCache } from './lru-cache.js';
3
3
  import { ProcessRouteTreeResult, ProcessedTree } from './new-process-route-tree.js';
4
4
  import { SearchParser, SearchSerializer } from './searchParams.js';
5
5
  import { AnyRedirect, ResolvedRedirect } from './redirect.js';
6
- import { HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
6
+ import { HistoryAction, HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
7
7
  import { Awaitable, Constrain, ControlledPromise, NoInfer, NonNullableUpdater, PickAsRequired, Updater } from './utils.js';
8
8
  import { ParsedLocation } from './location.js';
9
9
  import { AnyContext, AnyRoute, AnyRouteWithContext, LoaderStaleReloadMode, MakeRemountDepsOptionsUnion, RouteLike, RouteMask } from './route.js';
@@ -483,6 +483,9 @@ export type GetMatchRoutesFn = (pathname: string) => {
483
483
  export type EmitFn = (routerEvent: RouterEvent) => void;
484
484
  export type LoadFn = (opts?: {
485
485
  sync?: boolean;
486
+ action?: {
487
+ type: HistoryAction;
488
+ };
486
489
  }) => Promise<void>;
487
490
  export type CommitLocationFn = ({ viewTransition, ignoreBlocker, ...next }: ParsedLocation & CommitLocationOptions) => Promise<void>;
488
491
  export type StartTransitionFn = (fn: () => void) => void;
@@ -568,6 +571,7 @@ export declare function getLocationChangeInfo(location: ParsedLocation, resolved
568
571
  hrefChanged: boolean;
569
572
  hashChanged: boolean;
570
573
  };
574
+ export declare const locationHistoryActions: WeakMap<ParsedLocation<{}>, HistoryAction>;
571
575
  export type CreateRouterFn = <TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption = 'never', TDefaultStructuralSharingOption extends boolean = false, TRouterHistory extends RouterHistory = RouterHistory, TDehydrated extends Record<string, any> = Record<string, any>>(options: undefined extends number ? 'strictNullChecks must be enabled in tsconfig.json' : RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>) => RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>;
572
576
  declare global {
573
577
  var __TSR_CACHE__: {
@@ -49,6 +49,7 @@ function getLocationChangeInfo(location, resolvedLocation) {
49
49
  hashChanged: fromLocation?.hash !== toLocation.hash
50
50
  };
51
51
  }
52
+ const locationHistoryActions = /* @__PURE__ */ new WeakMap();
52
53
  /**
53
54
  * Core, framework-agnostic router engine that powers TanStack Router.
54
55
  *
@@ -374,6 +375,7 @@ var RouterCore = class {
374
375
  return buildWithMatches(opts);
375
376
  };
376
377
  this.commitLocation = async ({ viewTransition, ignoreBlocker, ...next }) => {
378
+ let historyAction;
377
379
  const isSameState = () => {
378
380
  const ignoredProps = [
379
381
  "key",
@@ -422,10 +424,11 @@ var RouterCore = class {
422
424
  }
423
425
  nextHistory.state.__hashScrollIntoViewOptions = hashScrollIntoView ?? this.options.defaultHashScrollIntoView ?? true;
424
426
  this.shouldViewTransition = viewTransition;
425
- this.history[next.replace ? "replace" : "push"](nextHistory.publicHref, nextHistory.state, { ignoreBlocker });
427
+ historyAction = next.replace ? "REPLACE" : "PUSH";
428
+ this.history[historyAction === "REPLACE" ? "replace" : "push"](nextHistory.publicHref, nextHistory.state, { ignoreBlocker });
426
429
  }
427
430
  this.resetNextScroll = next.resetScroll ?? true;
428
- if (!this.history.subscribers.size) this.load();
431
+ if (!this.history.subscribers.size) this.load(historyAction ? { action: { type: historyAction } } : void 0);
429
432
  return this.commitLocationPromise;
430
433
  };
431
434
  this.buildAndCommitLocation = ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, href, ...rest } = {}) => {
@@ -530,6 +533,7 @@ var RouterCore = class {
530
533
  });
531
534
  };
532
535
  this.load = async (opts) => {
536
+ const historyAction = opts?.action?.type;
533
537
  let redirect;
534
538
  let notFound;
535
539
  let loadPromise;
@@ -538,6 +542,8 @@ var RouterCore = class {
538
542
  this.startTransition(async () => {
539
543
  try {
540
544
  this.beforeLoad();
545
+ if (historyAction) locationHistoryActions.set(this.latestLocation, historyAction);
546
+ else locationHistoryActions.delete(this.latestLocation);
541
547
  const next = this.latestLocation;
542
548
  const locationChangeInfo = getLocationChangeInfo(next, this.stores.resolvedLocation.get());
543
549
  if (!this.stores.redirect.get()) this.emit({
@@ -1172,6 +1178,6 @@ function extractStrictParams(route, accumulatedParams) {
1172
1178
  }
1173
1179
  }
1174
1180
  //#endregion
1175
- export { PathParamError, RouterCore, SearchParamError, defaultSerializeError, getInitialRouterState, getLocationChangeInfo, getMatchedRoutes, lazyFn, trailingSlashOptions };
1181
+ export { PathParamError, RouterCore, SearchParamError, defaultSerializeError, getInitialRouterState, getLocationChangeInfo, getMatchedRoutes, lazyFn, locationHistoryActions, trailingSlashOptions };
1176
1182
 
1177
1183
  //# sourceMappingURL=router.js.map