@tanstack/router-core 0.0.1-beta.176 → 0.0.1-beta.178

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.
@@ -804,7 +804,7 @@ class Router {
804
804
  };
805
805
  #onFocus = () => {
806
806
  if (this.options.refetchOnWindowFocus ?? true) {
807
- this.reload();
807
+ this.invalidate();
808
808
  }
809
809
  };
810
810
  update = opts => {
@@ -1140,39 +1140,14 @@ class Router {
1140
1140
  return parentSearchInfo;
1141
1141
  }
1142
1142
  })();
1143
- Object.assign(match, {
1144
- ...searchInfo
1145
- });
1146
- const contextInfo = (() => {
1147
- try {
1148
- const routeContext = route.options.getContext?.({
1149
- parentContext: parentMatch?.routeContext ?? {},
1150
- context: parentMatch?.context ?? this?.options.context ?? {},
1151
- params: match.params,
1152
- search: match.search
1153
- }) || {};
1154
- const context = {
1155
- ...(parentMatch?.context ?? this?.options.context),
1156
- ...routeContext
1157
- };
1158
- return {
1159
- context,
1160
- routeContext
1161
- };
1162
- } catch (err) {
1163
- route.options.onError?.(err);
1164
- throw err;
1165
- }
1166
- })();
1167
- Object.assign(match, {
1168
- ...contextInfo
1169
- });
1143
+ Object.assign(match, searchInfo);
1170
1144
  });
1171
1145
  return matches;
1172
1146
  };
1173
- loadMatches = async (resolvedMatches, opts) => {
1147
+ loadMatches = async (_resolvedMatches, opts) => {
1148
+ const getFreshMatches = () => _resolvedMatches.map(d => this.getRouteMatch(d.id));
1174
1149
  if (!opts?.preload) {
1175
- resolvedMatches.forEach(match => {
1150
+ getFreshMatches().forEach(match => {
1176
1151
  // Update each match with its latest route data
1177
1152
  this.setRouteMatch(match.id, s => ({
1178
1153
  ...s,
@@ -1192,7 +1167,8 @@ class Router {
1192
1167
 
1193
1168
  // Check each match middleware to see if the route can be accessed
1194
1169
  try {
1195
- for (const [index, match] of resolvedMatches.entries()) {
1170
+ for (const [index, match] of getFreshMatches().entries()) {
1171
+ const parentMatch = getFreshMatches()[index - 1];
1196
1172
  const route = this.getRoute(match.routeId);
1197
1173
  const handleError = (err, code) => {
1198
1174
  err.routerCode = code;
@@ -1223,10 +1199,21 @@ class Router {
1223
1199
  }
1224
1200
  let didError = false;
1225
1201
  try {
1226
- await route.options.beforeLoad?.({
1202
+ const routeContext = (await route.options.beforeLoad?.({
1227
1203
  ...match,
1228
- preload: !!opts?.preload
1229
- });
1204
+ preload: !!opts?.preload,
1205
+ parentContext: parentMatch?.routeContext ?? {},
1206
+ context: parentMatch?.context ?? this?.options.context ?? {}
1207
+ })) ?? {};
1208
+ const context = {
1209
+ ...(parentMatch?.context ?? this?.options.context),
1210
+ ...routeContext
1211
+ };
1212
+ this.setRouteMatch(match.id, s => ({
1213
+ ...s,
1214
+ context,
1215
+ routeContext
1216
+ }));
1230
1217
  } catch (err) {
1231
1218
  handleError(err, 'BEFORE_LOAD');
1232
1219
  didError = true;
@@ -1243,7 +1230,7 @@ class Router {
1243
1230
  }
1244
1231
  throw err;
1245
1232
  }
1246
- const validResolvedMatches = resolvedMatches.slice(0, firstBadMatchIndex);
1233
+ const validResolvedMatches = getFreshMatches().slice(0, firstBadMatchIndex);
1247
1234
  const matchPromises = [];
1248
1235
  validResolvedMatches.forEach((match, index) => {
1249
1236
  matchPromises.push((async () => {
@@ -1323,13 +1310,6 @@ class Router {
1323
1310
  });
1324
1311
  await Promise.all(matchPromises);
1325
1312
  };
1326
- reload = () => {
1327
- return this.navigate({
1328
- fromCurrent: true,
1329
- replace: true,
1330
- search: true
1331
- });
1332
- };
1333
1313
  resolvePath = (from, path) => {
1334
1314
  return resolvePath(this.basepath, from, cleanPath(path));
1335
1315
  };
@@ -1807,7 +1787,11 @@ class Router {
1807
1787
  });
1808
1788
  }
1809
1789
  if (opts?.reload ?? true) {
1810
- return this.reload();
1790
+ return this.navigate({
1791
+ fromCurrent: true,
1792
+ replace: true,
1793
+ search: true
1794
+ });
1811
1795
  }
1812
1796
  };
1813
1797
  }