@tanstack/router-core 0.0.1-beta.177 → 0.0.1-beta.179
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/route.js.map +1 -1
- package/build/cjs/router.js +33 -45
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +33 -45
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +124 -124
- package/build/types/fileRoute.d.ts +0 -1
- package/build/types/route.d.ts +11 -10
- package/build/types/router.d.ts +2 -1
- package/build/umd/index.development.js +33 -45
- 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 +1 -1
- package/src/route.ts +36 -48
- package/src/router.ts +42 -49
package/build/esm/index.js
CHANGED
|
@@ -711,6 +711,7 @@ function stringifySearchWith(stringify, parser) {
|
|
|
711
711
|
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
712
712
|
const visibilityChangeEvent = 'visibilitychange';
|
|
713
713
|
const focusEvent = 'focus';
|
|
714
|
+
const preloadWarning = 'Error preloading route! ☝️';
|
|
714
715
|
class Router {
|
|
715
716
|
#unsubHistory;
|
|
716
717
|
resetNextScroll = false;
|
|
@@ -1140,39 +1141,14 @@ class Router {
|
|
|
1140
1141
|
return parentSearchInfo;
|
|
1141
1142
|
}
|
|
1142
1143
|
})();
|
|
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
|
-
});
|
|
1144
|
+
Object.assign(match, searchInfo);
|
|
1170
1145
|
});
|
|
1171
1146
|
return matches;
|
|
1172
1147
|
};
|
|
1173
|
-
loadMatches = async (
|
|
1148
|
+
loadMatches = async (_resolvedMatches, opts) => {
|
|
1149
|
+
const getFreshMatches = () => _resolvedMatches.map(d => this.getRouteMatch(d.id));
|
|
1174
1150
|
if (!opts?.preload) {
|
|
1175
|
-
|
|
1151
|
+
getFreshMatches().forEach(match => {
|
|
1176
1152
|
// Update each match with its latest route data
|
|
1177
1153
|
this.setRouteMatch(match.id, s => ({
|
|
1178
1154
|
...s,
|
|
@@ -1192,7 +1168,8 @@ class Router {
|
|
|
1192
1168
|
|
|
1193
1169
|
// Check each match middleware to see if the route can be accessed
|
|
1194
1170
|
try {
|
|
1195
|
-
for (const [index, match] of
|
|
1171
|
+
for (const [index, match] of getFreshMatches().entries()) {
|
|
1172
|
+
const parentMatch = getFreshMatches()[index - 1];
|
|
1196
1173
|
const route = this.getRoute(match.routeId);
|
|
1197
1174
|
const handleError = (err, code) => {
|
|
1198
1175
|
err.routerCode = code;
|
|
@@ -1223,10 +1200,21 @@ class Router {
|
|
|
1223
1200
|
}
|
|
1224
1201
|
let didError = false;
|
|
1225
1202
|
try {
|
|
1226
|
-
await route.options.beforeLoad?.({
|
|
1203
|
+
const routeContext = (await route.options.beforeLoad?.({
|
|
1227
1204
|
...match,
|
|
1228
|
-
preload: !!opts?.preload
|
|
1229
|
-
|
|
1205
|
+
preload: !!opts?.preload,
|
|
1206
|
+
parentContext: parentMatch?.routeContext ?? {},
|
|
1207
|
+
context: parentMatch?.context ?? this?.options.context ?? {}
|
|
1208
|
+
})) ?? {};
|
|
1209
|
+
const context = {
|
|
1210
|
+
...(parentMatch?.context ?? this?.options.context),
|
|
1211
|
+
...routeContext
|
|
1212
|
+
};
|
|
1213
|
+
this.setRouteMatch(match.id, s => ({
|
|
1214
|
+
...s,
|
|
1215
|
+
context,
|
|
1216
|
+
routeContext
|
|
1217
|
+
}));
|
|
1230
1218
|
} catch (err) {
|
|
1231
1219
|
handleError(err, 'BEFORE_LOAD');
|
|
1232
1220
|
didError = true;
|
|
@@ -1243,7 +1231,7 @@ class Router {
|
|
|
1243
1231
|
}
|
|
1244
1232
|
throw err;
|
|
1245
1233
|
}
|
|
1246
|
-
const validResolvedMatches =
|
|
1234
|
+
const validResolvedMatches = getFreshMatches().slice(0, firstBadMatchIndex);
|
|
1247
1235
|
const matchPromises = [];
|
|
1248
1236
|
validResolvedMatches.forEach((match, index) => {
|
|
1249
1237
|
matchPromises.push((async () => {
|
|
@@ -1452,14 +1440,14 @@ class Router {
|
|
|
1452
1440
|
if (preload) {
|
|
1453
1441
|
this.preloadRoute(nextOpts).catch(err => {
|
|
1454
1442
|
console.warn(err);
|
|
1455
|
-
console.warn(
|
|
1443
|
+
console.warn(preloadWarning);
|
|
1456
1444
|
});
|
|
1457
1445
|
}
|
|
1458
1446
|
};
|
|
1459
1447
|
const handleTouchStart = e => {
|
|
1460
1448
|
this.preloadRoute(nextOpts).catch(err => {
|
|
1461
1449
|
console.warn(err);
|
|
1462
|
-
console.warn(
|
|
1450
|
+
console.warn(preloadWarning);
|
|
1463
1451
|
});
|
|
1464
1452
|
};
|
|
1465
1453
|
const handleEnter = e => {
|
|
@@ -1472,7 +1460,7 @@ class Router {
|
|
|
1472
1460
|
target.preloadTimeout = null;
|
|
1473
1461
|
this.preloadRoute(nextOpts).catch(err => {
|
|
1474
1462
|
console.warn(err);
|
|
1475
|
-
console.warn(
|
|
1463
|
+
console.warn(preloadWarning);
|
|
1476
1464
|
});
|
|
1477
1465
|
}, preloadDelay);
|
|
1478
1466
|
}
|
|
@@ -1499,6 +1487,7 @@ class Router {
|
|
|
1499
1487
|
dehydrate = () => {
|
|
1500
1488
|
return {
|
|
1501
1489
|
state: {
|
|
1490
|
+
matchIds: this.state.matchIds,
|
|
1502
1491
|
dehydratedMatches: this.state.matches.map(d => pick(d, ['fetchedAt', 'invalid', 'preloadMaxAge', 'maxAge', 'id', 'loaderData', 'status', 'updatedAt']))
|
|
1503
1492
|
}
|
|
1504
1493
|
};
|
|
@@ -1513,11 +1502,9 @@ class Router {
|
|
|
1513
1502
|
const ctx = _ctx;
|
|
1514
1503
|
this.dehydratedData = ctx.payload;
|
|
1515
1504
|
this.options.hydrate?.(ctx.payload);
|
|
1516
|
-
const
|
|
1517
|
-
dehydratedMatches
|
|
1518
|
-
} = ctx.router.state;
|
|
1505
|
+
const dehydratedState = ctx.router.state;
|
|
1519
1506
|
let matches = this.matchRoutes(this.state.location.pathname, this.state.location.search).map(match => {
|
|
1520
|
-
const dehydratedMatch = dehydratedMatches.find(d => d.id === match.id);
|
|
1507
|
+
const dehydratedMatch = dehydratedState.dehydratedMatches.find(d => d.id === match.id);
|
|
1521
1508
|
invariant(dehydratedMatch, `Could not find a client-side match for dehydrated match with id: ${match.id}!`);
|
|
1522
1509
|
if (dehydratedMatch) {
|
|
1523
1510
|
return {
|
|
@@ -1530,6 +1517,7 @@ class Router {
|
|
|
1530
1517
|
this.__store.setState(s => {
|
|
1531
1518
|
return {
|
|
1532
1519
|
...s,
|
|
1520
|
+
matchIds: dehydratedState.matchIds,
|
|
1533
1521
|
matches,
|
|
1534
1522
|
matchesById: this.#mergeMatches(s.matchesById, matches)
|
|
1535
1523
|
};
|
|
@@ -1546,10 +1534,10 @@ class Router {
|
|
|
1546
1534
|
const id = `__TSR_DEHYDRATED__${strKey}`;
|
|
1547
1535
|
const data = typeof getData === 'function' ? await getData() : getData;
|
|
1548
1536
|
return `<script id='${id}' suppressHydrationWarning>window["__TSR_DEHYDRATED__${escapeJSON(strKey)}"] = ${JSON.stringify(data)}
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1537
|
+
;(() => {
|
|
1538
|
+
var el = document.getElementById('${id}')
|
|
1539
|
+
el.parentElement.removeChild(el)
|
|
1540
|
+
})()
|
|
1553
1541
|
</script>`;
|
|
1554
1542
|
});
|
|
1555
1543
|
return () => this.hydrateData(key);
|