@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.
@@ -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 = useRouterState().location.state.key;
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(RouterProviderInner, {
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
- // startReactTransition(() => {
1429
- try {
1430
- router.load();
1431
- } catch (err) {
1432
- console.error(err);
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 (router.state.location !== router.latestLocation) {
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 (router.state.location.href !== nextLocation.href) {
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 && router.state.resolvedLocation !== router.state.location) {
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: router.state.resolvedLocation,
1464
- toLocation: router.state.location,
1465
- pathChanged: router.state.location.href !== router.state.resolvedLocation?.href
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 /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
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);