@tanstack/react-router 0.0.1-beta.236 → 0.0.1-beta.237
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 +34 -19
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/esm/index.js +37 -24
- 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 +37 -24
- 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 +45 -20
|
@@ -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,9 +1401,11 @@
|
|
|
1403
1401
|
...rest?.context
|
|
1404
1402
|
}
|
|
1405
1403
|
});
|
|
1406
|
-
const inner = /*#__PURE__*/React__namespace.createElement(
|
|
1404
|
+
const inner = /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
|
|
1405
|
+
value: router
|
|
1406
|
+
}, /*#__PURE__*/React__namespace.createElement(RouterProviderInner, {
|
|
1407
1407
|
router: router
|
|
1408
|
-
});
|
|
1408
|
+
}));
|
|
1409
1409
|
if (router.options.Wrap) {
|
|
1410
1410
|
return /*#__PURE__*/React__namespace.createElement(router.options.Wrap, null, inner);
|
|
1411
1411
|
}
|
|
@@ -1414,6 +1414,13 @@
|
|
|
1414
1414
|
function RouterProviderInner({
|
|
1415
1415
|
router
|
|
1416
1416
|
}) {
|
|
1417
|
+
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(Matches, null), /*#__PURE__*/React__namespace.createElement(Transitioner, null));
|
|
1418
|
+
}
|
|
1419
|
+
function Transitioner() {
|
|
1420
|
+
const router = useRouter();
|
|
1421
|
+
const routerState = useRouterState({
|
|
1422
|
+
select: s => pick(s, ['isLoading', 'location', 'resolvedLocation', 'isTransitioning'])
|
|
1423
|
+
});
|
|
1417
1424
|
const [isTransitioning, startReactTransition] = React__namespace.useTransition();
|
|
1418
1425
|
router.startReactTransition = startReactTransition;
|
|
1419
1426
|
React__namespace.useEffect(() => {
|
|
@@ -1425,18 +1432,25 @@
|
|
|
1425
1432
|
}
|
|
1426
1433
|
}, [isTransitioning]);
|
|
1427
1434
|
const tryLoad = () => {
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
+
const apply = cb => {
|
|
1436
|
+
if (!routerState.isTransitioning) {
|
|
1437
|
+
startReactTransition(() => cb());
|
|
1438
|
+
} else {
|
|
1439
|
+
cb();
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
apply(() => {
|
|
1443
|
+
try {
|
|
1444
|
+
router.load();
|
|
1445
|
+
} catch (err) {
|
|
1446
|
+
console.error(err);
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1435
1449
|
};
|
|
1436
1450
|
useLayoutEffect$1(() => {
|
|
1437
1451
|
const unsub = router.history.subscribe(() => {
|
|
1438
1452
|
router.latestLocation = router.parseLocation(router.latestLocation);
|
|
1439
|
-
if (
|
|
1453
|
+
if (routerState.location !== router.latestLocation) {
|
|
1440
1454
|
tryLoad();
|
|
1441
1455
|
}
|
|
1442
1456
|
});
|
|
@@ -1446,7 +1460,7 @@
|
|
|
1446
1460
|
hash: true,
|
|
1447
1461
|
state: true
|
|
1448
1462
|
});
|
|
1449
|
-
if (
|
|
1463
|
+
if (routerState.location.href !== nextLocation.href) {
|
|
1450
1464
|
router.commitLocation({
|
|
1451
1465
|
...nextLocation,
|
|
1452
1466
|
replace: true
|
|
@@ -1457,12 +1471,13 @@
|
|
|
1457
1471
|
};
|
|
1458
1472
|
}, [router.history]);
|
|
1459
1473
|
useLayoutEffect$1(() => {
|
|
1460
|
-
if (!isTransitioning &&
|
|
1474
|
+
if (!isTransitioning && !routerState.isLoading && routerState.resolvedLocation !== routerState.location) {
|
|
1475
|
+
console.log('onResolved', routerState.location);
|
|
1461
1476
|
router.emit({
|
|
1462
1477
|
type: 'onResolved',
|
|
1463
|
-
fromLocation:
|
|
1464
|
-
toLocation:
|
|
1465
|
-
pathChanged:
|
|
1478
|
+
fromLocation: routerState.resolvedLocation,
|
|
1479
|
+
toLocation: routerState.location,
|
|
1480
|
+
pathChanged: routerState.location.href !== routerState.resolvedLocation?.href
|
|
1466
1481
|
});
|
|
1467
1482
|
router.pendingMatches = [];
|
|
1468
1483
|
router.__store.setState(s => ({
|
|
@@ -1471,15 +1486,13 @@
|
|
|
1471
1486
|
resolvedLocation: s.location
|
|
1472
1487
|
}));
|
|
1473
1488
|
}
|
|
1474
|
-
}, [isTransitioning]);
|
|
1489
|
+
}, [isTransitioning, routerState.isLoading]);
|
|
1475
1490
|
useLayoutEffect$1(() => {
|
|
1476
1491
|
if (!window.__TSR_DEHYDRATED__) {
|
|
1477
1492
|
tryLoad();
|
|
1478
1493
|
}
|
|
1479
1494
|
}, []);
|
|
1480
|
-
return
|
|
1481
|
-
value: router
|
|
1482
|
-
}, /*#__PURE__*/React__namespace.createElement(Matches, null));
|
|
1495
|
+
return null;
|
|
1483
1496
|
}
|
|
1484
1497
|
function getRouteMatch(state, id) {
|
|
1485
1498
|
return [...(state.pendingMatches ?? []), ...state.matches].find(d => d.id === id);
|