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