@tanstack/react-router 1.72.1 → 1.73.1

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.
@@ -523,7 +523,10 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
523
523
  filter?: (d: MakeRouteMatch<TRouteTree>) => boolean;
524
524
  }) => Promise<void>;
525
525
  resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
526
- cleanCache: () => void;
526
+ clearCache: (opts?: {
527
+ filter?: (d: MakeRouteMatch<TRouteTree>) => boolean;
528
+ }) => void;
529
+ clearExpiredCache: () => void;
527
530
  preloadRoute: <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = "">(opts: NavigateOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
528
531
  matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
529
532
  dehydrate: () => DehydratedRouter;
@@ -523,7 +523,10 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
523
523
  filter?: (d: MakeRouteMatch<TRouteTree>) => boolean;
524
524
  }) => Promise<void>;
525
525
  resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
526
- cleanCache: () => void;
526
+ clearCache: (opts?: {
527
+ filter?: (d: MakeRouteMatch<TRouteTree>) => boolean;
528
+ }) => void;
529
+ clearExpiredCache: () => void;
527
530
  preloadRoute: <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = "">(opts: NavigateOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
528
531
  matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
529
532
  dehydrate: () => DehydratedRouter;
@@ -633,7 +633,7 @@ class Router {
633
633
  ]
634
634
  };
635
635
  });
636
- this.cleanCache();
636
+ this.clearExpiredCache();
637
637
  });
638
638
  [
639
639
  [exitingMatches, "onLeave"],
@@ -1125,20 +1125,34 @@ class Router {
1125
1125
  }
1126
1126
  return redirect;
1127
1127
  };
1128
- this.cleanCache = () => {
1129
- this.__store.setState((s) => {
1130
- return {
1131
- ...s,
1132
- cachedMatches: s.cachedMatches.filter((d) => {
1133
- const route = this.looseRoutesById[d.routeId];
1134
- if (!route.options.loader) {
1135
- return false;
1136
- }
1137
- const gcTime = (d.preload ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime : route.options.gcTime ?? this.options.defaultGcTime) ?? 5 * 60 * 1e3;
1138
- return d.status !== "error" && Date.now() - d.updatedAt < gcTime;
1139
- })
1140
- };
1141
- });
1128
+ this.clearCache = (opts) => {
1129
+ const filter = opts == null ? void 0 : opts.filter;
1130
+ if (filter !== void 0) {
1131
+ this.__store.setState((s) => {
1132
+ return {
1133
+ ...s,
1134
+ cachedMatches: s.cachedMatches.filter((m) => !filter(m))
1135
+ };
1136
+ });
1137
+ } else {
1138
+ this.__store.setState((s) => {
1139
+ return {
1140
+ ...s,
1141
+ cachedMatches: []
1142
+ };
1143
+ });
1144
+ }
1145
+ };
1146
+ this.clearExpiredCache = () => {
1147
+ const filter = (d) => {
1148
+ const route = this.looseRoutesById[d.routeId];
1149
+ if (!route.options.loader) {
1150
+ return true;
1151
+ }
1152
+ const gcTime = (d.preload ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime : route.options.gcTime ?? this.options.defaultGcTime) ?? 5 * 60 * 1e3;
1153
+ return !(d.status !== "error" && Date.now() - d.updatedAt < gcTime);
1154
+ };
1155
+ this.clearCache({ filter });
1142
1156
  };
1143
1157
  this.preloadRoute = async (opts) => {
1144
1158
  const next = this.buildLocation(opts);