@tanstack/router-core 1.171.16-pre.0 → 1.171.16

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.
@@ -7,7 +7,7 @@ import { AnyRoute } from './route.cjs';
7
7
  import { AnyRedirect } from './redirect.cjs';
8
8
  import { AnyRouter } from './router.cjs';
9
9
  export declare function replaceRouteChunk(route: AnyRoute, lazyFn: AnyRoute['lazyFn']): void;
10
- export declare function loadRouteChunk(route: AnyRoute, componentType?: 'errorComponent' | 'notFoundComponent' | false): Promise<void> | undefined;
10
+ export declare function loadRouteChunk(route: AnyRoute, componentType?: 'errorComponent' | 'notFoundComponent' | false, onPendingReady?: () => void): Promise<void> | undefined;
11
11
  /** Return the structural lane through the first terminal render boundary. */
12
12
  export declare function _getRenderedMatches(matches: Array<AnyRouteMatch>): Array<AnyRouteMatch>;
13
13
  /** Return the lane whose document assets belong to the current presentation. */
@@ -37,7 +37,7 @@ declare const ERROR = 1;
37
37
  declare const NOT_FOUND = 2;
38
38
  declare const REDIRECTED = 3;
39
39
  declare const CANCELED = 4;
40
- type LoaderOutcome = [typeof SUCCESS, data: unknown] | [typeof ERROR, error: unknown] | [typeof NOT_FOUND, error: NotFoundError] | [typeof REDIRECTED, redirect: AnyRedirect] | [typeof CANCELED];
40
+ type LoaderOutcome = [kind: typeof SUCCESS, data: unknown] | [kind: typeof ERROR, error: unknown] | [kind: typeof NOT_FOUND, error: NotFoundError] | [kind: typeof REDIRECTED, redirect: AnyRedirect] | [kind: typeof CANCELED];
41
41
  type IndexedOutcome = [index: number, outcome: LoaderOutcome, boundary?: number];
42
42
  export type LoaderFlight = [
43
43
  outcome: Promise<LoaderOutcome>,
@@ -58,27 +58,6 @@ declare const matchPhase: unique symbol;
58
58
  type SettledMatch = WorkMatch & {
59
59
  readonly [matchPhase]: 'settled';
60
60
  };
61
- export type LaneInputs = [
62
- routeTree: AnyRoute,
63
- context: unknown,
64
- additionalContext: unknown,
65
- state: object,
66
- search: object,
67
- maskedLocation: [
68
- href: string,
69
- state: object,
70
- search: object,
71
- unmaskOnReload: boolean | undefined
72
- ] | undefined
73
- ];
74
- export type ActivePreload = [
75
- matches: Array<AnyRouteMatch>,
76
- controller: AbortController,
77
- result: Promise<LaneResult>,
78
- semanticOwner: Array<AnyRouteMatch>,
79
- inputs: LaneInputs,
80
- redirects: number
81
- ];
82
61
  export type LoadTransaction = [
83
62
  controller: AbortController,
84
63
  redirects: number,
@@ -88,12 +67,14 @@ export type LoadTransaction = [
88
67
  done: Promise<void>,
89
68
  /**
90
69
  * Dev-only HMR refresh mode. Presence is the mode flag; a refresh always
91
- * carries the presentation it started from, while the hydration handoff is
92
- * genuinely optional the tuple makes a half-armed refresh unrepresentable.
70
+ * carries the presentation it started from and its optional hydration
71
+ * handoff. While a publication awaits acknowledgement, its rollback lives
72
+ * with the transaction that owns the publication.
93
73
  */
94
74
  refresh?: [
95
75
  presentation: Array<AnyRouteMatch>,
96
- handoff: NonNullable<AnyRouter['_handoff']> | undefined
76
+ handoff: NonNullable<AnyRouter['_handoff']> | undefined,
77
+ rollback?: () => boolean
97
78
  ]
98
79
  ];
99
80
  export type PendingSession = [
@@ -106,34 +87,24 @@ export type PendingSession = [
106
87
  component?: unknown
107
88
  ];
108
89
  type CoordinatorRouter = AnyRouter & {
109
- /** Whole speculative lanes that a matching navigation may adopt. */
110
- _preloads?: Map<string, ActivePreload>;
90
+ /** Active speculative lanes retained for cancellation, invalidation, and cache clearing. */
91
+ _preloads?: Map<AbortController, Array<AnyRouteMatch>>;
111
92
  _refreshNextLoad?: boolean;
112
- _rollbackRefresh?: () => void;
113
93
  _cancelTransition?: () => void;
114
94
  };
115
95
  type BackgroundLoaderTask = [
116
96
  index: number,
117
97
  outcome: Promise<LoaderOutcome>,
118
- ready: Promise<IndexedOutcome | undefined>,
98
+ chunkFailure: Promise<IndexedOutcome | undefined>,
119
99
  candidate: WorkMatch
120
100
  ];
121
- type ControlOutcome = [typeof REDIRECTED, redirect: AnyRedirect] | [typeof CANCELED];
122
- type LaneResult = ProjectedLane | ControlOutcome;
123
101
  export declare function waitFor<T>(value: T | PromiseLike<T>, signal: AbortSignal): Promise<T>;
124
102
  export declare function getRoute(router: AnyRouter, match: WorkMatch): AnyRoute;
125
103
  export declare function navigateFrom(router: AnyRouter, location: ParsedLocation): (opts: any) => Promise<void>;
126
- export declare function laneInputs(router: AnyRouter, location: ParsedLocation): LaneInputs;
127
- /**
128
- * Not passing in a `next` ownership recipient
129
- * is equivalent to discarding the match resources
130
- */
131
- export declare function transferMatchResources(router: AnyRouter, previous: Array<AnyRouteMatch>, next?: Array<AnyRouteMatch>): void;
132
104
  export declare function cacheLoaderMatch(router: CoordinatorRouter, match: SettledMatch, planned: AnyRouteMatch | undefined): void;
133
105
  export declare function projectLane(router: AnyRouter, lane: ReducedLane, signal: AbortSignal, start?: number, end?: number): Promise<ProjectedLane>;
134
106
  export declare function loadClientRoute(router: CoordinatorRouter, opts?: {
135
107
  sync?: boolean;
136
- _dedupe?: boolean;
137
108
  }): Promise<void>;
138
109
  export declare function refreshClientRoute(router: CoordinatorRouter): Promise<void>;
139
110
  export declare function preloadClientRoute(router: CoordinatorRouter, opts: any, redirects?: number): Promise<Array<AnyRouteMatch> | undefined>;
@@ -387,7 +387,7 @@ var RouterCore = class {
387
387
  previousCommitPromise?.resolve();
388
388
  };
389
389
  this._commitPromise = commitPromise;
390
- if (isSameLocation) this.load({ _dedupe: true });
390
+ if (isSameLocation) this.load();
391
391
  else {
392
392
  let { maskedLocation, hashScrollIntoView, ...nextHistory } = next;
393
393
  if (maskedLocation) {
@@ -518,9 +518,20 @@ var RouterCore = class {
518
518
  this.invalidate = (opts) => {
519
519
  const committedMatches = this._committed;
520
520
  const filter = opts?.filter;
521
- const invalidIds = filter ? new Set([...committedMatches, ...this._cache.values()].filter((match) => filter(match)).map((match) => match.id)) : void 0;
521
+ const preloads = this._preloads;
522
+ const invalidIds = new Set([
523
+ ...committedMatches,
524
+ ...this._cache.values(),
525
+ ...[...preloads?.values() ?? []].flat(),
526
+ ...this._tx?.[3] ?? []
527
+ ].filter((match) => !filter || filter(match)).map((match) => match.id));
528
+ const discardedPreloads = [];
529
+ for (const [controller, matches] of preloads ?? []) if (matches.some((match) => invalidIds.has(match.id))) {
530
+ preloads.delete(controller);
531
+ discardedPreloads.push(controller);
532
+ }
522
533
  const invalidate = (d) => {
523
- if (!invalidIds || invalidIds.has(d.id)) {
534
+ if (invalidIds.has(d.id)) {
524
535
  const route = this.routesById[d.routeId];
525
536
  const next = {
526
537
  ...d,
@@ -535,11 +546,13 @@ var RouterCore = class {
535
546
  }
536
547
  return d;
537
548
  };
538
- const committed = committedMatches.map(invalidate);
539
- this._committed = committed;
540
- const cache = /* @__PURE__ */ new Map();
541
- for (const [id, match] of this._cache) cache.set(id, invalidate(match));
542
- this._cache = cache;
549
+ this._committed = committedMatches.map(invalidate);
550
+ for (const [id, match] of this._cache) if (invalidIds.has(id)) {
551
+ match.invalid = true;
552
+ if (opts?.forcePending) match.status = "pending";
553
+ }
554
+ for (const id of invalidIds) this._flights?.delete(id);
555
+ for (const controller of discardedPreloads) controller.abort();
543
556
  this.shouldViewTransition = false;
544
557
  return this.load({ sync: opts?.sync });
545
558
  };
@@ -565,20 +578,28 @@ var RouterCore = class {
565
578
  const cached = this._cache;
566
579
  const preloads = this._preloads;
567
580
  const filter = opts?.filter;
568
- const retained = /* @__PURE__ */ new Map();
569
581
  const discarded = [];
570
- for (const [id, match] of cached) if (filter && !filter(match)) retained.set(id, match);
571
- else discarded.push(match);
572
- const retainedPreloads = /* @__PURE__ */ new Map();
573
- const discardedPreloads = [];
574
- for (const [href, preload] of preloads ?? []) if (!filter || preload[0].some(filter)) {
575
- discardedPreloads.push(preload);
576
- discarded.push(...preload[0]);
577
- } else retainedPreloads.set(href, preload);
578
- this._cache = retained;
579
- this._preloads = retainedPreloads;
580
- require_load_client.transferMatchResources(this, discarded);
581
- for (const preload of discardedPreloads) preload[1].abort();
582
+ const discardedIds = [];
583
+ for (const [id, match] of cached) if (!filter || filter(match)) {
584
+ discardedIds.push(id);
585
+ discarded.push(match);
586
+ }
587
+ const abort = [];
588
+ for (const [controller, matches] of preloads ?? []) if (!filter || matches.some(filter)) {
589
+ abort.push(controller);
590
+ discarded.push(...matches);
591
+ }
592
+ for (const id of discardedIds) cached.delete(id);
593
+ for (const controller of abort) preloads.delete(controller);
594
+ for (const match of discarded) {
595
+ const flight = match._flight;
596
+ match._flight = void 0;
597
+ if (flight && !--flight[2]) {
598
+ if (this._flights?.get(match.id) === flight) this._flights.delete(match.id);
599
+ abort.push(flight[1]);
600
+ }
601
+ }
602
+ for (const controller of abort) controller.abort();
582
603
  };
583
604
  this.loadRouteChunk = require_load_client.loadRouteChunk;
584
605
  this.preloadRoute = (opts) => require_load_client.preloadClientRoute(this, opts);
@@ -931,7 +952,6 @@ function extractStrictParams(route, accumulatedParams) {
931
952
  exports.PathParamError = PathParamError;
932
953
  exports.RouterCore = RouterCore;
933
954
  exports.SearchParamError = SearchParamError;
934
- exports._getUserHistoryState = _getUserHistoryState;
935
955
  exports.defaultSerializeError = defaultSerializeError;
936
956
  exports.getInitialRouterState = getInitialRouterState;
937
957
  exports.getLocationChangeInfo = getLocationChangeInfo;