@tanstack/router-core 0.0.1-beta.10 → 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.
- 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 +22 -25
- package/build/cjs/packages/router-core/src/router.js.map +1 -1
- package/build/esm/index.js +81 -121
- 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 +81 -121
- 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 -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 +30 -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
|
});
|
|
@@ -1850,18 +1813,26 @@ function createRouter(userOptions) {
|
|
|
1850
1813
|
const matches = router.matchRoutes(router.location.pathname, {
|
|
1851
1814
|
strictParseParams: true
|
|
1852
1815
|
});
|
|
1853
|
-
|
|
1854
|
-
|
|
1816
|
+
|
|
1817
|
+
if (typeof document !== 'undefined') {
|
|
1818
|
+
router.state = _extends({}, router.state, {
|
|
1819
|
+
pending: {
|
|
1820
|
+
matches: matches,
|
|
1821
|
+
location: router.location
|
|
1822
|
+
},
|
|
1823
|
+
status: 'loading'
|
|
1824
|
+
});
|
|
1825
|
+
} else {
|
|
1826
|
+
router.state = _extends({}, router.state, {
|
|
1855
1827
|
matches: matches,
|
|
1856
|
-
location: router.location
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
}
|
|
1828
|
+
location: router.location,
|
|
1829
|
+
status: 'loading'
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1860
1833
|
router.notify(); // Load the matches
|
|
1861
1834
|
|
|
1862
|
-
await router.loadMatches(matches
|
|
1863
|
-
withPending: true
|
|
1864
|
-
});
|
|
1835
|
+
await router.loadMatches(matches);
|
|
1865
1836
|
|
|
1866
1837
|
if (router.startedLoadingAt !== id) {
|
|
1867
1838
|
// Ignore side-effects of match loading
|
|
@@ -1878,6 +1849,9 @@ function createRouter(userOptions) {
|
|
|
1878
1849
|
exiting.push(d);
|
|
1879
1850
|
}
|
|
1880
1851
|
});
|
|
1852
|
+
const entering = matches.filter(d => {
|
|
1853
|
+
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1854
|
+
});
|
|
1881
1855
|
const now = Date.now();
|
|
1882
1856
|
exiting.forEach(d => {
|
|
1883
1857
|
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
@@ -1885,12 +1859,7 @@ function createRouter(userOptions) {
|
|
|
1885
1859
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1886
1860
|
params: d.params,
|
|
1887
1861
|
search: d.routeSearch
|
|
1888
|
-
}); //
|
|
1889
|
-
// if (d.action) {
|
|
1890
|
-
// d.action.current = undefined
|
|
1891
|
-
// d.action.submissions = []
|
|
1892
|
-
// }
|
|
1893
|
-
// Clear idle error states when match leaves
|
|
1862
|
+
}); // Clear idle error states when match leaves
|
|
1894
1863
|
|
|
1895
1864
|
if (d.status === 'error' && !d.isFetching) {
|
|
1896
1865
|
d.status = 'idle';
|
|
@@ -1912,16 +1881,13 @@ function createRouter(userOptions) {
|
|
|
1912
1881
|
search: d.routeSearch
|
|
1913
1882
|
});
|
|
1914
1883
|
});
|
|
1915
|
-
const entering = matches.filter(d => {
|
|
1916
|
-
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1917
|
-
});
|
|
1918
1884
|
entering.forEach(d => {
|
|
1919
1885
|
d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
|
|
1920
1886
|
params: d.params,
|
|
1921
1887
|
search: d.search
|
|
1922
1888
|
});
|
|
1923
1889
|
delete router.matchCache[d.matchId];
|
|
1924
|
-
});
|
|
1890
|
+
});
|
|
1925
1891
|
|
|
1926
1892
|
if (router.startedLoadingAt !== id) {
|
|
1927
1893
|
// Ignore side-effects of match loading
|
|
@@ -2088,14 +2054,8 @@ function createRouter(userOptions) {
|
|
|
2088
2054
|
|
|
2089
2055
|
match.load(loaderOpts);
|
|
2090
2056
|
|
|
2091
|
-
if (match.status === 'loading') {
|
|
2092
|
-
// If requested, start the pending timers
|
|
2093
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
2057
|
if (match.__.loadPromise) {
|
|
2097
2058
|
// Wait for the first sign of activity from the match
|
|
2098
|
-
// This might be completion, error, or a pending state
|
|
2099
2059
|
await match.__.loadPromise;
|
|
2100
2060
|
}
|
|
2101
2061
|
});
|