@tanstack/react-router 1.69.0 → 1.70.0

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.
@@ -270,7 +270,7 @@ class Router {
270
270
  };
271
271
  this.buildLocation = (opts) => {
272
272
  const build = (dest = {}, matchedRoutesResult) => {
273
- var _a, _b, _c, _d, _e;
273
+ var _a, _b, _c, _d, _e, _f;
274
274
  const fromMatches = dest._fromLocation ? this.matchRoutes(dest._fromLocation, { _buildLocation: true }) : this.state.matches;
275
275
  const fromMatch = dest.from != null ? fromMatches.find(
276
276
  (d) => matchPathname(this.basepath, trimPathRight(d.pathname), {
@@ -381,15 +381,20 @@ class Router {
381
381
  };
382
382
  let search = applyMiddlewares();
383
383
  if (opts._includeValidateSearch) {
384
+ let validatedSearch = ((_f = this.options.search) == null ? void 0 : _f.strict) ? {} : search;
384
385
  matchedRoutesResult == null ? void 0 : matchedRoutesResult.matchedRoutes.forEach((route) => {
385
386
  try {
386
387
  if (route.options.validateSearch) {
387
388
  const validator = typeof route.options.validateSearch === "object" ? route.options.validateSearch.parse : route.options.validateSearch;
388
- search = { ...search, ...validator(search) };
389
+ validatedSearch = {
390
+ ...validatedSearch,
391
+ ...validator({ ...validatedSearch, ...search })
392
+ };
389
393
  }
390
394
  } catch (e) {
391
395
  }
392
396
  });
397
+ search = validatedSearch;
393
398
  }
394
399
  search = replaceEqualDeep(fromSearch, search);
395
400
  const searchStr = this.options.stringifySearch(search);
@@ -957,24 +962,31 @@ class Router {
957
962
  }
958
963
  };
959
964
  try {
960
- route._lazyPromise = route._lazyPromise || (route.lazyFn ? route.lazyFn().then((lazyRoute) => {
961
- const { id, ...options2 } = lazyRoute.options;
962
- Object.assign(route.options, options2);
963
- }) : Promise.resolve());
964
- const componentsPromise = this.getMatch(matchId).componentsPromise || route._lazyPromise.then(
965
- () => Promise.all(
966
- componentTypes.map(async (type) => {
967
- const component = route.options[type];
968
- if (component == null ? void 0 : component.preload) {
969
- await component.preload();
970
- }
971
- })
972
- )
973
- );
965
+ if (route._lazyPromise === void 0) {
966
+ if (route.lazyFn) {
967
+ route._lazyPromise = route.lazyFn().then((lazyRoute) => {
968
+ const { id: _id, ...options2 } = lazyRoute.options;
969
+ Object.assign(route.options, options2);
970
+ });
971
+ } else {
972
+ route._lazyPromise = Promise.resolve();
973
+ }
974
+ }
975
+ if (route._componentsPromise === void 0) {
976
+ route._componentsPromise = route._lazyPromise.then(
977
+ () => Promise.all(
978
+ componentTypes.map(async (type) => {
979
+ const component = route.options[type];
980
+ if (component == null ? void 0 : component.preload) {
981
+ await component.preload();
982
+ }
983
+ })
984
+ )
985
+ );
986
+ }
974
987
  updateMatch(matchId, (prev) => ({
975
988
  ...prev,
976
- isFetching: "loader",
977
- componentsPromise
989
+ isFetching: "loader"
978
990
  }));
979
991
  let loaderData = await ((_b2 = (_a2 = route.options).loader) == null ? void 0 : _b2.call(_a2, getLoaderContext()));
980
992
  if (this.serializeLoaderData) {
@@ -1032,7 +1044,7 @@ class Router {
1032
1044
  isFetching: false
1033
1045
  }));
1034
1046
  }
1035
- await this.getMatch(matchId).componentsPromise;
1047
+ await route._componentsPromise;
1036
1048
  } catch (err) {
1037
1049
  handleRedirectAndNotFound(this.getMatch(matchId), err);
1038
1050
  }
@@ -1082,12 +1094,18 @@ class Router {
1082
1094
  }
1083
1095
  return matches;
1084
1096
  };
1085
- this.invalidate = () => {
1086
- const invalidate = (d) => ({
1087
- ...d,
1088
- invalid: true,
1089
- ...d.status === "error" ? { status: "pending", error: void 0 } : {}
1090
- });
1097
+ this.invalidate = (opts) => {
1098
+ const invalidate = (d) => {
1099
+ var _a;
1100
+ if (((_a = opts == null ? void 0 : opts.filter) == null ? void 0 : _a.call(opts, d)) ?? true) {
1101
+ return {
1102
+ ...d,
1103
+ invalid: true,
1104
+ ...d.status === "error" ? { status: "pending", error: void 0 } : {}
1105
+ };
1106
+ }
1107
+ return d;
1108
+ };
1091
1109
  this.__store.setState((s) => {
1092
1110
  var _a;
1093
1111
  return {