@tanstack/router-core 1.157.16 → 1.157.18

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.
@@ -1104,6 +1104,11 @@ class RouterCore {
1104
1104
  get looseRoutesById() {
1105
1105
  return this.routesById;
1106
1106
  }
1107
+ getParentContext(parentMatch) {
1108
+ const parentMatchId = parentMatch?.id;
1109
+ const parentContext = !parentMatchId ? this.options.context ?? void 0 : parentMatch.context ?? this.options.context ?? void 0;
1110
+ return parentContext;
1111
+ }
1107
1112
  matchRoutesInternal(next, opts) {
1108
1113
  const matchedRoutesResult = this.getMatchedRoutes(next.pathname);
1109
1114
  const { foundRoute, routeParams, parsedParams } = matchedRoutesResult;
@@ -1123,27 +1128,24 @@ class RouterCore {
1123
1128
  }
1124
1129
  }
1125
1130
  const globalNotFoundRouteId = isGlobalNotFound ? findGlobalNotFoundRouteId(this.options.notFoundMode, matchedRoutes) : void 0;
1126
- const matches = [];
1127
- const getParentContext = (parentMatch) => {
1128
- const parentMatchId = parentMatch?.id;
1129
- const parentContext = !parentMatchId ? this.options.context ?? void 0 : parentMatch.context ?? this.options.context ?? void 0;
1130
- return parentContext;
1131
- };
1132
- matchedRoutes.forEach((route, index) => {
1131
+ const matches = new Array(matchedRoutes.length);
1132
+ for (let index = 0; index < matchedRoutes.length; index++) {
1133
+ const route = matchedRoutes[index];
1133
1134
  const parentMatch = matches[index - 1];
1134
- const [preMatchSearch, strictMatchSearch, searchError] = (() => {
1135
+ let preMatchSearch;
1136
+ let strictMatchSearch;
1137
+ let searchError;
1138
+ {
1135
1139
  const parentSearch = parentMatch?.search ?? next.search;
1136
1140
  const parentStrictSearch = parentMatch?._strictSearch ?? void 0;
1137
1141
  try {
1138
1142
  const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ?? void 0;
1139
- return [
1140
- {
1141
- ...parentSearch,
1142
- ...strictSearch
1143
- },
1144
- { ...parentStrictSearch, ...strictSearch },
1145
- void 0
1146
- ];
1143
+ preMatchSearch = {
1144
+ ...parentSearch,
1145
+ ...strictSearch
1146
+ };
1147
+ strictMatchSearch = { ...parentStrictSearch, ...strictSearch };
1148
+ searchError = void 0;
1147
1149
  } catch (err) {
1148
1150
  let searchParamError = err;
1149
1151
  if (!(err instanceof SearchParamError)) {
@@ -1154,9 +1156,11 @@ class RouterCore {
1154
1156
  if (opts?.throwOnError) {
1155
1157
  throw searchParamError;
1156
1158
  }
1157
- return [parentSearch, {}, searchParamError];
1159
+ preMatchSearch = parentSearch;
1160
+ strictMatchSearch = {};
1161
+ searchError = searchParamError;
1158
1162
  }
1159
- })();
1163
+ }
1160
1164
  const loaderDeps = route.options.loaderDeps?.({
1161
1165
  search: preMatchSearch
1162
1166
  }) ?? "";
@@ -1249,20 +1253,21 @@ class RouterCore {
1249
1253
  match.globalNotFound = globalNotFoundRouteId === route.id;
1250
1254
  }
1251
1255
  match.searchError = searchError;
1252
- const parentContext = getParentContext(parentMatch);
1256
+ const parentContext = this.getParentContext(parentMatch);
1253
1257
  match.context = {
1254
1258
  ...parentContext,
1255
1259
  ...match.__routeContext,
1256
1260
  ...match.__beforeLoadContext
1257
1261
  };
1258
- matches.push(match);
1259
- });
1260
- matches.forEach((match, index) => {
1262
+ matches[index] = match;
1263
+ }
1264
+ for (let index = 0; index < matches.length; index++) {
1265
+ const match = matches[index];
1261
1266
  const route = this.looseRoutesById[match.routeId];
1262
1267
  const existingMatch = this.getMatch(match.id);
1263
1268
  if (!existingMatch) {
1264
1269
  const parentMatch = matches[index - 1];
1265
- const parentContext = getParentContext(parentMatch);
1270
+ const parentContext = this.getParentContext(parentMatch);
1266
1271
  if (route.options.context) {
1267
1272
  const contextFnContext = {
1268
1273
  deps: match.loaderDeps,
@@ -1284,7 +1289,7 @@ class RouterCore {
1284
1289
  ...match.__beforeLoadContext
1285
1290
  };
1286
1291
  }
1287
- });
1292
+ }
1288
1293
  return matches;
1289
1294
  }
1290
1295
  /**