@tanstack/router-core 0.0.1-beta.11 → 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/packages/router-core/src/routeConfig.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +57 -94
- package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -1
- package/build/cjs/packages/router-core/src/router.js +32 -21
- package/build/cjs/packages/router-core/src/router.js.map +1 -1
- package/build/esm/index.js +91 -117
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +131 -138
- package/build/types/index.d.ts +54 -72
- package/build/umd/index.development.js +91 -117
- 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 +1 -1
- package/src/frameworks.ts +1 -2
- package/src/index.ts +0 -1
- package/src/routeConfig.ts +7 -13
- package/src/routeMatch.ts +72 -130
- package/src/router.ts +50 -38
package/build/esm/index.js
CHANGED
|
@@ -1382,7 +1382,7 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
1382
1382
|
};
|
|
1383
1383
|
};
|
|
1384
1384
|
|
|
1385
|
-
const
|
|
1385
|
+
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
1386
1386
|
function createRouteMatch(router, route, opts) {
|
|
1387
1387
|
const routeMatch = _extends({}, route, opts, {
|
|
1388
1388
|
router,
|
|
@@ -1392,7 +1392,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1392
1392
|
status: 'idle',
|
|
1393
1393
|
routeLoaderData: {},
|
|
1394
1394
|
loaderData: {},
|
|
1395
|
-
isPending: false,
|
|
1396
1395
|
isFetching: false,
|
|
1397
1396
|
isInvalid: false,
|
|
1398
1397
|
invalidAt: Infinity,
|
|
@@ -1410,32 +1409,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1410
1409
|
|
|
1411
1410
|
routeMatch.router.notify();
|
|
1412
1411
|
},
|
|
1413
|
-
startPending: () => {
|
|
1414
|
-
var _routeMatch$options$p, _routeMatch$options$p2;
|
|
1415
|
-
|
|
1416
|
-
const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
|
|
1417
|
-
const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
|
|
1418
|
-
|
|
1419
|
-
if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
|
|
1420
|
-
return;
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
routeMatch.__.pendingTimeout = setTimeout(() => {
|
|
1424
|
-
routeMatch.isPending = true;
|
|
1425
|
-
|
|
1426
|
-
routeMatch.__.resolve();
|
|
1427
|
-
|
|
1428
|
-
if (typeof pendingMinMs !== 'undefined') {
|
|
1429
|
-
routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
|
|
1430
|
-
}
|
|
1431
|
-
}, pendingMs);
|
|
1432
|
-
},
|
|
1433
|
-
cancelPending: () => {
|
|
1434
|
-
routeMatch.isPending = false;
|
|
1435
|
-
clearTimeout(routeMatch.__.pendingTimeout);
|
|
1436
|
-
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1437
|
-
delete routeMatch.__.pendingMinPromise;
|
|
1438
|
-
},
|
|
1439
1412
|
validate: () => {
|
|
1440
1413
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1441
1414
|
|
|
@@ -1455,11 +1428,11 @@ function createRouteMatch(router, route, opts) {
|
|
|
1455
1428
|
|
|
1456
1429
|
routeMatch.routeSearch = nextSearch;
|
|
1457
1430
|
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1458
|
-
|
|
1459
|
-
const
|
|
1431
|
+
componentTypes.map(async type => {
|
|
1432
|
+
const component = routeMatch.options[type];
|
|
1460
1433
|
|
|
1461
1434
|
if (typeof routeMatch.__[type] !== 'function') {
|
|
1462
|
-
routeMatch.__[type] =
|
|
1435
|
+
routeMatch.__[type] = component;
|
|
1463
1436
|
}
|
|
1464
1437
|
});
|
|
1465
1438
|
} catch (err) {
|
|
@@ -1479,14 +1452,16 @@ function createRouteMatch(router, route, opts) {
|
|
|
1479
1452
|
var _routeMatch$__$abortC;
|
|
1480
1453
|
|
|
1481
1454
|
(_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
|
|
1482
|
-
|
|
1483
|
-
routeMatch.__.cancelPending();
|
|
1484
1455
|
},
|
|
1485
1456
|
invalidate: () => {
|
|
1486
1457
|
routeMatch.isInvalid = true;
|
|
1487
1458
|
},
|
|
1488
1459
|
hasLoaders: () => {
|
|
1489
|
-
return !!(route.options.loader ||
|
|
1460
|
+
return !!(route.options.loader || componentTypes.some(d => {
|
|
1461
|
+
var _route$options$d;
|
|
1462
|
+
|
|
1463
|
+
return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
|
|
1464
|
+
}));
|
|
1490
1465
|
},
|
|
1491
1466
|
load: async loaderOpts => {
|
|
1492
1467
|
const now = Date.now();
|
|
@@ -1530,91 +1505,79 @@ function createRouteMatch(router, route, opts) {
|
|
|
1530
1505
|
routeMatch.isFetching = true;
|
|
1531
1506
|
routeMatch.__.resolve = resolve;
|
|
1532
1507
|
|
|
1533
|
-
routeMatch.__.
|
|
1534
|
-
//
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
await Promise.all(elementTypes.map(async type => {
|
|
1539
|
-
const routeElement = routeMatch.options[type];
|
|
1508
|
+
routeMatch.__.componentsPromise = (async () => {
|
|
1509
|
+
// then run all component and data loaders in parallel
|
|
1510
|
+
// For each component type, potentially load it asynchronously
|
|
1511
|
+
await Promise.all(componentTypes.map(async type => {
|
|
1512
|
+
var _routeMatch$__$type;
|
|
1540
1513
|
|
|
1541
|
-
|
|
1542
|
-
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1543
|
-
}
|
|
1544
|
-
}));
|
|
1545
|
-
})();
|
|
1546
|
-
|
|
1547
|
-
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1548
|
-
try {
|
|
1549
|
-
var _ref, _ref2, _opts$maxAge;
|
|
1550
|
-
|
|
1551
|
-
if (routeMatch.options.loader) {
|
|
1552
|
-
const data = await routeMatch.options.loader({
|
|
1553
|
-
params: routeMatch.params,
|
|
1554
|
-
search: routeMatch.routeSearch,
|
|
1555
|
-
signal: routeMatch.__.abortController.signal
|
|
1556
|
-
});
|
|
1557
|
-
|
|
1558
|
-
if (id !== routeMatch.__.latestId) {
|
|
1559
|
-
return routeMatch.__.loadPromise;
|
|
1560
|
-
}
|
|
1514
|
+
const component = routeMatch.options[type];
|
|
1561
1515
|
|
|
1562
|
-
|
|
1563
|
-
|
|
1516
|
+
if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
|
|
1517
|
+
routeMatch.__[type] = await router.options.loadComponent(component);
|
|
1518
|
+
}
|
|
1519
|
+
}));
|
|
1520
|
+
})();
|
|
1521
|
+
|
|
1522
|
+
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1523
|
+
try {
|
|
1524
|
+
var _ref, _ref2, _opts$maxAge;
|
|
1525
|
+
|
|
1526
|
+
if (routeMatch.options.loader) {
|
|
1527
|
+
const data = await routeMatch.options.loader({
|
|
1528
|
+
params: routeMatch.params,
|
|
1529
|
+
search: routeMatch.routeSearch,
|
|
1530
|
+
signal: routeMatch.__.abortController.signal
|
|
1531
|
+
});
|
|
1564
1532
|
|
|
1565
|
-
routeMatch.error = undefined;
|
|
1566
|
-
routeMatch.status = 'success';
|
|
1567
|
-
routeMatch.updatedAt = Date.now();
|
|
1568
|
-
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);
|
|
1569
|
-
} catch (err) {
|
|
1570
1533
|
if (id !== routeMatch.__.latestId) {
|
|
1571
1534
|
return routeMatch.__.loadPromise;
|
|
1572
1535
|
}
|
|
1573
1536
|
|
|
1574
|
-
|
|
1575
|
-
console.error(err);
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
routeMatch.error = err;
|
|
1579
|
-
routeMatch.status = 'error';
|
|
1580
|
-
routeMatch.updatedAt = Date.now();
|
|
1537
|
+
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1581
1538
|
}
|
|
1582
|
-
});
|
|
1583
|
-
|
|
1584
|
-
try {
|
|
1585
|
-
await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
|
|
1586
1539
|
|
|
1540
|
+
routeMatch.error = undefined;
|
|
1541
|
+
routeMatch.status = 'success';
|
|
1542
|
+
routeMatch.updatedAt = Date.now();
|
|
1543
|
+
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);
|
|
1544
|
+
} catch (err) {
|
|
1587
1545
|
if (id !== routeMatch.__.latestId) {
|
|
1588
1546
|
return routeMatch.__.loadPromise;
|
|
1589
1547
|
}
|
|
1590
1548
|
|
|
1591
|
-
if (
|
|
1592
|
-
|
|
1593
|
-
delete routeMatch.__.pendingMinPromise;
|
|
1594
|
-
}
|
|
1595
|
-
} finally {
|
|
1596
|
-
if (id !== routeMatch.__.latestId) {
|
|
1597
|
-
return routeMatch.__.loadPromise;
|
|
1549
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1550
|
+
console.error(err);
|
|
1598
1551
|
}
|
|
1599
1552
|
|
|
1600
|
-
routeMatch.
|
|
1553
|
+
routeMatch.error = err;
|
|
1554
|
+
routeMatch.status = 'error';
|
|
1555
|
+
routeMatch.updatedAt = Date.now();
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1601
1558
|
|
|
1602
|
-
|
|
1603
|
-
|
|
1559
|
+
try {
|
|
1560
|
+
await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise]);
|
|
1604
1561
|
|
|
1605
|
-
|
|
1562
|
+
if (id !== routeMatch.__.latestId) {
|
|
1563
|
+
return routeMatch.__.loadPromise;
|
|
1564
|
+
}
|
|
1565
|
+
} finally {
|
|
1566
|
+
if (id !== routeMatch.__.latestId) {
|
|
1567
|
+
return routeMatch.__.loadPromise;
|
|
1606
1568
|
}
|
|
1607
|
-
})();
|
|
1608
1569
|
|
|
1609
|
-
|
|
1570
|
+
routeMatch.isFetching = false;
|
|
1610
1571
|
|
|
1611
|
-
|
|
1612
|
-
return routeMatch.__.loadPromise;
|
|
1572
|
+
routeMatch.__.notify();
|
|
1613
1573
|
}
|
|
1614
|
-
|
|
1615
|
-
delete routeMatch.__.loaderDataPromise;
|
|
1616
1574
|
});
|
|
1617
1575
|
await routeMatch.__.loadPromise;
|
|
1576
|
+
|
|
1577
|
+
if (id !== routeMatch.__.latestId) {
|
|
1578
|
+
return routeMatch.__.loadPromise;
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1618
1581
|
delete routeMatch.__.loadPromise;
|
|
1619
1582
|
}
|
|
1620
1583
|
});
|
|
@@ -1738,10 +1701,16 @@ function createRouter(userOptions) {
|
|
|
1738
1701
|
return router.routesById[id];
|
|
1739
1702
|
},
|
|
1740
1703
|
notify: () => {
|
|
1741
|
-
router.state
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1704
|
+
const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
|
|
1705
|
+
const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
|
|
1706
|
+
|
|
1707
|
+
if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
|
|
1708
|
+
router.state = _extends({}, router.state, {
|
|
1709
|
+
isFetching,
|
|
1710
|
+
isPreloading
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1745
1714
|
cascadeLoaderData(router.state.matches);
|
|
1746
1715
|
router.listeners.forEach(listener => listener(router));
|
|
1747
1716
|
},
|
|
@@ -1760,7 +1729,7 @@ function createRouter(userOptions) {
|
|
|
1760
1729
|
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1761
1730
|
Object.assign(match, dehydratedMatch);
|
|
1762
1731
|
});
|
|
1763
|
-
|
|
1732
|
+
matches.forEach(match => match.__.validate());
|
|
1764
1733
|
router.state = _extends({}, router.state, dehydratedState, {
|
|
1765
1734
|
matches
|
|
1766
1735
|
});
|
|
@@ -1776,8 +1745,11 @@ function createRouter(userOptions) {
|
|
|
1776
1745
|
|
|
1777
1746
|
if (next.href !== router.location.href) {
|
|
1778
1747
|
router.__.commitLocation(next, true);
|
|
1779
|
-
}
|
|
1748
|
+
}
|
|
1780
1749
|
|
|
1750
|
+
if (!router.state.matches.length) {
|
|
1751
|
+
router.load();
|
|
1752
|
+
}
|
|
1781
1753
|
|
|
1782
1754
|
const unsub = router.history.listen(event => {
|
|
1783
1755
|
router.load(router.__.parseLocation(event.location, router.location));
|
|
@@ -1850,18 +1822,26 @@ function createRouter(userOptions) {
|
|
|
1850
1822
|
const matches = router.matchRoutes(router.location.pathname, {
|
|
1851
1823
|
strictParseParams: true
|
|
1852
1824
|
});
|
|
1853
|
-
|
|
1854
|
-
|
|
1825
|
+
|
|
1826
|
+
if (typeof document !== 'undefined') {
|
|
1827
|
+
router.state = _extends({}, router.state, {
|
|
1828
|
+
pending: {
|
|
1829
|
+
matches: matches,
|
|
1830
|
+
location: router.location
|
|
1831
|
+
},
|
|
1832
|
+
status: 'loading'
|
|
1833
|
+
});
|
|
1834
|
+
} else {
|
|
1835
|
+
router.state = _extends({}, router.state, {
|
|
1855
1836
|
matches: matches,
|
|
1856
|
-
location: router.location
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
}
|
|
1837
|
+
location: router.location,
|
|
1838
|
+
status: 'loading'
|
|
1839
|
+
});
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1860
1842
|
router.notify(); // Load the matches
|
|
1861
1843
|
|
|
1862
|
-
await router.loadMatches(matches
|
|
1863
|
-
withPending: true
|
|
1864
|
-
});
|
|
1844
|
+
await router.loadMatches(matches);
|
|
1865
1845
|
|
|
1866
1846
|
if (router.startedLoadingAt !== id) {
|
|
1867
1847
|
// Ignore side-effects of match loading
|
|
@@ -2083,14 +2063,8 @@ function createRouter(userOptions) {
|
|
|
2083
2063
|
|
|
2084
2064
|
match.load(loaderOpts);
|
|
2085
2065
|
|
|
2086
|
-
if (match.status === 'loading') {
|
|
2087
|
-
// If requested, start the pending timers
|
|
2088
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
2066
|
if (match.__.loadPromise) {
|
|
2092
2067
|
// Wait for the first sign of activity from the match
|
|
2093
|
-
// This might be completion, error, or a pending state
|
|
2094
2068
|
await match.__.loadPromise;
|
|
2095
2069
|
}
|
|
2096
2070
|
});
|