@tanstack/react-router 0.0.1-beta.192 → 0.0.1-beta.194
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/react.js +2 -14
- package/build/cjs/react.js.map +1 -1
- package/build/esm/index.js +2 -14
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +98 -98
- package/build/types/react.d.ts +28 -30
- package/build/umd/index.development.js +31 -32
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/react.tsx +73 -105
|
@@ -1246,12 +1246,19 @@
|
|
|
1246
1246
|
});
|
|
1247
1247
|
const matches = matchedRoutes.map((route, index) => {
|
|
1248
1248
|
const interpolatedPath = interpolatePath(route.path, routeParams);
|
|
1249
|
-
const
|
|
1250
|
-
params: routeParams,
|
|
1249
|
+
const loaderContext = route.options.loaderContext ? route.options.loaderContext({
|
|
1251
1250
|
search: locationSearch
|
|
1252
|
-
})
|
|
1253
|
-
const
|
|
1254
|
-
|
|
1251
|
+
}) : undefined;
|
|
1252
|
+
const matchId = JSON.stringify([interpolatePath(route.id, routeParams, true), loaderContext].filter(d => d !== undefined), (key, value) => {
|
|
1253
|
+
if (typeof value === 'function') {
|
|
1254
|
+
console.info(route);
|
|
1255
|
+
invariant(false, `Cannot return functions and other non-serializable values from routeOptions.loaderContext! Please use routeOptions.beforeLoad to do this. Route info is logged above 👆`);
|
|
1256
|
+
}
|
|
1257
|
+
if (typeof value === 'object' && value !== null) {
|
|
1258
|
+
return Object.fromEntries(Object.keys(value).sort().map(key => [key, value[key]]));
|
|
1259
|
+
}
|
|
1260
|
+
return value;
|
|
1261
|
+
});
|
|
1255
1262
|
|
|
1256
1263
|
// Waste not, want not. If we already have a match for this route,
|
|
1257
1264
|
// reuse it. This is important for layout routes, which might stick
|
|
@@ -1267,7 +1274,7 @@
|
|
|
1267
1274
|
const hasLoaders = !!(route.options.loader || componentTypes.some(d => route.options[d]?.preload));
|
|
1268
1275
|
const routeMatch = {
|
|
1269
1276
|
id: matchId,
|
|
1270
|
-
|
|
1277
|
+
loaderContext,
|
|
1271
1278
|
routeId: route.id,
|
|
1272
1279
|
params: routeParams,
|
|
1273
1280
|
pathname: joinPaths([this.basepath, interpolatedPath]),
|
|
@@ -1284,7 +1291,6 @@
|
|
|
1284
1291
|
searchError: undefined,
|
|
1285
1292
|
loaderData: undefined,
|
|
1286
1293
|
loadPromise: Promise.resolve(),
|
|
1287
|
-
routeContext: undefined,
|
|
1288
1294
|
context: undefined,
|
|
1289
1295
|
abortController: new AbortController(),
|
|
1290
1296
|
fetchedAt: 0
|
|
@@ -1341,7 +1347,6 @@
|
|
|
1341
1347
|
...s,
|
|
1342
1348
|
routeSearch: match.routeSearch,
|
|
1343
1349
|
search: match.search,
|
|
1344
|
-
routeContext: match.routeContext,
|
|
1345
1350
|
context: match.context,
|
|
1346
1351
|
error: match.error,
|
|
1347
1352
|
paramsError: match.paramsError,
|
|
@@ -1386,21 +1391,25 @@
|
|
|
1386
1391
|
handleError(match.searchError, 'VALIDATE_SEARCH');
|
|
1387
1392
|
}
|
|
1388
1393
|
let didError = false;
|
|
1394
|
+
const parentContext = parentMatch?.context ?? this?.options.context ?? {};
|
|
1389
1395
|
try {
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1396
|
+
const beforeLoadContext = (await route.options.beforeLoad?.({
|
|
1397
|
+
abortController: match.abortController,
|
|
1398
|
+
params: match.params,
|
|
1392
1399
|
preload: !!opts?.preload,
|
|
1393
|
-
|
|
1394
|
-
|
|
1400
|
+
context: {
|
|
1401
|
+
...parentContext,
|
|
1402
|
+
...match.loaderContext
|
|
1403
|
+
}
|
|
1395
1404
|
})) ?? {};
|
|
1396
1405
|
const context = {
|
|
1397
|
-
...
|
|
1398
|
-
...
|
|
1406
|
+
...parentContext,
|
|
1407
|
+
...match.loaderContext,
|
|
1408
|
+
...beforeLoadContext
|
|
1399
1409
|
};
|
|
1400
1410
|
this.setRouteMatch(match.id, s => ({
|
|
1401
1411
|
...s,
|
|
1402
|
-
context,
|
|
1403
|
-
routeContext
|
|
1412
|
+
context: replaceEqualDeep(s.context, context)
|
|
1404
1413
|
}));
|
|
1405
1414
|
} catch (err) {
|
|
1406
1415
|
handleError(err, 'BEFORE_LOAD');
|
|
@@ -1454,9 +1463,11 @@
|
|
|
1454
1463
|
}
|
|
1455
1464
|
}));
|
|
1456
1465
|
const loaderPromise = route.options.loader?.({
|
|
1457
|
-
|
|
1466
|
+
params: match.params,
|
|
1458
1467
|
preload: !!opts?.preload,
|
|
1459
|
-
parentMatchPromise
|
|
1468
|
+
parentMatchPromise,
|
|
1469
|
+
abortController: match.abortController,
|
|
1470
|
+
context: match.context
|
|
1460
1471
|
});
|
|
1461
1472
|
const [_, loader] = await Promise.all([componentsPromise, loaderPromise]);
|
|
1462
1473
|
if (latestPromise = checkLatest()) return await latestPromise;
|
|
@@ -2290,18 +2301,11 @@
|
|
|
2290
2301
|
from: route.id
|
|
2291
2302
|
});
|
|
2292
2303
|
},
|
|
2293
|
-
useContext: (opts = {}) => {
|
|
2294
|
-
return useMatch({
|
|
2295
|
-
...opts,
|
|
2296
|
-
from: route.id,
|
|
2297
|
-
select: d => opts?.select ? opts.select(d.context) : d.context
|
|
2298
|
-
});
|
|
2299
|
-
},
|
|
2300
2304
|
useRouteContext: (opts = {}) => {
|
|
2301
2305
|
return useMatch({
|
|
2302
2306
|
...opts,
|
|
2303
2307
|
from: route.id,
|
|
2304
|
-
select: d => opts?.select ? opts.select(d.
|
|
2308
|
+
select: d => opts?.select ? opts.select(d.context) : d.context
|
|
2305
2309
|
});
|
|
2306
2310
|
},
|
|
2307
2311
|
useSearch: (opts = {}) => {
|
|
@@ -2491,7 +2495,6 @@
|
|
|
2491
2495
|
return /*#__PURE__*/React__namespace.createElement(ErrorComponent, {
|
|
2492
2496
|
...props,
|
|
2493
2497
|
useMatch: route.useMatch,
|
|
2494
|
-
useContext: route.useContext,
|
|
2495
2498
|
useRouteContext: route.useRouteContext,
|
|
2496
2499
|
useSearch: route.useSearch,
|
|
2497
2500
|
useParams: route.useParams
|
|
@@ -2558,7 +2561,7 @@
|
|
|
2558
2561
|
function useRouteContext(opts) {
|
|
2559
2562
|
return useMatch({
|
|
2560
2563
|
...opts,
|
|
2561
|
-
select: match => opts?.select ? opts.select(match.
|
|
2564
|
+
select: match => opts?.select ? opts.select(match.context) : match.context
|
|
2562
2565
|
});
|
|
2563
2566
|
}
|
|
2564
2567
|
function useSearch(opts) {
|
|
@@ -2636,7 +2639,6 @@
|
|
|
2636
2639
|
return /*#__PURE__*/React__namespace.createElement(routeErrorComponent, {
|
|
2637
2640
|
...props,
|
|
2638
2641
|
useMatch: route.useMatch,
|
|
2639
|
-
useContext: route.useContext,
|
|
2640
2642
|
useRouteContext: route.useRouteContext,
|
|
2641
2643
|
useSearch: route.useSearch,
|
|
2642
2644
|
useParams: route.useParams
|
|
@@ -2647,7 +2649,6 @@
|
|
|
2647
2649
|
}, /*#__PURE__*/React__namespace.createElement(ResolvedSuspenseBoundary, {
|
|
2648
2650
|
fallback: /*#__PURE__*/React__namespace.createElement(PendingComponent, {
|
|
2649
2651
|
useMatch: route.useMatch,
|
|
2650
|
-
useContext: route.useContext,
|
|
2651
2652
|
useRouteContext: route.useRouteContext,
|
|
2652
2653
|
useSearch: route.useSearch,
|
|
2653
2654
|
useParams: route.useParams
|
|
@@ -2682,7 +2683,6 @@
|
|
|
2682
2683
|
return /*#__PURE__*/React__namespace.createElement(PendingComponent, {
|
|
2683
2684
|
useLoader: route.useLoader,
|
|
2684
2685
|
useMatch: route.useMatch,
|
|
2685
|
-
useContext: route.useContext,
|
|
2686
2686
|
useRouteContext: route.useRouteContext,
|
|
2687
2687
|
useSearch: route.useSearch,
|
|
2688
2688
|
useParams: route.useParams
|
|
@@ -2694,7 +2694,6 @@
|
|
|
2694
2694
|
return /*#__PURE__*/React__namespace.createElement(comp, {
|
|
2695
2695
|
useLoader: route.useLoader,
|
|
2696
2696
|
useMatch: route.useMatch,
|
|
2697
|
-
useContext: route.useContext,
|
|
2698
2697
|
useRouteContext: route.useRouteContext,
|
|
2699
2698
|
useSearch: route.useSearch,
|
|
2700
2699
|
useParams: route.useParams
|