@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.
- package/build/cjs/router.js +40 -34
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +40 -34
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +116 -116
- package/build/umd/index.development.js +40 -34
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +47 -40
package/build/esm/index.js
CHANGED
|
@@ -716,7 +716,6 @@ class Router {
|
|
|
716
716
|
onUpdate: () => {
|
|
717
717
|
const prev = this.state;
|
|
718
718
|
const next = this.__store.state;
|
|
719
|
-
console.log(Object.values(next.matchesById).find(d => d.status === 'error'));
|
|
720
719
|
const matchesByIdChanged = prev.matchesById !== next.matchesById;
|
|
721
720
|
let matchesChanged;
|
|
722
721
|
let pendingMatchesChanged;
|
|
@@ -1143,7 +1142,6 @@ class Router {
|
|
|
1143
1142
|
throw errorHandlerErr;
|
|
1144
1143
|
}
|
|
1145
1144
|
}
|
|
1146
|
-
console.log('set error');
|
|
1147
1145
|
this.setRouteMatch(match.id, s => ({
|
|
1148
1146
|
...s,
|
|
1149
1147
|
error: err,
|
|
@@ -1196,17 +1194,17 @@ class Router {
|
|
|
1196
1194
|
const latest = this.getRouteMatch(match.id);
|
|
1197
1195
|
return latest && latest.fetchedAt !== fetchedAt ? latest.loadPromise : undefined;
|
|
1198
1196
|
};
|
|
1197
|
+
const handleIfRedirect = err => {
|
|
1198
|
+
if (isRedirect(err)) {
|
|
1199
|
+
if (!opts?.preload) {
|
|
1200
|
+
this.navigate(err);
|
|
1201
|
+
}
|
|
1202
|
+
return true;
|
|
1203
|
+
}
|
|
1204
|
+
return false;
|
|
1205
|
+
};
|
|
1199
1206
|
const load = async () => {
|
|
1200
1207
|
let latestPromise;
|
|
1201
|
-
const handleError = err => {
|
|
1202
|
-
if (isRedirect(err)) {
|
|
1203
|
-
if (!opts?.preload) {
|
|
1204
|
-
this.navigate(err);
|
|
1205
|
-
}
|
|
1206
|
-
return true;
|
|
1207
|
-
}
|
|
1208
|
-
return false;
|
|
1209
|
-
};
|
|
1210
1208
|
try {
|
|
1211
1209
|
const componentsPromise = Promise.all(componentTypes.map(async type => {
|
|
1212
1210
|
const component = route.options[type];
|
|
@@ -1223,39 +1221,48 @@ class Router {
|
|
|
1223
1221
|
if (latestPromise = checkLatest()) return await latestPromise;
|
|
1224
1222
|
this.setRouteMatchData(match.id, () => loader, opts);
|
|
1225
1223
|
} catch (loaderError) {
|
|
1224
|
+
let latestError = loaderError;
|
|
1226
1225
|
if (latestPromise = checkLatest()) return await latestPromise;
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1226
|
+
if (handleIfRedirect(loaderError)) return;
|
|
1227
|
+
if (route.options.onLoadError) {
|
|
1228
|
+
try {
|
|
1229
|
+
route.options.onLoadError(loaderError);
|
|
1230
|
+
} catch (onLoadError) {
|
|
1231
|
+
latestError = onLoadError;
|
|
1232
|
+
if (handleIfRedirect(onLoadError)) return;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
if ((!route.options.onLoadError || latestError !== loaderError) && route.options.onError) {
|
|
1236
|
+
try {
|
|
1237
|
+
route.options.onError(latestError);
|
|
1238
|
+
} catch (onErrorError) {
|
|
1239
|
+
if (handleIfRedirect(onErrorError)) return;
|
|
1234
1240
|
}
|
|
1235
|
-
} catch (errorHandlerErr) {
|
|
1236
|
-
error = errorHandlerErr;
|
|
1237
|
-
handleError(error);
|
|
1238
1241
|
}
|
|
1239
|
-
console.log('set error');
|
|
1240
1242
|
this.setRouteMatch(match.id, s => ({
|
|
1241
1243
|
...s,
|
|
1242
|
-
error:
|
|
1244
|
+
error: loaderError,
|
|
1243
1245
|
status: 'error',
|
|
1244
1246
|
isFetching: false,
|
|
1245
1247
|
updatedAt: Date.now()
|
|
1246
1248
|
}));
|
|
1247
|
-
console.log(this.getRouteMatch(match.id)?.status);
|
|
1248
1249
|
}
|
|
1249
1250
|
};
|
|
1250
|
-
|
|
1251
|
-
this.
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1251
|
+
let loadPromise;
|
|
1252
|
+
this.__store.batch(() => {
|
|
1253
|
+
this.setRouteMatch(match.id, s => ({
|
|
1254
|
+
...s,
|
|
1255
|
+
// status: s.status !== 'success' ? 'pending' : s.status,
|
|
1256
|
+
isFetching: true,
|
|
1257
|
+
fetchedAt,
|
|
1258
|
+
invalid: false
|
|
1259
|
+
}));
|
|
1260
|
+
loadPromise = load();
|
|
1261
|
+
this.setRouteMatch(match.id, s => ({
|
|
1262
|
+
...s,
|
|
1263
|
+
loadPromise
|
|
1264
|
+
}));
|
|
1265
|
+
});
|
|
1259
1266
|
await loadPromise;
|
|
1260
1267
|
})());
|
|
1261
1268
|
});
|
|
@@ -1691,7 +1698,6 @@ class Router {
|
|
|
1691
1698
|
const updatedAt = opts?.updatedAt ?? Date.now();
|
|
1692
1699
|
const preloadInvalidAt = updatedAt + (opts?.maxAge ?? route.options.preloadMaxAge ?? this.options.defaultPreloadMaxAge ?? 5000);
|
|
1693
1700
|
const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? Infinity);
|
|
1694
|
-
console.log('set success');
|
|
1695
1701
|
this.setRouteMatch(id, s => ({
|
|
1696
1702
|
...s,
|
|
1697
1703
|
error: undefined,
|