@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
package/build/esm/index.js
CHANGED
|
@@ -1013,6 +1013,7 @@ function createRouter(userOptions) {
|
|
|
1013
1013
|
let router = {
|
|
1014
1014
|
options: originalOptions,
|
|
1015
1015
|
listeners: [],
|
|
1016
|
+
removeActionQueue: [],
|
|
1016
1017
|
// Resolved after construction
|
|
1017
1018
|
basepath: '',
|
|
1018
1019
|
routeTree: undefined,
|
|
@@ -1136,12 +1137,14 @@ function createRouter(userOptions) {
|
|
|
1136
1137
|
strictParseParams: true
|
|
1137
1138
|
});
|
|
1138
1139
|
const toMatches = router.matchRoutes(pathname);
|
|
1139
|
-
|
|
1140
|
+
|
|
1141
|
+
const prevParams = _extends$1({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
|
|
1142
|
+
|
|
1140
1143
|
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
1141
1144
|
|
|
1142
1145
|
if (nextParams) {
|
|
1143
1146
|
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
1144
|
-
Object.assign(nextParams, fn(nextParams));
|
|
1147
|
+
Object.assign({}, nextParams, fn(nextParams));
|
|
1145
1148
|
});
|
|
1146
1149
|
}
|
|
1147
1150
|
|
|
@@ -1244,22 +1247,33 @@ function createRouter(userOptions) {
|
|
|
1244
1247
|
router.startedLoadingAt = id;
|
|
1245
1248
|
|
|
1246
1249
|
if (next) {
|
|
1250
|
+
// If the location.href has changed
|
|
1247
1251
|
// Ingest the new location
|
|
1248
1252
|
router.location = next;
|
|
1249
|
-
} //
|
|
1253
|
+
} // Clear out old actions
|
|
1250
1254
|
|
|
1251
1255
|
|
|
1256
|
+
router.removeActionQueue.forEach(_ref => {
|
|
1257
|
+
let {
|
|
1258
|
+
action,
|
|
1259
|
+
actionState
|
|
1260
|
+
} = _ref;
|
|
1261
|
+
|
|
1262
|
+
if (router.state.currentAction === actionState) {
|
|
1263
|
+
router.state.currentAction = undefined;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
if (action.current === actionState) {
|
|
1267
|
+
action.current = undefined;
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
router.removeActionQueue = []; // Cancel any pending matches
|
|
1271
|
+
|
|
1252
1272
|
router.cancelMatches(); // Match the routes
|
|
1253
1273
|
|
|
1254
1274
|
const unloadedMatches = router.matchRoutes(location.pathname, {
|
|
1255
1275
|
strictParseParams: true
|
|
1256
1276
|
});
|
|
1257
|
-
unloadedMatches.forEach((match, index) => {
|
|
1258
|
-
const parent = unloadedMatches[index - 1];
|
|
1259
|
-
const child = unloadedMatches[index + 1];
|
|
1260
|
-
if (parent) match.__.setParentMatch(parent);
|
|
1261
|
-
if (child) match.__.addChildMatch(child);
|
|
1262
|
-
});
|
|
1263
1277
|
router.state = _extends$1({}, router.state, {
|
|
1264
1278
|
pending: {
|
|
1265
1279
|
matches: unloadedMatches,
|
|
@@ -1440,6 +1454,7 @@ function createRouter(userOptions) {
|
|
|
1440
1454
|
};
|
|
1441
1455
|
|
|
1442
1456
|
recurse([router.routeTree]);
|
|
1457
|
+
cascadeLoaderData(matches);
|
|
1443
1458
|
return matches;
|
|
1444
1459
|
},
|
|
1445
1460
|
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
@@ -1518,14 +1533,14 @@ function createRouter(userOptions) {
|
|
|
1518
1533
|
const next = router.buildNext(location);
|
|
1519
1534
|
return router.commitLocation(next, location.replace);
|
|
1520
1535
|
},
|
|
1521
|
-
navigate: async
|
|
1536
|
+
navigate: async _ref2 => {
|
|
1522
1537
|
let {
|
|
1523
1538
|
from,
|
|
1524
1539
|
to = '.',
|
|
1525
1540
|
search,
|
|
1526
1541
|
hash,
|
|
1527
1542
|
replace
|
|
1528
|
-
} =
|
|
1543
|
+
} = _ref2;
|
|
1529
1544
|
// If this link simply reloads the current route,
|
|
1530
1545
|
// make sure it has a new key so it will trigger a data refresh
|
|
1531
1546
|
// If this `to` is a valid external URL, return
|
|
@@ -1547,8 +1562,8 @@ function createRouter(userOptions) {
|
|
|
1547
1562
|
hash
|
|
1548
1563
|
});
|
|
1549
1564
|
},
|
|
1550
|
-
buildLink:
|
|
1551
|
-
var _preload,
|
|
1565
|
+
buildLink: _ref3 => {
|
|
1566
|
+
var _preload, _ref4, _ref5;
|
|
1552
1567
|
|
|
1553
1568
|
let {
|
|
1554
1569
|
from,
|
|
@@ -1563,7 +1578,7 @@ function createRouter(userOptions) {
|
|
|
1563
1578
|
preloadMaxAge: userPreloadMaxAge,
|
|
1564
1579
|
preloadDelay: userPreloadDelay,
|
|
1565
1580
|
disabled
|
|
1566
|
-
} =
|
|
1581
|
+
} = _ref3;
|
|
1567
1582
|
|
|
1568
1583
|
// If this link simply reloads the current route,
|
|
1569
1584
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -1587,8 +1602,8 @@ function createRouter(userOptions) {
|
|
|
1587
1602
|
};
|
|
1588
1603
|
const next = router.buildNext(nextOpts);
|
|
1589
1604
|
preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
|
|
1590
|
-
const preloadMaxAge = (
|
|
1591
|
-
const preloadDelay = (
|
|
1605
|
+
const preloadMaxAge = (_ref4 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref4 : 2000;
|
|
1606
|
+
const preloadDelay = (_ref5 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref5 : 50; // Compare path/hash for matches
|
|
1592
1607
|
|
|
1593
1608
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
1594
1609
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -1662,11 +1677,11 @@ function createRouter(userOptions) {
|
|
|
1662
1677
|
},
|
|
1663
1678
|
__experimental__createSnapshot: () => {
|
|
1664
1679
|
return _extends$1({}, router.state, {
|
|
1665
|
-
matches: router.state.matches.map(
|
|
1680
|
+
matches: router.state.matches.map(_ref6 => {
|
|
1666
1681
|
let {
|
|
1667
1682
|
routeLoaderData: loaderData,
|
|
1668
1683
|
matchId
|
|
1669
|
-
} =
|
|
1684
|
+
} = _ref6;
|
|
1670
1685
|
return {
|
|
1671
1686
|
matchId,
|
|
1672
1687
|
loaderData
|
|
@@ -1716,10 +1731,12 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1716
1731
|
status: 'pending',
|
|
1717
1732
|
submission
|
|
1718
1733
|
};
|
|
1734
|
+
action.current = actionState;
|
|
1719
1735
|
action.latest = actionState;
|
|
1720
1736
|
action.pending.push(actionState);
|
|
1721
1737
|
router.state = _extends$1({}, router.state, {
|
|
1722
|
-
|
|
1738
|
+
currentAction: actionState,
|
|
1739
|
+
latestAction: actionState
|
|
1723
1740
|
});
|
|
1724
1741
|
router.notify();
|
|
1725
1742
|
|
|
@@ -1743,11 +1760,10 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1743
1760
|
actionState.status = 'error';
|
|
1744
1761
|
} finally {
|
|
1745
1762
|
action.pending = action.pending.filter(d => d !== actionState);
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1763
|
+
router.removeActionQueue.push({
|
|
1764
|
+
action,
|
|
1765
|
+
actionState
|
|
1766
|
+
});
|
|
1751
1767
|
router.notify();
|
|
1752
1768
|
}
|
|
1753
1769
|
}
|
|
@@ -1834,16 +1850,17 @@ function createRouteMatch(router, route, opts) {
|
|
|
1834
1850
|
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1835
1851
|
delete routeMatch.__.pendingMinPromise;
|
|
1836
1852
|
},
|
|
1837
|
-
setParentMatch: parentMatch => {
|
|
1838
|
-
|
|
1839
|
-
},
|
|
1840
|
-
addChildMatch: childMatch => {
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1853
|
+
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
1854
|
+
// routeMatch.parentMatch = parentMatch
|
|
1855
|
+
// },
|
|
1856
|
+
// addChildMatch: (childMatch: RouteMatch) => {
|
|
1857
|
+
// if (
|
|
1858
|
+
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
1859
|
+
// ) {
|
|
1860
|
+
// return
|
|
1861
|
+
// }
|
|
1862
|
+
// routeMatch.childMatches.push(childMatch)
|
|
1863
|
+
// },
|
|
1847
1864
|
validate: () => {
|
|
1848
1865
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1849
1866
|
|
|
@@ -1947,7 +1964,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1947
1964
|
}
|
|
1948
1965
|
|
|
1949
1966
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1950
|
-
cascadeLoaderData(routeMatch);
|
|
1951
1967
|
routeMatch.error = undefined;
|
|
1952
1968
|
routeMatch.status = 'success';
|
|
1953
1969
|
routeMatch.updatedAt = Date.now();
|
|
@@ -2007,16 +2023,14 @@ function createRouteMatch(router, route, opts) {
|
|
|
2007
2023
|
return routeMatch;
|
|
2008
2024
|
}
|
|
2009
2025
|
|
|
2010
|
-
function cascadeLoaderData(
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
}
|
|
2026
|
+
function cascadeLoaderData(matches) {
|
|
2027
|
+
matches.forEach((match, index) => {
|
|
2028
|
+
const parent = matches[index - 1];
|
|
2014
2029
|
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
}
|
|
2030
|
+
if (parent) {
|
|
2031
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends$1({}, parent.loaderData, match.routeLoaderData));
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2020
2034
|
}
|
|
2021
2035
|
|
|
2022
2036
|
function matchPathname(currentPathname, matchLocation) {
|