@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.
@@ -635,7 +635,7 @@ class Router {
635
635
  ]
636
636
  };
637
637
  });
638
- this.cleanCache();
638
+ this.clearExpiredCache();
639
639
  });
640
640
  [
641
641
  [exitingMatches, "onLeave"],
@@ -1127,20 +1127,34 @@ class Router {
1127
1127
  }
1128
1128
  return redirect;
1129
1129
  };
1130
- this.cleanCache = () => {
1131
- this.__store.setState((s) => {
1132
- return {
1133
- ...s,
1134
- cachedMatches: s.cachedMatches.filter((d) => {
1135
- const route = this.looseRoutesById[d.routeId];
1136
- if (!route.options.loader) {
1137
- return false;
1138
- }
1139
- const gcTime = (d.preload ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime : route.options.gcTime ?? this.options.defaultGcTime) ?? 5 * 60 * 1e3;
1140
- return d.status !== "error" && Date.now() - d.updatedAt < gcTime;
1141
- })
1142
- };
1143
- });
1130
+ this.clearCache = (opts) => {
1131
+ const filter = opts == null ? void 0 : opts.filter;
1132
+ if (filter !== void 0) {
1133
+ this.__store.setState((s) => {
1134
+ return {
1135
+ ...s,
1136
+ cachedMatches: s.cachedMatches.filter((m) => !filter(m))
1137
+ };
1138
+ });
1139
+ } else {
1140
+ this.__store.setState((s) => {
1141
+ return {
1142
+ ...s,
1143
+ cachedMatches: []
1144
+ };
1145
+ });
1146
+ }
1147
+ };
1148
+ this.clearExpiredCache = () => {
1149
+ const filter = (d) => {
1150
+ const route = this.looseRoutesById[d.routeId];
1151
+ if (!route.options.loader) {
1152
+ return true;
1153
+ }
1154
+ const gcTime = (d.preload ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime : route.options.gcTime ?? this.options.defaultGcTime) ?? 5 * 60 * 1e3;
1155
+ return !(d.status !== "error" && Date.now() - d.updatedAt < gcTime);
1156
+ };
1157
+ this.clearCache({ filter });
1144
1158
  };
1145
1159
  this.preloadRoute = async (opts) => {
1146
1160
  const next = this.buildLocation(opts);