@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.
@@ -1,8 +1,8 @@
1
- import { loadRouteChunk, ActivePreload, LoadTransaction, LoaderFlight, PendingSession } from './load-client.js';
2
1
  import { LRUCache } from './lru-cache.js';
3
2
  import { ProcessRouteTreeResult, ProcessedTree } from './new-process-route-tree.js';
4
3
  import { SearchParser, SearchSerializer } from './searchParams.js';
5
4
  import { AnyRedirect, ResolvedRedirect } from './redirect.js';
5
+ import { LoadTransaction, LoaderFlight, PendingSession } from './load-client.js';
6
6
  import { ServerLoadResult } from './load-server.js';
7
7
  import { HistoryAction, HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
8
8
  import { Awaitable, Constrain, NoInfer, NonNullableUpdater, PickAsRequired, Updater } from './utils.js';
@@ -482,10 +482,9 @@ export type LoadFn = (opts?: {
482
482
  type: HistoryAction;
483
483
  };
484
484
  _signal?: AbortSignal;
485
- _dedupe?: boolean;
486
485
  }) => Promise<void>;
487
486
  export type CommitLocationFn = ({ viewTransition, ignoreBlocker, ...next }: ParsedLocation & CommitLocationOptions) => Promise<void>;
488
- export type StartTransitionFn = (fn: () => void, expected: Array<AnyRouteMatch>, urgent?: boolean) => Promise<boolean>;
487
+ export type StartTransitionFn = (fn: () => void, expected: Array<AnyRouteMatch>) => Promise<boolean>;
489
488
  export interface MatchRoutesFn {
490
489
  (pathname: string, locationSearch?: AnySchema, opts?: MatchRoutesOpts): Array<MakeRouteMatchUnion>;
491
490
  /**
@@ -602,8 +601,8 @@ export interface RouterCore<in out TRouteTree extends AnyRoute, in out TTrailing
602
601
  _tx?: LoadTransaction;
603
602
  /** Joinable in-flight loader generations keyed by match ID. */
604
603
  _flights?: Map<string, LoaderFlight>;
605
- /** Whole speculative lanes that an identical navigation may adopt. */
606
- _preloads?: Map<string, ActivePreload>;
604
+ /** Active speculative lanes retained for cancellation, invalidation, and cache clearing. */
605
+ _preloads?: Map<AbortController, Array<AnyRouteMatch>>;
607
606
  /** Owns cancellable work before a client transaction publishes. */
608
607
  _preflight?: AbortController;
609
608
  /** Transfers one reconstructed SSR prefix into its initial client load. */
@@ -612,8 +611,11 @@ export interface RouterCore<in out TRouteTree extends AnyRoute, in out TTrailing
612
611
  _pending?: PendingSession;
613
612
  /** Result of the latest server load, used to render or redirect. */
614
613
  _serverResult?: ServerLoadResult;
615
- /** Framework callback that acknowledges an exact matches publication. */
616
- _rendered?: (matches: Array<AnyRouteMatch>) => void;
614
+ /** Framework publication waiting for an exact render acknowledgement. */
615
+ _rendered?: [
616
+ offered?: Array<AnyRouteMatch>,
617
+ settle?: (rendered: boolean) => void
618
+ ];
617
619
  /** Development-only HMR reload for a route and its descendants. */
618
620
  _refreshRoute: (() => Promise<void>) | undefined;
619
621
  /** Development-only replacement for a route's lazy chunk owner. */
@@ -733,9 +735,11 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
733
735
  load: LoadFn;
734
736
  startViewTransition: (fn: () => Promise<void>) => any;
735
737
  /**
736
- * Invalidate the current matches and optionally force them back into a pending state.
738
+ * Invalidate selected match generations and optionally force current matches
739
+ * back into a pending state.
737
740
  *
738
- * - Marks all matches that pass the optional `filter` as `invalid: true`.
741
+ * - Marks committed and cached matches whose IDs are selected as invalid.
742
+ * - Retires selected active preloads so older work cannot publish fresh data.
739
743
  *
740
744
  * The next load decides when to publish pending UI, so invalidation does not
741
745
  * mutate the currently rendered status.
@@ -743,7 +747,7 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
743
747
  invalidate: InvalidateFn<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>>;
744
748
  resolveRedirect: (redirect: AnyRedirect) => AnyRedirect;
745
749
  clearCache: ClearCacheFn<this>;
746
- loadRouteChunk: typeof loadRouteChunk;
750
+ loadRouteChunk: (route: AnyRoute, componentType?: 'errorComponent' | 'notFoundComponent' | false) => Promise<void> | undefined;
747
751
  preloadRoute: PreloadRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
748
752
  matchRoute: MatchRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
749
753
  ssr?: {
@@ -7,7 +7,7 @@ import { setupScrollRestoration } from "./scroll-restoration.js";
7
7
  import { defaultParseSearch, defaultStringifySearch } from "./searchParams.js";
8
8
  import { rootRouteId } from "./root.js";
9
9
  import { isRedirect } from "./redirect.js";
10
- import { loadClientRoute, loadRouteChunk, preloadClientRoute, refreshClientRoute, replaceRouteChunk, transferMatchResources } from "./load-client.js";
10
+ import { loadClientRoute, loadRouteChunk, preloadClientRoute, refreshClientRoute, replaceRouteChunk } from "./load-client.js";
11
11
  import { composeRewrites, executeRewriteInput, executeRewriteOutput, rewriteBasepath } from "./rewrite.js";
12
12
  import { createRouterStores } from "./stores.js";
13
13
  import { createBrowserHistory, parseHref } from "@tanstack/history";
@@ -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
- 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 = loadRouteChunk;
584
605
  this.preloadRoute = (opts) => preloadClientRoute(this, opts);
@@ -928,6 +949,6 @@ function extractStrictParams(route, accumulatedParams) {
928
949
  if (parseParams) Object.assign(accumulatedParams, parseParams(accumulatedParams));
929
950
  }
930
951
  //#endregion
931
- export { PathParamError, RouterCore, SearchParamError, _getUserHistoryState, defaultSerializeError, getInitialRouterState, getLocationChangeInfo, lazyFn, runRouteLifecycle, trailingSlashOptions };
952
+ export { PathParamError, RouterCore, SearchParamError, defaultSerializeError, getInitialRouterState, getLocationChangeInfo, lazyFn, runRouteLifecycle, trailingSlashOptions };
932
953
 
933
954
  //# sourceMappingURL=router.js.map