@tanstack/react-router 0.0.1-beta.236 → 0.0.1-beta.238
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/Matches.js +3 -5
- package/build/cjs/Matches.js.map +1 -1
- package/build/cjs/RouterProvider.js +31 -23
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/esm/index.js +34 -28
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/umd/index.development.js +34 -28
- 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/Matches.tsx +3 -3
- package/src/RouterProvider.tsx +38 -24
|
@@ -1199,13 +1199,11 @@
|
|
|
1199
1199
|
//
|
|
1200
1200
|
|
|
1201
1201
|
function Matches() {
|
|
1202
|
-
const
|
|
1203
|
-
routesById
|
|
1204
|
-
} = useRouter();
|
|
1202
|
+
const router = useRouter();
|
|
1205
1203
|
const routerState = useRouterState();
|
|
1206
1204
|
const matches = routerState.pendingMatches?.some(d => d.showPending) ? routerState.pendingMatches : routerState.matches;
|
|
1207
|
-
const locationKey =
|
|
1208
|
-
const route = routesById[rootRouteId];
|
|
1205
|
+
const locationKey = router.latestLocation.state.key;
|
|
1206
|
+
const route = router.routesById[rootRouteId];
|
|
1209
1207
|
const errorComponent = React__namespace.useCallback(props => {
|
|
1210
1208
|
return /*#__PURE__*/React__namespace.createElement(ErrorComponent, {
|
|
1211
1209
|
...props,
|
|
@@ -1403,17 +1401,19 @@
|
|
|
1403
1401
|
...rest?.context
|
|
1404
1402
|
}
|
|
1405
1403
|
});
|
|
1406
|
-
const inner = /*#__PURE__*/React__namespace.createElement(
|
|
1407
|
-
|
|
1408
|
-
});
|
|
1404
|
+
const inner = /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
|
|
1405
|
+
value: router
|
|
1406
|
+
}, /*#__PURE__*/React__namespace.createElement(Matches, null), /*#__PURE__*/React__namespace.createElement(Transitioner, null));
|
|
1409
1407
|
if (router.options.Wrap) {
|
|
1410
1408
|
return /*#__PURE__*/React__namespace.createElement(router.options.Wrap, null, inner);
|
|
1411
1409
|
}
|
|
1412
1410
|
return inner;
|
|
1413
1411
|
}
|
|
1414
|
-
function
|
|
1415
|
-
router
|
|
1416
|
-
|
|
1412
|
+
function Transitioner() {
|
|
1413
|
+
const router = useRouter();
|
|
1414
|
+
const routerState = useRouterState({
|
|
1415
|
+
select: s => pick(s, ['isLoading', 'location', 'resolvedLocation', 'isTransitioning'])
|
|
1416
|
+
});
|
|
1417
1417
|
const [isTransitioning, startReactTransition] = React__namespace.useTransition();
|
|
1418
1418
|
router.startReactTransition = startReactTransition;
|
|
1419
1419
|
React__namespace.useEffect(() => {
|
|
@@ -1425,18 +1425,25 @@
|
|
|
1425
1425
|
}
|
|
1426
1426
|
}, [isTransitioning]);
|
|
1427
1427
|
const tryLoad = () => {
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1428
|
+
const apply = cb => {
|
|
1429
|
+
if (!routerState.isTransitioning) {
|
|
1430
|
+
startReactTransition(() => cb());
|
|
1431
|
+
} else {
|
|
1432
|
+
cb();
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
apply(() => {
|
|
1436
|
+
try {
|
|
1437
|
+
router.load();
|
|
1438
|
+
} catch (err) {
|
|
1439
|
+
console.error(err);
|
|
1440
|
+
}
|
|
1441
|
+
});
|
|
1435
1442
|
};
|
|
1436
1443
|
useLayoutEffect$1(() => {
|
|
1437
1444
|
const unsub = router.history.subscribe(() => {
|
|
1438
1445
|
router.latestLocation = router.parseLocation(router.latestLocation);
|
|
1439
|
-
if (
|
|
1446
|
+
if (routerState.location !== router.latestLocation) {
|
|
1440
1447
|
tryLoad();
|
|
1441
1448
|
}
|
|
1442
1449
|
});
|
|
@@ -1446,7 +1453,7 @@
|
|
|
1446
1453
|
hash: true,
|
|
1447
1454
|
state: true
|
|
1448
1455
|
});
|
|
1449
|
-
if (
|
|
1456
|
+
if (routerState.location.href !== nextLocation.href) {
|
|
1450
1457
|
router.commitLocation({
|
|
1451
1458
|
...nextLocation,
|
|
1452
1459
|
replace: true
|
|
@@ -1457,12 +1464,13 @@
|
|
|
1457
1464
|
};
|
|
1458
1465
|
}, [router.history]);
|
|
1459
1466
|
useLayoutEffect$1(() => {
|
|
1460
|
-
if (!isTransitioning &&
|
|
1467
|
+
if (!isTransitioning && !routerState.isLoading && routerState.resolvedLocation !== routerState.location) {
|
|
1468
|
+
console.log('onResolved', routerState.location);
|
|
1461
1469
|
router.emit({
|
|
1462
1470
|
type: 'onResolved',
|
|
1463
|
-
fromLocation:
|
|
1464
|
-
toLocation:
|
|
1465
|
-
pathChanged:
|
|
1471
|
+
fromLocation: routerState.resolvedLocation,
|
|
1472
|
+
toLocation: routerState.location,
|
|
1473
|
+
pathChanged: routerState.location.href !== routerState.resolvedLocation?.href
|
|
1466
1474
|
});
|
|
1467
1475
|
router.pendingMatches = [];
|
|
1468
1476
|
router.__store.setState(s => ({
|
|
@@ -1471,15 +1479,13 @@
|
|
|
1471
1479
|
resolvedLocation: s.location
|
|
1472
1480
|
}));
|
|
1473
1481
|
}
|
|
1474
|
-
}, [isTransitioning]);
|
|
1482
|
+
}, [isTransitioning, routerState.isLoading]);
|
|
1475
1483
|
useLayoutEffect$1(() => {
|
|
1476
1484
|
if (!window.__TSR_DEHYDRATED__) {
|
|
1477
1485
|
tryLoad();
|
|
1478
1486
|
}
|
|
1479
1487
|
}, []);
|
|
1480
|
-
return
|
|
1481
|
-
value: router
|
|
1482
|
-
}, /*#__PURE__*/React__namespace.createElement(Matches, null));
|
|
1488
|
+
return null;
|
|
1483
1489
|
}
|
|
1484
1490
|
function getRouteMatch(state, id) {
|
|
1485
1491
|
return [...(state.pendingMatches ?? []), ...state.matches].find(d => d.id === id);
|