@tanstack/react-router 0.0.1-beta.12 → 0.0.1-beta.13

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.
@@ -1396,7 +1396,7 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
1396
1396
  };
1397
1397
  };
1398
1398
 
1399
- const elementTypes = ['element', 'errorElement', 'catchElement', 'pendingElement'];
1399
+ const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
1400
1400
  function createRouteMatch(router, route, opts) {
1401
1401
  const routeMatch = _extends({}, route, opts, {
1402
1402
  router,
@@ -1406,7 +1406,6 @@ function createRouteMatch(router, route, opts) {
1406
1406
  status: 'idle',
1407
1407
  routeLoaderData: {},
1408
1408
  loaderData: {},
1409
- isPending: false,
1410
1409
  isFetching: false,
1411
1410
  isInvalid: false,
1412
1411
  invalidAt: Infinity,
@@ -1424,32 +1423,6 @@ function createRouteMatch(router, route, opts) {
1424
1423
 
1425
1424
  routeMatch.router.notify();
1426
1425
  },
1427
- startPending: () => {
1428
- var _routeMatch$options$p, _routeMatch$options$p2;
1429
-
1430
- const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
1431
- const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
1432
-
1433
- if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
1434
- return;
1435
- }
1436
-
1437
- routeMatch.__.pendingTimeout = setTimeout(() => {
1438
- routeMatch.isPending = true;
1439
-
1440
- routeMatch.__.resolve();
1441
-
1442
- if (typeof pendingMinMs !== 'undefined') {
1443
- routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
1444
- }
1445
- }, pendingMs);
1446
- },
1447
- cancelPending: () => {
1448
- routeMatch.isPending = false;
1449
- clearTimeout(routeMatch.__.pendingTimeout);
1450
- clearTimeout(routeMatch.__.pendingMinTimeout);
1451
- delete routeMatch.__.pendingMinPromise;
1452
- },
1453
1426
  validate: () => {
1454
1427
  var _routeMatch$parentMat, _routeMatch$parentMat2;
1455
1428
 
@@ -1469,11 +1442,11 @@ function createRouteMatch(router, route, opts) {
1469
1442
 
1470
1443
  routeMatch.routeSearch = nextSearch;
1471
1444
  routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
1472
- elementTypes.map(async type => {
1473
- const routeElement = routeMatch.options[type];
1445
+ componentTypes.map(async type => {
1446
+ const component = routeMatch.options[type];
1474
1447
 
1475
1448
  if (typeof routeMatch.__[type] !== 'function') {
1476
- routeMatch.__[type] = routeElement;
1449
+ routeMatch.__[type] = component;
1477
1450
  }
1478
1451
  });
1479
1452
  } catch (err) {
@@ -1493,14 +1466,16 @@ function createRouteMatch(router, route, opts) {
1493
1466
  var _routeMatch$__$abortC;
1494
1467
 
1495
1468
  (_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
1496
-
1497
- routeMatch.__.cancelPending();
1498
1469
  },
1499
1470
  invalidate: () => {
1500
1471
  routeMatch.isInvalid = true;
1501
1472
  },
1502
1473
  hasLoaders: () => {
1503
- return !!(route.options.loader || elementTypes.some(d => typeof route.options[d] === 'function'));
1474
+ return !!(route.options.loader || componentTypes.some(d => {
1475
+ var _route$options$d;
1476
+
1477
+ return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
1478
+ }));
1504
1479
  },
1505
1480
  load: async loaderOpts => {
1506
1481
  const now = Date.now();
@@ -1544,91 +1519,79 @@ function createRouteMatch(router, route, opts) {
1544
1519
  routeMatch.isFetching = true;
1545
1520
  routeMatch.__.resolve = resolve;
1546
1521
 
1547
- routeMatch.__.loaderDataPromise = (async () => {
1548
- // Load the elements and data in parallel
1549
- routeMatch.__.elementsPromise = (async () => {
1550
- // then run all element and data loaders in parallel
1551
- // For each element type, potentially load it asynchronously
1552
- await Promise.all(elementTypes.map(async type => {
1553
- const routeElement = routeMatch.options[type];
1522
+ routeMatch.__.componentsPromise = (async () => {
1523
+ // then run all component and data loaders in parallel
1524
+ // For each component type, potentially load it asynchronously
1525
+ await Promise.all(componentTypes.map(async type => {
1526
+ var _routeMatch$__$type;
1554
1527
 
1555
- if (typeof routeMatch.__[type] === 'function') {
1556
- routeMatch.__[type] = await router.options.createElement(routeElement);
1557
- }
1558
- }));
1559
- })();
1560
-
1561
- routeMatch.__.dataPromise = Promise.resolve().then(async () => {
1562
- try {
1563
- var _ref, _ref2, _opts$maxAge;
1564
-
1565
- if (routeMatch.options.loader) {
1566
- const data = await routeMatch.options.loader({
1567
- params: routeMatch.params,
1568
- search: routeMatch.routeSearch,
1569
- signal: routeMatch.__.abortController.signal
1570
- });
1571
-
1572
- if (id !== routeMatch.__.latestId) {
1573
- return routeMatch.__.loadPromise;
1574
- }
1528
+ const component = routeMatch.options[type];
1575
1529
 
1576
- routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1577
- }
1530
+ if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
1531
+ routeMatch.__[type] = await router.options.loadComponent(component);
1532
+ }
1533
+ }));
1534
+ })();
1535
+
1536
+ routeMatch.__.dataPromise = Promise.resolve().then(async () => {
1537
+ try {
1538
+ var _ref, _ref2, _opts$maxAge;
1539
+
1540
+ if (routeMatch.options.loader) {
1541
+ const data = await routeMatch.options.loader({
1542
+ params: routeMatch.params,
1543
+ search: routeMatch.routeSearch,
1544
+ signal: routeMatch.__.abortController.signal
1545
+ });
1578
1546
 
1579
- routeMatch.error = undefined;
1580
- routeMatch.status = 'success';
1581
- routeMatch.updatedAt = Date.now();
1582
- routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
1583
- } catch (err) {
1584
1547
  if (id !== routeMatch.__.latestId) {
1585
1548
  return routeMatch.__.loadPromise;
1586
1549
  }
1587
1550
 
1588
- if (process.env.NODE_ENV !== 'production') {
1589
- console.error(err);
1590
- }
1591
-
1592
- routeMatch.error = err;
1593
- routeMatch.status = 'error';
1594
- routeMatch.updatedAt = Date.now();
1551
+ routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1595
1552
  }
1596
- });
1597
-
1598
- try {
1599
- await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
1600
1553
 
1554
+ routeMatch.error = undefined;
1555
+ routeMatch.status = 'success';
1556
+ routeMatch.updatedAt = Date.now();
1557
+ routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
1558
+ } catch (err) {
1601
1559
  if (id !== routeMatch.__.latestId) {
1602
1560
  return routeMatch.__.loadPromise;
1603
1561
  }
1604
1562
 
1605
- if (routeMatch.__.pendingMinPromise) {
1606
- await routeMatch.__.pendingMinPromise;
1607
- delete routeMatch.__.pendingMinPromise;
1608
- }
1609
- } finally {
1610
- if (id !== routeMatch.__.latestId) {
1611
- return routeMatch.__.loadPromise;
1563
+ if (process.env.NODE_ENV !== 'production') {
1564
+ console.error(err);
1612
1565
  }
1613
1566
 
1614
- routeMatch.__.cancelPending();
1567
+ routeMatch.error = err;
1568
+ routeMatch.status = 'error';
1569
+ routeMatch.updatedAt = Date.now();
1570
+ }
1571
+ });
1615
1572
 
1616
- routeMatch.isPending = false;
1617
- routeMatch.isFetching = false;
1573
+ try {
1574
+ await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise]);
1618
1575
 
1619
- routeMatch.__.notify();
1576
+ if (id !== routeMatch.__.latestId) {
1577
+ return routeMatch.__.loadPromise;
1578
+ }
1579
+ } finally {
1580
+ if (id !== routeMatch.__.latestId) {
1581
+ return routeMatch.__.loadPromise;
1620
1582
  }
1621
- })();
1622
1583
 
1623
- await routeMatch.__.loaderDataPromise;
1584
+ routeMatch.isFetching = false;
1624
1585
 
1625
- if (id !== routeMatch.__.latestId) {
1626
- return routeMatch.__.loadPromise;
1586
+ routeMatch.__.notify();
1627
1587
  }
1628
-
1629
- delete routeMatch.__.loaderDataPromise;
1630
1588
  });
1631
1589
  await routeMatch.__.loadPromise;
1590
+
1591
+ if (id !== routeMatch.__.latestId) {
1592
+ return routeMatch.__.loadPromise;
1593
+ }
1594
+
1632
1595
  delete routeMatch.__.loadPromise;
1633
1596
  }
1634
1597
  });
@@ -1864,18 +1827,26 @@ function createRouter(userOptions) {
1864
1827
  const matches = router.matchRoutes(router.location.pathname, {
1865
1828
  strictParseParams: true
1866
1829
  });
1867
- router.state = _extends({}, router.state, {
1868
- pending: {
1830
+
1831
+ if (typeof document !== 'undefined') {
1832
+ router.state = _extends({}, router.state, {
1833
+ pending: {
1834
+ matches: matches,
1835
+ location: router.location
1836
+ },
1837
+ status: 'loading'
1838
+ });
1839
+ } else {
1840
+ router.state = _extends({}, router.state, {
1869
1841
  matches: matches,
1870
- location: router.location
1871
- },
1872
- status: 'loading'
1873
- });
1842
+ location: router.location,
1843
+ status: 'loading'
1844
+ });
1845
+ }
1846
+
1874
1847
  router.notify(); // Load the matches
1875
1848
 
1876
- await router.loadMatches(matches, {
1877
- withPending: true
1878
- });
1849
+ await router.loadMatches(matches);
1879
1850
 
1880
1851
  if (router.startedLoadingAt !== id) {
1881
1852
  // Ignore side-effects of match loading
@@ -2097,14 +2068,8 @@ function createRouter(userOptions) {
2097
2068
 
2098
2069
  match.load(loaderOpts);
2099
2070
 
2100
- if (match.status === 'loading') {
2101
- // If requested, start the pending timers
2102
- if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
2103
- }
2104
-
2105
2071
  if (match.__.loadPromise) {
2106
2072
  // Wait for the first sign of activity from the match
2107
- // This might be completion, error, or a pending state
2108
2073
  await match.__.loadPromise;
2109
2074
  }
2110
2075
  });