@tanstack/router-core 0.0.1-beta.160 → 0.0.1-beta.161

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.
@@ -811,7 +811,6 @@
811
811
  onUpdate: () => {
812
812
  const prev = this.state;
813
813
  const next = this.__store.state;
814
- console.log(Object.values(next.matchesById).find(d => d.status === 'error'));
815
814
  const matchesByIdChanged = prev.matchesById !== next.matchesById;
816
815
  let matchesChanged;
817
816
  let pendingMatchesChanged;
@@ -1238,7 +1237,6 @@
1238
1237
  throw errorHandlerErr;
1239
1238
  }
1240
1239
  }
1241
- console.log('set error');
1242
1240
  this.setRouteMatch(match.id, s => ({
1243
1241
  ...s,
1244
1242
  error: err,
@@ -1291,17 +1289,17 @@
1291
1289
  const latest = this.getRouteMatch(match.id);
1292
1290
  return latest && latest.fetchedAt !== fetchedAt ? latest.loadPromise : undefined;
1293
1291
  };
1292
+ const handleIfRedirect = err => {
1293
+ if (isRedirect(err)) {
1294
+ if (!opts?.preload) {
1295
+ this.navigate(err);
1296
+ }
1297
+ return true;
1298
+ }
1299
+ return false;
1300
+ };
1294
1301
  const load = async () => {
1295
1302
  let latestPromise;
1296
- const handleError = err => {
1297
- if (isRedirect(err)) {
1298
- if (!opts?.preload) {
1299
- this.navigate(err);
1300
- }
1301
- return true;
1302
- }
1303
- return false;
1304
- };
1305
1303
  try {
1306
1304
  const componentsPromise = Promise.all(componentTypes.map(async type => {
1307
1305
  const component = route.options[type];
@@ -1318,39 +1316,48 @@
1318
1316
  if (latestPromise = checkLatest()) return await latestPromise;
1319
1317
  this.setRouteMatchData(match.id, () => loader, opts);
1320
1318
  } catch (loaderError) {
1319
+ let latestError = loaderError;
1321
1320
  if (latestPromise = checkLatest()) return await latestPromise;
1322
- handleError(loaderError);
1323
- let error = loaderError;
1324
- try {
1325
- if (route.options.onLoadError) {
1326
- route.options.onLoadError?.(loaderError);
1327
- } else {
1328
- route.options.onError?.(loaderError);
1321
+ if (handleIfRedirect(loaderError)) return;
1322
+ if (route.options.onLoadError) {
1323
+ try {
1324
+ route.options.onLoadError(loaderError);
1325
+ } catch (onLoadError) {
1326
+ latestError = onLoadError;
1327
+ if (handleIfRedirect(onLoadError)) return;
1328
+ }
1329
+ }
1330
+ if ((!route.options.onLoadError || latestError !== loaderError) && route.options.onError) {
1331
+ try {
1332
+ route.options.onError(latestError);
1333
+ } catch (onErrorError) {
1334
+ if (handleIfRedirect(onErrorError)) return;
1329
1335
  }
1330
- } catch (errorHandlerErr) {
1331
- error = errorHandlerErr;
1332
- handleError(error);
1333
1336
  }
1334
- console.log('set error');
1335
1337
  this.setRouteMatch(match.id, s => ({
1336
1338
  ...s,
1337
- error: error,
1339
+ error: loaderError,
1338
1340
  status: 'error',
1339
1341
  isFetching: false,
1340
1342
  updatedAt: Date.now()
1341
1343
  }));
1342
- console.log(this.getRouteMatch(match.id)?.status);
1343
1344
  }
1344
1345
  };
1345
- const loadPromise = load();
1346
- this.setRouteMatch(match.id, s => ({
1347
- ...s,
1348
- status: s.status !== 'success' ? 'pending' : s.status,
1349
- isFetching: true,
1350
- loadPromise,
1351
- fetchedAt,
1352
- invalid: false
1353
- }));
1346
+ let loadPromise;
1347
+ this.__store.batch(() => {
1348
+ this.setRouteMatch(match.id, s => ({
1349
+ ...s,
1350
+ // status: s.status !== 'success' ? 'pending' : s.status,
1351
+ isFetching: true,
1352
+ fetchedAt,
1353
+ invalid: false
1354
+ }));
1355
+ loadPromise = load();
1356
+ this.setRouteMatch(match.id, s => ({
1357
+ ...s,
1358
+ loadPromise
1359
+ }));
1360
+ });
1354
1361
  await loadPromise;
1355
1362
  })());
1356
1363
  });
@@ -1786,7 +1793,6 @@
1786
1793
  const updatedAt = opts?.updatedAt ?? Date.now();
1787
1794
  const preloadInvalidAt = updatedAt + (opts?.maxAge ?? route.options.preloadMaxAge ?? this.options.defaultPreloadMaxAge ?? 5000);
1788
1795
  const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? Infinity);
1789
- console.log('set success');
1790
1796
  this.setRouteMatch(id, s => ({
1791
1797
  ...s,
1792
1798
  error: undefined,