@tanstack/react-router 0.0.1-beta.12 → 0.0.1-beta.14
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-router/src/index.js +81 -102
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/cjs/router-core/build/esm/index.js +91 -117
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +129 -180
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +43 -29
- package/build/types/index.d.ts +10 -3
- package/build/umd/index.development.js +136 -184
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -2
- package/src/index.tsx +60 -76
|
@@ -1396,7 +1396,7 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
1396
1396
|
};
|
|
1397
1397
|
};
|
|
1398
1398
|
|
|
1399
|
-
const
|
|
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
|
-
|
|
1473
|
-
const
|
|
1445
|
+
componentTypes.map(async type => {
|
|
1446
|
+
const component = routeMatch.options[type];
|
|
1474
1447
|
|
|
1475
1448
|
if (typeof routeMatch.__[type] !== 'function') {
|
|
1476
|
-
routeMatch.__[type] =
|
|
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 ||
|
|
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.__.
|
|
1548
|
-
//
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
1606
|
-
|
|
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.
|
|
1567
|
+
routeMatch.error = err;
|
|
1568
|
+
routeMatch.status = 'error';
|
|
1569
|
+
routeMatch.updatedAt = Date.now();
|
|
1570
|
+
}
|
|
1571
|
+
});
|
|
1615
1572
|
|
|
1616
|
-
|
|
1617
|
-
|
|
1573
|
+
try {
|
|
1574
|
+
await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise]);
|
|
1618
1575
|
|
|
1619
|
-
|
|
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
|
-
|
|
1584
|
+
routeMatch.isFetching = false;
|
|
1624
1585
|
|
|
1625
|
-
|
|
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
|
});
|
|
@@ -1752,10 +1715,16 @@ function createRouter(userOptions) {
|
|
|
1752
1715
|
return router.routesById[id];
|
|
1753
1716
|
},
|
|
1754
1717
|
notify: () => {
|
|
1755
|
-
router.state
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1718
|
+
const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
|
|
1719
|
+
const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
|
|
1720
|
+
|
|
1721
|
+
if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
|
|
1722
|
+
router.state = _extends({}, router.state, {
|
|
1723
|
+
isFetching,
|
|
1724
|
+
isPreloading
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1759
1728
|
cascadeLoaderData(router.state.matches);
|
|
1760
1729
|
router.listeners.forEach(listener => listener(router));
|
|
1761
1730
|
},
|
|
@@ -1774,7 +1743,7 @@ function createRouter(userOptions) {
|
|
|
1774
1743
|
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1775
1744
|
Object.assign(match, dehydratedMatch);
|
|
1776
1745
|
});
|
|
1777
|
-
|
|
1746
|
+
matches.forEach(match => match.__.validate());
|
|
1778
1747
|
router.state = _extends({}, router.state, dehydratedState, {
|
|
1779
1748
|
matches
|
|
1780
1749
|
});
|
|
@@ -1790,8 +1759,11 @@ function createRouter(userOptions) {
|
|
|
1790
1759
|
|
|
1791
1760
|
if (next.href !== router.location.href) {
|
|
1792
1761
|
router.__.commitLocation(next, true);
|
|
1793
|
-
}
|
|
1762
|
+
}
|
|
1794
1763
|
|
|
1764
|
+
if (!router.state.matches.length) {
|
|
1765
|
+
router.load();
|
|
1766
|
+
}
|
|
1795
1767
|
|
|
1796
1768
|
const unsub = router.history.listen(event => {
|
|
1797
1769
|
router.load(router.__.parseLocation(event.location, router.location));
|
|
@@ -1864,18 +1836,26 @@ function createRouter(userOptions) {
|
|
|
1864
1836
|
const matches = router.matchRoutes(router.location.pathname, {
|
|
1865
1837
|
strictParseParams: true
|
|
1866
1838
|
});
|
|
1867
|
-
|
|
1868
|
-
|
|
1839
|
+
|
|
1840
|
+
if (typeof document !== 'undefined') {
|
|
1841
|
+
router.state = _extends({}, router.state, {
|
|
1842
|
+
pending: {
|
|
1843
|
+
matches: matches,
|
|
1844
|
+
location: router.location
|
|
1845
|
+
},
|
|
1846
|
+
status: 'loading'
|
|
1847
|
+
});
|
|
1848
|
+
} else {
|
|
1849
|
+
router.state = _extends({}, router.state, {
|
|
1869
1850
|
matches: matches,
|
|
1870
|
-
location: router.location
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
}
|
|
1851
|
+
location: router.location,
|
|
1852
|
+
status: 'loading'
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1874
1856
|
router.notify(); // Load the matches
|
|
1875
1857
|
|
|
1876
|
-
await router.loadMatches(matches
|
|
1877
|
-
withPending: true
|
|
1878
|
-
});
|
|
1858
|
+
await router.loadMatches(matches);
|
|
1879
1859
|
|
|
1880
1860
|
if (router.startedLoadingAt !== id) {
|
|
1881
1861
|
// Ignore side-effects of match loading
|
|
@@ -2097,14 +2077,8 @@ function createRouter(userOptions) {
|
|
|
2097
2077
|
|
|
2098
2078
|
match.load(loaderOpts);
|
|
2099
2079
|
|
|
2100
|
-
if (match.status === 'loading') {
|
|
2101
|
-
// If requested, start the pending timers
|
|
2102
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2103
|
-
}
|
|
2104
|
-
|
|
2105
2080
|
if (match.__.loadPromise) {
|
|
2106
2081
|
// Wait for the first sign of activity from the match
|
|
2107
|
-
// This might be completion, error, or a pending state
|
|
2108
2082
|
await match.__.loadPromise;
|
|
2109
2083
|
}
|
|
2110
2084
|
});
|