@tanstack/react-router 0.0.1-beta.1 → 0.0.1-beta.10
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 +39 -69
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/cjs/router-core/build/esm/index.js +147 -118
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +185 -186
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +29 -29
- package/build/types/index.d.ts +6 -2
- package/build/umd/index.development.js +185 -186
- 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 -3
- package/src/index.tsx +58 -69
- package/src/qss.ts +0 -53
|
@@ -944,6 +944,12 @@ function functionalUpdate(updater, previous) {
|
|
|
944
944
|
|
|
945
945
|
return updater;
|
|
946
946
|
}
|
|
947
|
+
function pick(parent, keys) {
|
|
948
|
+
return keys.reduce((obj, key) => {
|
|
949
|
+
obj[key] = parent[key];
|
|
950
|
+
return obj;
|
|
951
|
+
}, {});
|
|
952
|
+
}
|
|
947
953
|
|
|
948
954
|
function joinPaths(paths) {
|
|
949
955
|
return cleanPath(paths.filter(Boolean).join('/'));
|
|
@@ -1170,6 +1176,7 @@ function toValue(mix) {
|
|
|
1170
1176
|
var str = decodeURIComponent(mix);
|
|
1171
1177
|
if (str === 'false') return false;
|
|
1172
1178
|
if (str === 'true') return true;
|
|
1179
|
+
if (str.charAt(0) === '0') return str;
|
|
1173
1180
|
return +str * 0 === 0 ? +str : str;
|
|
1174
1181
|
}
|
|
1175
1182
|
|
|
@@ -1220,7 +1227,7 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1220
1227
|
|
|
1221
1228
|
const action = router.state.actions[id] || (() => {
|
|
1222
1229
|
router.state.actions[id] = {
|
|
1223
|
-
|
|
1230
|
+
submissions: [],
|
|
1224
1231
|
submit: async (submission, actionOpts) => {
|
|
1225
1232
|
var _actionOpts$invalidat;
|
|
1226
1233
|
|
|
@@ -1229,18 +1236,20 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1229
1236
|
}
|
|
1230
1237
|
|
|
1231
1238
|
const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
|
|
1239
|
+
|
|
1240
|
+
if (!(actionOpts != null && actionOpts.multi)) {
|
|
1241
|
+
action.submissions = action.submissions.filter(d => d.isMulti);
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1232
1244
|
const actionState = {
|
|
1233
1245
|
submittedAt: Date.now(),
|
|
1234
1246
|
status: 'pending',
|
|
1235
|
-
submission
|
|
1247
|
+
submission,
|
|
1248
|
+
isMulti: !!(actionOpts != null && actionOpts.multi)
|
|
1236
1249
|
};
|
|
1237
1250
|
action.current = actionState;
|
|
1238
1251
|
action.latest = actionState;
|
|
1239
|
-
action.
|
|
1240
|
-
router.state = _extends({}, router.state, {
|
|
1241
|
-
currentAction: actionState,
|
|
1242
|
-
latestAction: actionState
|
|
1243
|
-
});
|
|
1252
|
+
action.submissions.push(actionState);
|
|
1244
1253
|
router.notify();
|
|
1245
1254
|
|
|
1246
1255
|
try {
|
|
@@ -1262,11 +1271,6 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1262
1271
|
actionState.error = err;
|
|
1263
1272
|
actionState.status = 'error';
|
|
1264
1273
|
} finally {
|
|
1265
|
-
action.pending = action.pending.filter(d => d !== actionState);
|
|
1266
|
-
router.removeActionQueue.push({
|
|
1267
|
-
action,
|
|
1268
|
-
actionState
|
|
1269
|
-
});
|
|
1270
1274
|
router.notify();
|
|
1271
1275
|
}
|
|
1272
1276
|
}
|
|
@@ -1341,15 +1345,6 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1341
1345
|
});
|
|
1342
1346
|
return route;
|
|
1343
1347
|
}
|
|
1344
|
-
function cascadeLoaderData(matches) {
|
|
1345
|
-
matches.forEach((match, index) => {
|
|
1346
|
-
const parent = matches[index - 1];
|
|
1347
|
-
|
|
1348
|
-
if (parent) {
|
|
1349
|
-
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
1350
|
-
}
|
|
1351
|
-
});
|
|
1352
|
-
}
|
|
1353
1348
|
|
|
1354
1349
|
const rootRouteId = '__root__';
|
|
1355
1350
|
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
@@ -1415,6 +1410,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1415
1410
|
isFetching: false,
|
|
1416
1411
|
isInvalid: false,
|
|
1417
1412
|
invalidAt: Infinity,
|
|
1413
|
+
// pendingActions: [],
|
|
1418
1414
|
getIsInvalid: () => {
|
|
1419
1415
|
const now = Date.now();
|
|
1420
1416
|
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
@@ -1454,17 +1450,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1454
1450
|
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1455
1451
|
delete routeMatch.__.pendingMinPromise;
|
|
1456
1452
|
},
|
|
1457
|
-
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
1458
|
-
// routeMatch.parentMatch = parentMatch
|
|
1459
|
-
// },
|
|
1460
|
-
// addChildMatch: (childMatch: RouteMatch) => {
|
|
1461
|
-
// if (
|
|
1462
|
-
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
1463
|
-
// ) {
|
|
1464
|
-
// return
|
|
1465
|
-
// }
|
|
1466
|
-
// routeMatch.childMatches.push(childMatch)
|
|
1467
|
-
// },
|
|
1468
1453
|
validate: () => {
|
|
1469
1454
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1470
1455
|
|
|
@@ -1472,9 +1457,11 @@ function createRouteMatch(router, route, opts) {
|
|
|
1472
1457
|
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
1473
1458
|
|
|
1474
1459
|
try {
|
|
1460
|
+
var _validator;
|
|
1461
|
+
|
|
1475
1462
|
const prevSearch = routeMatch.routeSearch;
|
|
1476
1463
|
const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
|
|
1477
|
-
let nextSearch = replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch)); // Invalidate route matches when search param stability changes
|
|
1464
|
+
let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
|
|
1478
1465
|
|
|
1479
1466
|
if (prevSearch !== nextSearch) {
|
|
1480
1467
|
routeMatch.isInvalid = true;
|
|
@@ -1482,6 +1469,13 @@ function createRouteMatch(router, route, opts) {
|
|
|
1482
1469
|
|
|
1483
1470
|
routeMatch.routeSearch = nextSearch;
|
|
1484
1471
|
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1472
|
+
elementTypes.map(async type => {
|
|
1473
|
+
const routeElement = routeMatch.options[type];
|
|
1474
|
+
|
|
1475
|
+
if (typeof routeMatch.__[type] !== 'function') {
|
|
1476
|
+
routeMatch.__[type] = routeElement;
|
|
1477
|
+
}
|
|
1478
|
+
});
|
|
1485
1479
|
} catch (err) {
|
|
1486
1480
|
console.error(err);
|
|
1487
1481
|
const error = new Error('Invalid search params found', {
|
|
@@ -1527,7 +1521,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1527
1521
|
|
|
1528
1522
|
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1529
1523
|
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1530
|
-
routeMatch.fetch({
|
|
1524
|
+
await routeMatch.fetch({
|
|
1531
1525
|
maxAge
|
|
1532
1526
|
});
|
|
1533
1527
|
}
|
|
@@ -1550,7 +1544,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1550
1544
|
routeMatch.isFetching = true;
|
|
1551
1545
|
routeMatch.__.resolve = resolve;
|
|
1552
1546
|
|
|
1553
|
-
|
|
1547
|
+
routeMatch.__.loaderDataPromise = (async () => {
|
|
1554
1548
|
// Load the elements and data in parallel
|
|
1555
1549
|
routeMatch.__.elementsPromise = (async () => {
|
|
1556
1550
|
// then run all element and data loaders in parallel
|
|
@@ -1558,11 +1552,9 @@ function createRouteMatch(router, route, opts) {
|
|
|
1558
1552
|
await Promise.all(elementTypes.map(async type => {
|
|
1559
1553
|
const routeElement = routeMatch.options[type];
|
|
1560
1554
|
|
|
1561
|
-
if (routeMatch.__[type]) {
|
|
1562
|
-
|
|
1555
|
+
if (typeof routeMatch.__[type] === 'function') {
|
|
1556
|
+
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1563
1557
|
}
|
|
1564
|
-
|
|
1565
|
-
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1566
1558
|
}));
|
|
1567
1559
|
})();
|
|
1568
1560
|
|
|
@@ -1578,7 +1570,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1578
1570
|
});
|
|
1579
1571
|
|
|
1580
1572
|
if (id !== routeMatch.__.latestId) {
|
|
1581
|
-
return routeMatch.__.
|
|
1573
|
+
return routeMatch.__.loadPromise;
|
|
1582
1574
|
}
|
|
1583
1575
|
|
|
1584
1576
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
@@ -1590,7 +1582,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1590
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);
|
|
1591
1583
|
} catch (err) {
|
|
1592
1584
|
if (id !== routeMatch.__.latestId) {
|
|
1593
|
-
return routeMatch.__.
|
|
1585
|
+
return routeMatch.__.loadPromise;
|
|
1594
1586
|
}
|
|
1595
1587
|
|
|
1596
1588
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -1607,7 +1599,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1607
1599
|
await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
|
|
1608
1600
|
|
|
1609
1601
|
if (id !== routeMatch.__.latestId) {
|
|
1610
|
-
return routeMatch.__.
|
|
1602
|
+
return routeMatch.__.loadPromise;
|
|
1611
1603
|
}
|
|
1612
1604
|
|
|
1613
1605
|
if (routeMatch.__.pendingMinPromise) {
|
|
@@ -1616,7 +1608,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1616
1608
|
}
|
|
1617
1609
|
} finally {
|
|
1618
1610
|
if (id !== routeMatch.__.latestId) {
|
|
1619
|
-
return routeMatch.__.
|
|
1611
|
+
return routeMatch.__.loadPromise;
|
|
1620
1612
|
}
|
|
1621
1613
|
|
|
1622
1614
|
routeMatch.__.cancelPending();
|
|
@@ -1628,16 +1620,16 @@ function createRouteMatch(router, route, opts) {
|
|
|
1628
1620
|
}
|
|
1629
1621
|
})();
|
|
1630
1622
|
|
|
1631
|
-
routeMatch.__.
|
|
1632
|
-
await loaderPromise;
|
|
1623
|
+
await routeMatch.__.loaderDataPromise;
|
|
1633
1624
|
|
|
1634
1625
|
if (id !== routeMatch.__.latestId) {
|
|
1635
|
-
return routeMatch.__.
|
|
1626
|
+
return routeMatch.__.loadPromise;
|
|
1636
1627
|
}
|
|
1637
1628
|
|
|
1638
|
-
delete routeMatch.__.
|
|
1629
|
+
delete routeMatch.__.loaderDataPromise;
|
|
1639
1630
|
});
|
|
1640
|
-
|
|
1631
|
+
await routeMatch.__.loadPromise;
|
|
1632
|
+
delete routeMatch.__.loadPromise;
|
|
1641
1633
|
}
|
|
1642
1634
|
});
|
|
1643
1635
|
|
|
@@ -1698,9 +1690,22 @@ function stringifySearchWith(stringify) {
|
|
|
1698
1690
|
|
|
1699
1691
|
var _window$document;
|
|
1700
1692
|
// Detect if we're in the DOM
|
|
1701
|
-
const isServer =
|
|
1693
|
+
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
|
|
1702
1694
|
|
|
1703
|
-
const createDefaultHistory = () =>
|
|
1695
|
+
const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
|
|
1696
|
+
|
|
1697
|
+
function getInitialRouterState() {
|
|
1698
|
+
return {
|
|
1699
|
+
status: 'idle',
|
|
1700
|
+
location: null,
|
|
1701
|
+
matches: [],
|
|
1702
|
+
actions: {},
|
|
1703
|
+
loaders: {},
|
|
1704
|
+
lastUpdated: Date.now(),
|
|
1705
|
+
isFetching: false,
|
|
1706
|
+
isPreloading: false
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1704
1709
|
|
|
1705
1710
|
function createRouter(userOptions) {
|
|
1706
1711
|
var _userOptions$stringif, _userOptions$parseSea;
|
|
@@ -1721,7 +1726,6 @@ function createRouter(userOptions) {
|
|
|
1721
1726
|
history,
|
|
1722
1727
|
options: originalOptions,
|
|
1723
1728
|
listeners: [],
|
|
1724
|
-
removeActionQueue: [],
|
|
1725
1729
|
// Resolved after construction
|
|
1726
1730
|
basepath: '',
|
|
1727
1731
|
routeTree: undefined,
|
|
@@ -1732,16 +1736,10 @@ function createRouter(userOptions) {
|
|
|
1732
1736
|
navigationPromise: Promise.resolve(),
|
|
1733
1737
|
resolveNavigation: () => {},
|
|
1734
1738
|
matchCache: {},
|
|
1735
|
-
state:
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
actions: {},
|
|
1740
|
-
loaders: {},
|
|
1741
|
-
loaderData: {},
|
|
1742
|
-
lastUpdated: Date.now(),
|
|
1743
|
-
isFetching: false,
|
|
1744
|
-
isPreloading: false
|
|
1739
|
+
state: getInitialRouterState(),
|
|
1740
|
+
reset: () => {
|
|
1741
|
+
router.state = getInitialRouterState();
|
|
1742
|
+
router.notify();
|
|
1745
1743
|
},
|
|
1746
1744
|
startedLoadingAt: Date.now(),
|
|
1747
1745
|
subscribe: listener => {
|
|
@@ -1759,7 +1757,27 @@ function createRouter(userOptions) {
|
|
|
1759
1757
|
isPreloading: Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId))
|
|
1760
1758
|
});
|
|
1761
1759
|
cascadeLoaderData(router.state.matches);
|
|
1762
|
-
router.listeners.forEach(listener => listener());
|
|
1760
|
+
router.listeners.forEach(listener => listener(router));
|
|
1761
|
+
},
|
|
1762
|
+
dehydrateState: () => {
|
|
1763
|
+
return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
|
|
1764
|
+
matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
1765
|
+
});
|
|
1766
|
+
},
|
|
1767
|
+
hydrateState: dehydratedState => {
|
|
1768
|
+
// Match the routes
|
|
1769
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1770
|
+
strictParseParams: true
|
|
1771
|
+
});
|
|
1772
|
+
matches.forEach((match, index) => {
|
|
1773
|
+
const dehydratedMatch = dehydratedState.matches[index];
|
|
1774
|
+
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1775
|
+
Object.assign(match, dehydratedMatch);
|
|
1776
|
+
});
|
|
1777
|
+
router.loadMatches(matches);
|
|
1778
|
+
router.state = _extends({}, router.state, dehydratedState, {
|
|
1779
|
+
matches
|
|
1780
|
+
});
|
|
1763
1781
|
},
|
|
1764
1782
|
mount: () => {
|
|
1765
1783
|
const next = router.__.buildLocation({
|
|
@@ -1772,12 +1790,11 @@ function createRouter(userOptions) {
|
|
|
1772
1790
|
|
|
1773
1791
|
if (next.href !== router.location.href) {
|
|
1774
1792
|
router.__.commitLocation(next, true);
|
|
1775
|
-
}
|
|
1776
|
-
router.loadLocation();
|
|
1777
|
-
}
|
|
1793
|
+
} // router.load()
|
|
1778
1794
|
|
|
1779
|
-
|
|
1780
|
-
|
|
1795
|
+
|
|
1796
|
+
const unsub = router.history.listen(event => {
|
|
1797
|
+
router.load(router.__.parseLocation(event.location, router.location));
|
|
1781
1798
|
}); // addEventListener does not exist in React Native, but window does
|
|
1782
1799
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1783
1800
|
|
|
@@ -1788,16 +1805,30 @@ function createRouter(userOptions) {
|
|
|
1788
1805
|
}
|
|
1789
1806
|
|
|
1790
1807
|
return () => {
|
|
1791
|
-
unsub();
|
|
1808
|
+
unsub();
|
|
1792
1809
|
|
|
1793
|
-
window.removeEventListener
|
|
1794
|
-
|
|
1810
|
+
if (!isServer && window.removeEventListener) {
|
|
1811
|
+
// Be sure to unsubscribe if a new handler is set
|
|
1812
|
+
window.removeEventListener('visibilitychange', router.onFocus);
|
|
1813
|
+
window.removeEventListener('focus', router.onFocus);
|
|
1814
|
+
}
|
|
1795
1815
|
};
|
|
1796
1816
|
},
|
|
1797
1817
|
onFocus: () => {
|
|
1798
|
-
router.
|
|
1818
|
+
router.load();
|
|
1799
1819
|
},
|
|
1800
1820
|
update: opts => {
|
|
1821
|
+
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
1822
|
+
|
|
1823
|
+
if (!router.location || newHistory) {
|
|
1824
|
+
if (opts != null && opts.history) {
|
|
1825
|
+
router.history = opts.history;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
router.location = router.__.parseLocation(router.history.location);
|
|
1829
|
+
router.state.location = router.location;
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1801
1832
|
Object.assign(router.options, opts);
|
|
1802
1833
|
const {
|
|
1803
1834
|
basepath,
|
|
@@ -1818,35 +1849,19 @@ function createRouter(userOptions) {
|
|
|
1818
1849
|
match.cancel();
|
|
1819
1850
|
});
|
|
1820
1851
|
},
|
|
1821
|
-
|
|
1852
|
+
load: async next => {
|
|
1822
1853
|
const id = Math.random();
|
|
1823
1854
|
router.startedLoadingAt = id;
|
|
1824
1855
|
|
|
1825
1856
|
if (next) {
|
|
1826
1857
|
// Ingest the new location
|
|
1827
1858
|
router.location = next;
|
|
1828
|
-
} //
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
router.removeActionQueue.forEach(_ref => {
|
|
1832
|
-
let {
|
|
1833
|
-
action,
|
|
1834
|
-
actionState
|
|
1835
|
-
} = _ref;
|
|
1859
|
+
} // Cancel any pending matches
|
|
1836
1860
|
|
|
1837
|
-
if (router.state.currentAction === actionState) {
|
|
1838
|
-
router.state.currentAction = undefined;
|
|
1839
|
-
}
|
|
1840
|
-
|
|
1841
|
-
if (action.current === actionState) {
|
|
1842
|
-
action.current = undefined;
|
|
1843
|
-
}
|
|
1844
|
-
});
|
|
1845
|
-
router.removeActionQueue = []; // Cancel any pending matches
|
|
1846
1861
|
|
|
1847
1862
|
router.cancelMatches(); // Match the routes
|
|
1848
1863
|
|
|
1849
|
-
const matches = router.matchRoutes(location.pathname, {
|
|
1864
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1850
1865
|
strictParseParams: true
|
|
1851
1866
|
});
|
|
1852
1867
|
router.state = _extends({}, router.state, {
|
|
@@ -1879,19 +1894,24 @@ function createRouter(userOptions) {
|
|
|
1879
1894
|
});
|
|
1880
1895
|
const now = Date.now();
|
|
1881
1896
|
exiting.forEach(d => {
|
|
1882
|
-
var
|
|
1897
|
+
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
1883
1898
|
|
|
1884
1899
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1885
1900
|
params: d.params,
|
|
1886
1901
|
search: d.routeSearch
|
|
1887
|
-
}); // Clear
|
|
1902
|
+
}); // // Clear actions
|
|
1903
|
+
// if (d.action) {
|
|
1904
|
+
// d.action.current = undefined
|
|
1905
|
+
// d.action.submissions = []
|
|
1906
|
+
// }
|
|
1907
|
+
// Clear idle error states when match leaves
|
|
1888
1908
|
|
|
1889
1909
|
if (d.status === 'error' && !d.isFetching) {
|
|
1890
1910
|
d.status = 'idle';
|
|
1891
1911
|
d.error = undefined;
|
|
1892
1912
|
}
|
|
1893
1913
|
|
|
1894
|
-
const gc = Math.max((
|
|
1914
|
+
const gc = Math.max((_ref = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref : 0, (_ref2 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref2 : 0);
|
|
1895
1915
|
|
|
1896
1916
|
if (gc > 0) {
|
|
1897
1917
|
router.matchCache[d.matchId] = {
|
|
@@ -1915,18 +1935,20 @@ function createRouter(userOptions) {
|
|
|
1915
1935
|
search: d.search
|
|
1916
1936
|
});
|
|
1917
1937
|
delete router.matchCache[d.matchId];
|
|
1918
|
-
});
|
|
1919
|
-
|
|
1920
|
-
if (matches.some(d => d.status === 'loading')) {
|
|
1921
|
-
router.notify();
|
|
1922
|
-
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
1923
|
-
}
|
|
1938
|
+
}); // router.notify()
|
|
1924
1939
|
|
|
1925
1940
|
if (router.startedLoadingAt !== id) {
|
|
1926
1941
|
// Ignore side-effects of match loading
|
|
1927
1942
|
return;
|
|
1928
1943
|
}
|
|
1929
1944
|
|
|
1945
|
+
matches.forEach(match => {
|
|
1946
|
+
// Clear actions
|
|
1947
|
+
if (match.action) {
|
|
1948
|
+
match.action.current = undefined;
|
|
1949
|
+
match.action.submissions = [];
|
|
1950
|
+
}
|
|
1951
|
+
});
|
|
1930
1952
|
router.state = _extends({}, router.state, {
|
|
1931
1953
|
location: router.location,
|
|
1932
1954
|
matches,
|
|
@@ -1967,7 +1989,7 @@ function createRouter(userOptions) {
|
|
|
1967
1989
|
return matches;
|
|
1968
1990
|
},
|
|
1969
1991
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
1970
|
-
var
|
|
1992
|
+
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
1971
1993
|
|
|
1972
1994
|
if (navigateOpts === void 0) {
|
|
1973
1995
|
navigateOpts = router.location;
|
|
@@ -1979,8 +2001,8 @@ function createRouter(userOptions) {
|
|
|
1979
2001
|
});
|
|
1980
2002
|
await router.loadMatches(matches, {
|
|
1981
2003
|
preload: true,
|
|
1982
|
-
maxAge: (
|
|
1983
|
-
gcMaxAge: (
|
|
2004
|
+
maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
|
|
2005
|
+
gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
|
|
1984
2006
|
});
|
|
1985
2007
|
return matches;
|
|
1986
2008
|
},
|
|
@@ -2082,9 +2104,12 @@ function createRouter(userOptions) {
|
|
|
2082
2104
|
|
|
2083
2105
|
if (match.status === 'loading') {
|
|
2084
2106
|
// If requested, start the pending timers
|
|
2085
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2086
|
-
|
|
2107
|
+
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2108
|
+
}
|
|
2087
2109
|
|
|
2110
|
+
if (match.__.loadPromise) {
|
|
2111
|
+
// Wait for the first sign of activity from the match
|
|
2112
|
+
// This might be completion, error, or a pending state
|
|
2088
2113
|
await match.__.loadPromise;
|
|
2089
2114
|
}
|
|
2090
2115
|
});
|
|
@@ -2135,7 +2160,7 @@ function createRouter(userOptions) {
|
|
|
2135
2160
|
to: next.pathname
|
|
2136
2161
|
}));
|
|
2137
2162
|
},
|
|
2138
|
-
navigate: async
|
|
2163
|
+
navigate: async _ref7 => {
|
|
2139
2164
|
let {
|
|
2140
2165
|
from,
|
|
2141
2166
|
to = '.',
|
|
@@ -2143,7 +2168,7 @@ function createRouter(userOptions) {
|
|
|
2143
2168
|
hash,
|
|
2144
2169
|
replace,
|
|
2145
2170
|
params
|
|
2146
|
-
} =
|
|
2171
|
+
} = _ref7;
|
|
2147
2172
|
// If this link simply reloads the current route,
|
|
2148
2173
|
// make sure it has a new key so it will trigger a data refresh
|
|
2149
2174
|
// If this `to` is a valid external URL, return
|
|
@@ -2167,8 +2192,8 @@ function createRouter(userOptions) {
|
|
|
2167
2192
|
params
|
|
2168
2193
|
});
|
|
2169
2194
|
},
|
|
2170
|
-
buildLink:
|
|
2171
|
-
var _preload,
|
|
2195
|
+
buildLink: _ref8 => {
|
|
2196
|
+
var _preload, _ref9;
|
|
2172
2197
|
|
|
2173
2198
|
let {
|
|
2174
2199
|
from,
|
|
@@ -2184,7 +2209,7 @@ function createRouter(userOptions) {
|
|
|
2184
2209
|
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2185
2210
|
preloadDelay: userPreloadDelay,
|
|
2186
2211
|
disabled
|
|
2187
|
-
} =
|
|
2212
|
+
} = _ref8;
|
|
2188
2213
|
|
|
2189
2214
|
// If this link simply reloads the current route,
|
|
2190
2215
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -2208,7 +2233,7 @@ function createRouter(userOptions) {
|
|
|
2208
2233
|
};
|
|
2209
2234
|
const next = router.buildNext(nextOpts);
|
|
2210
2235
|
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2211
|
-
const preloadDelay = (
|
|
2236
|
+
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
|
|
2212
2237
|
|
|
2213
2238
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2214
2239
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -2309,11 +2334,7 @@ function createRouter(userOptions) {
|
|
|
2309
2334
|
const recurseRoutes = (routeConfigs, parent) => {
|
|
2310
2335
|
return routeConfigs.map(routeConfig => {
|
|
2311
2336
|
const routeOptions = routeConfig.options;
|
|
2312
|
-
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2313
|
-
// pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
|
|
2314
|
-
// pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
|
|
2315
|
-
// }
|
|
2316
|
-
|
|
2337
|
+
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2317
2338
|
const existingRoute = router.routesById[route.routeId];
|
|
2318
2339
|
|
|
2319
2340
|
if (existingRoute) {
|
|
@@ -2448,8 +2469,6 @@ function createRouter(userOptions) {
|
|
|
2448
2469
|
}
|
|
2449
2470
|
}
|
|
2450
2471
|
};
|
|
2451
|
-
router.location = router.__.parseLocation(history.location);
|
|
2452
|
-
router.state.location = router.location;
|
|
2453
2472
|
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
2454
2473
|
|
|
2455
2474
|
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
@@ -2460,7 +2479,16 @@ function isCtrlEvent(e) {
|
|
|
2460
2479
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2461
2480
|
}
|
|
2462
2481
|
|
|
2463
|
-
|
|
2482
|
+
function cascadeLoaderData(matches) {
|
|
2483
|
+
matches.forEach((match, index) => {
|
|
2484
|
+
const parent = matches[index - 1];
|
|
2485
|
+
|
|
2486
|
+
if (parent) {
|
|
2487
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
2488
|
+
}
|
|
2489
|
+
});
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2464
2492
|
exports.cleanPath = cleanPath;
|
|
2465
2493
|
exports.createBrowserHistory = createBrowserHistory;
|
|
2466
2494
|
exports.createHashHistory = createHashHistory;
|
|
@@ -2482,6 +2510,7 @@ exports.matchByPath = matchByPath;
|
|
|
2482
2510
|
exports.matchPathname = matchPathname;
|
|
2483
2511
|
exports.parsePathname = parsePathname;
|
|
2484
2512
|
exports.parseSearchWith = parseSearchWith;
|
|
2513
|
+
exports.pick = pick;
|
|
2485
2514
|
exports.replaceEqualDeep = replaceEqualDeep;
|
|
2486
2515
|
exports.resolvePath = resolvePath;
|
|
2487
2516
|
exports.rootRouteId = rootRouteId;
|