@tanstack/react-router 0.0.1-alpha.4 → 0.0.1-alpha.5
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/router-core/build/esm/index.js +58 -44
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +58 -44
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +27 -27
- package/build/umd/index.development.js +58 -44
- 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 -2
|
@@ -982,6 +982,7 @@ function createRouter(userOptions) {
|
|
|
982
982
|
let router = {
|
|
983
983
|
options: originalOptions,
|
|
984
984
|
listeners: [],
|
|
985
|
+
removeActionQueue: [],
|
|
985
986
|
// Resolved after construction
|
|
986
987
|
basepath: '',
|
|
987
988
|
routeTree: undefined,
|
|
@@ -1105,12 +1106,14 @@ function createRouter(userOptions) {
|
|
|
1105
1106
|
strictParseParams: true
|
|
1106
1107
|
});
|
|
1107
1108
|
const toMatches = router.matchRoutes(pathname);
|
|
1108
|
-
|
|
1109
|
+
|
|
1110
|
+
const prevParams = _extends$1({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
|
|
1111
|
+
|
|
1109
1112
|
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
1110
1113
|
|
|
1111
1114
|
if (nextParams) {
|
|
1112
1115
|
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
1113
|
-
Object.assign(nextParams, fn(nextParams));
|
|
1116
|
+
Object.assign({}, nextParams, fn(nextParams));
|
|
1114
1117
|
});
|
|
1115
1118
|
}
|
|
1116
1119
|
|
|
@@ -1213,22 +1216,33 @@ function createRouter(userOptions) {
|
|
|
1213
1216
|
router.startedLoadingAt = id;
|
|
1214
1217
|
|
|
1215
1218
|
if (next) {
|
|
1219
|
+
// If the location.href has changed
|
|
1216
1220
|
// Ingest the new location
|
|
1217
1221
|
router.location = next;
|
|
1218
|
-
} //
|
|
1222
|
+
} // Clear out old actions
|
|
1219
1223
|
|
|
1220
1224
|
|
|
1225
|
+
router.removeActionQueue.forEach(_ref => {
|
|
1226
|
+
let {
|
|
1227
|
+
action,
|
|
1228
|
+
actionState
|
|
1229
|
+
} = _ref;
|
|
1230
|
+
|
|
1231
|
+
if (router.state.currentAction === actionState) {
|
|
1232
|
+
router.state.currentAction = undefined;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
if (action.current === actionState) {
|
|
1236
|
+
action.current = undefined;
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
router.removeActionQueue = []; // Cancel any pending matches
|
|
1240
|
+
|
|
1221
1241
|
router.cancelMatches(); // Match the routes
|
|
1222
1242
|
|
|
1223
1243
|
const unloadedMatches = router.matchRoutes(location.pathname, {
|
|
1224
1244
|
strictParseParams: true
|
|
1225
1245
|
});
|
|
1226
|
-
unloadedMatches.forEach((match, index) => {
|
|
1227
|
-
const parent = unloadedMatches[index - 1];
|
|
1228
|
-
const child = unloadedMatches[index + 1];
|
|
1229
|
-
if (parent) match.__.setParentMatch(parent);
|
|
1230
|
-
if (child) match.__.addChildMatch(child);
|
|
1231
|
-
});
|
|
1232
1246
|
router.state = _extends$1({}, router.state, {
|
|
1233
1247
|
pending: {
|
|
1234
1248
|
matches: unloadedMatches,
|
|
@@ -1409,6 +1423,7 @@ function createRouter(userOptions) {
|
|
|
1409
1423
|
};
|
|
1410
1424
|
|
|
1411
1425
|
recurse([router.routeTree]);
|
|
1426
|
+
cascadeLoaderData(matches);
|
|
1412
1427
|
return matches;
|
|
1413
1428
|
},
|
|
1414
1429
|
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
@@ -1487,14 +1502,14 @@ function createRouter(userOptions) {
|
|
|
1487
1502
|
const next = router.buildNext(location);
|
|
1488
1503
|
return router.commitLocation(next, location.replace);
|
|
1489
1504
|
},
|
|
1490
|
-
navigate: async
|
|
1505
|
+
navigate: async _ref2 => {
|
|
1491
1506
|
let {
|
|
1492
1507
|
from,
|
|
1493
1508
|
to = '.',
|
|
1494
1509
|
search,
|
|
1495
1510
|
hash,
|
|
1496
1511
|
replace
|
|
1497
|
-
} =
|
|
1512
|
+
} = _ref2;
|
|
1498
1513
|
// If this link simply reloads the current route,
|
|
1499
1514
|
// make sure it has a new key so it will trigger a data refresh
|
|
1500
1515
|
// If this `to` is a valid external URL, return
|
|
@@ -1516,8 +1531,8 @@ function createRouter(userOptions) {
|
|
|
1516
1531
|
hash
|
|
1517
1532
|
});
|
|
1518
1533
|
},
|
|
1519
|
-
buildLink:
|
|
1520
|
-
var _preload,
|
|
1534
|
+
buildLink: _ref3 => {
|
|
1535
|
+
var _preload, _ref4, _ref5;
|
|
1521
1536
|
|
|
1522
1537
|
let {
|
|
1523
1538
|
from,
|
|
@@ -1532,7 +1547,7 @@ function createRouter(userOptions) {
|
|
|
1532
1547
|
preloadMaxAge: userPreloadMaxAge,
|
|
1533
1548
|
preloadDelay: userPreloadDelay,
|
|
1534
1549
|
disabled
|
|
1535
|
-
} =
|
|
1550
|
+
} = _ref3;
|
|
1536
1551
|
|
|
1537
1552
|
// If this link simply reloads the current route,
|
|
1538
1553
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -1556,8 +1571,8 @@ function createRouter(userOptions) {
|
|
|
1556
1571
|
};
|
|
1557
1572
|
const next = router.buildNext(nextOpts);
|
|
1558
1573
|
preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
|
|
1559
|
-
const preloadMaxAge = (
|
|
1560
|
-
const preloadDelay = (
|
|
1574
|
+
const preloadMaxAge = (_ref4 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref4 : 2000;
|
|
1575
|
+
const preloadDelay = (_ref5 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref5 : 50; // Compare path/hash for matches
|
|
1561
1576
|
|
|
1562
1577
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
1563
1578
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -1631,11 +1646,11 @@ function createRouter(userOptions) {
|
|
|
1631
1646
|
},
|
|
1632
1647
|
__experimental__createSnapshot: () => {
|
|
1633
1648
|
return _extends$1({}, router.state, {
|
|
1634
|
-
matches: router.state.matches.map(
|
|
1649
|
+
matches: router.state.matches.map(_ref6 => {
|
|
1635
1650
|
let {
|
|
1636
1651
|
routeLoaderData: loaderData,
|
|
1637
1652
|
matchId
|
|
1638
|
-
} =
|
|
1653
|
+
} = _ref6;
|
|
1639
1654
|
return {
|
|
1640
1655
|
matchId,
|
|
1641
1656
|
loaderData
|
|
@@ -1685,10 +1700,12 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1685
1700
|
status: 'pending',
|
|
1686
1701
|
submission
|
|
1687
1702
|
};
|
|
1703
|
+
action.current = actionState;
|
|
1688
1704
|
action.latest = actionState;
|
|
1689
1705
|
action.pending.push(actionState);
|
|
1690
1706
|
router.state = _extends$1({}, router.state, {
|
|
1691
|
-
|
|
1707
|
+
currentAction: actionState,
|
|
1708
|
+
latestAction: actionState
|
|
1692
1709
|
});
|
|
1693
1710
|
router.notify();
|
|
1694
1711
|
|
|
@@ -1712,11 +1729,10 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1712
1729
|
actionState.status = 'error';
|
|
1713
1730
|
} finally {
|
|
1714
1731
|
action.pending = action.pending.filter(d => d !== actionState);
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1732
|
+
router.removeActionQueue.push({
|
|
1733
|
+
action,
|
|
1734
|
+
actionState
|
|
1735
|
+
});
|
|
1720
1736
|
router.notify();
|
|
1721
1737
|
}
|
|
1722
1738
|
}
|
|
@@ -1803,16 +1819,17 @@ function createRouteMatch(router, route, opts) {
|
|
|
1803
1819
|
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1804
1820
|
delete routeMatch.__.pendingMinPromise;
|
|
1805
1821
|
},
|
|
1806
|
-
setParentMatch: parentMatch => {
|
|
1807
|
-
|
|
1808
|
-
},
|
|
1809
|
-
addChildMatch: childMatch => {
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1822
|
+
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
1823
|
+
// routeMatch.parentMatch = parentMatch
|
|
1824
|
+
// },
|
|
1825
|
+
// addChildMatch: (childMatch: RouteMatch) => {
|
|
1826
|
+
// if (
|
|
1827
|
+
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
1828
|
+
// ) {
|
|
1829
|
+
// return
|
|
1830
|
+
// }
|
|
1831
|
+
// routeMatch.childMatches.push(childMatch)
|
|
1832
|
+
// },
|
|
1816
1833
|
validate: () => {
|
|
1817
1834
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1818
1835
|
|
|
@@ -1916,7 +1933,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1916
1933
|
}
|
|
1917
1934
|
|
|
1918
1935
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1919
|
-
cascadeLoaderData(routeMatch);
|
|
1920
1936
|
routeMatch.error = undefined;
|
|
1921
1937
|
routeMatch.status = 'success';
|
|
1922
1938
|
routeMatch.updatedAt = Date.now();
|
|
@@ -1976,16 +1992,14 @@ function createRouteMatch(router, route, opts) {
|
|
|
1976
1992
|
return routeMatch;
|
|
1977
1993
|
}
|
|
1978
1994
|
|
|
1979
|
-
function cascadeLoaderData(
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
}
|
|
1995
|
+
function cascadeLoaderData(matches) {
|
|
1996
|
+
matches.forEach((match, index) => {
|
|
1997
|
+
const parent = matches[index - 1];
|
|
1983
1998
|
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
}
|
|
1999
|
+
if (parent) {
|
|
2000
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends$1({}, parent.loaderData, match.routeLoaderData));
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
1989
2003
|
}
|
|
1990
2004
|
|
|
1991
2005
|
function matchPathname(currentPathname, matchLocation) {
|