@tanstack/react-router 0.0.1-alpha.4 → 0.0.1-alpha.6

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.
@@ -4014,7 +4014,7 @@ var drawChart = (function (exports) {
4014
4014
  </script>
4015
4015
  <script>
4016
4016
  /*<!--*/
4017
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"uid":"c4e0-25","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"c4e0-27"},{"name":"react-router/src/index.tsx","uid":"c4e0-29"}]}]}],"isRoot":true},"nodeParts":{"c4e0-25":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"c4e0-24"},"c4e0-27":{"renderedLength":69609,"gzipLength":14467,"brotliLength":0,"mainUid":"c4e0-26"},"c4e0-29":{"renderedLength":11456,"gzipLength":2963,"brotliLength":0,"mainUid":"c4e0-28"}},"nodeMetas":{"c4e0-24":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"c4e0-25"},"imported":[],"importedBy":[{"uid":"c4e0-28"}]},"c4e0-26":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"c4e0-27"},"imported":[],"importedBy":[{"uid":"c4e0-28"}]},"c4e0-28":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"c4e0-29"},"imported":[{"uid":"c4e0-24"},{"uid":"c4e0-30"},{"uid":"c4e0-31"},{"uid":"c4e0-26"}],"importedBy":[],"isEntry":true},"c4e0-30":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"c4e0-28"}],"isExternal":true},"c4e0-31":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"c4e0-28"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4017
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"uid":"19e6-25","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"19e6-27"},{"name":"react-router/src/index.tsx","uid":"19e6-29"}]}]}],"isRoot":true},"nodeParts":{"19e6-25":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"19e6-24"},"19e6-27":{"renderedLength":69986,"gzipLength":14566,"brotliLength":0,"mainUid":"19e6-26"},"19e6-29":{"renderedLength":11513,"gzipLength":2992,"brotliLength":0,"mainUid":"19e6-28"}},"nodeMetas":{"19e6-24":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"19e6-25"},"imported":[],"importedBy":[{"uid":"19e6-28"}]},"19e6-26":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"19e6-27"},"imported":[],"importedBy":[{"uid":"19e6-28"}]},"19e6-28":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"19e6-29"},"imported":[{"uid":"19e6-24"},{"uid":"19e6-30"},{"uid":"19e6-31"},{"uid":"19e6-26"}],"importedBy":[],"isEntry":true},"19e6-30":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"19e6-28"}],"isExternal":true},"19e6-31":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"19e6-28"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4018
4018
 
4019
4019
  const run = () => {
4020
4020
  const width = window.innerWidth;
@@ -7,7 +7,7 @@
7
7
  "name": "index.production.js",
8
8
  "children": [
9
9
  {
10
- "uid": "c4e0-33",
10
+ "uid": "19e6-33",
11
11
  "name": "\u0000rollupPluginBabelHelpers.js"
12
12
  },
13
13
  {
@@ -15,11 +15,11 @@
15
15
  "children": [
16
16
  {
17
17
  "name": "router-core/build/esm/index.js",
18
- "uid": "c4e0-35"
18
+ "uid": "19e6-35"
19
19
  },
20
20
  {
21
21
  "name": "react-router/src/index.tsx",
22
- "uid": "c4e0-37"
22
+ "uid": "19e6-37"
23
23
  }
24
24
  ]
25
25
  }
@@ -29,90 +29,90 @@
29
29
  "isRoot": true
30
30
  },
31
31
  "nodeParts": {
32
- "c4e0-33": {
32
+ "19e6-33": {
33
33
  "renderedLength": 798,
34
34
  "gzipLength": 366,
35
35
  "brotliLength": 0,
36
- "mainUid": "c4e0-32"
36
+ "mainUid": "19e6-32"
37
37
  },
38
- "c4e0-35": {
39
- "renderedLength": 69609,
40
- "gzipLength": 14467,
38
+ "19e6-35": {
39
+ "renderedLength": 69986,
40
+ "gzipLength": 14566,
41
41
  "brotliLength": 0,
42
- "mainUid": "c4e0-34"
42
+ "mainUid": "19e6-34"
43
43
  },
44
- "c4e0-37": {
45
- "renderedLength": 11456,
46
- "gzipLength": 2963,
44
+ "19e6-37": {
45
+ "renderedLength": 11513,
46
+ "gzipLength": 2992,
47
47
  "brotliLength": 0,
48
- "mainUid": "c4e0-36"
48
+ "mainUid": "19e6-36"
49
49
  }
50
50
  },
51
51
  "nodeMetas": {
52
- "c4e0-32": {
52
+ "19e6-32": {
53
53
  "id": "\u0000rollupPluginBabelHelpers.js",
54
54
  "moduleParts": {
55
- "index.production.js": "c4e0-33"
55
+ "index.production.js": "19e6-33"
56
56
  },
57
57
  "imported": [],
58
58
  "importedBy": [
59
59
  {
60
- "uid": "c4e0-36"
60
+ "uid": "19e6-36"
61
61
  }
62
62
  ]
63
63
  },
64
- "c4e0-34": {
64
+ "19e6-34": {
65
65
  "id": "/packages/router-core/build/esm/index.js",
66
66
  "moduleParts": {
67
- "index.production.js": "c4e0-35"
67
+ "index.production.js": "19e6-35"
68
68
  },
69
69
  "imported": [],
70
70
  "importedBy": [
71
71
  {
72
- "uid": "c4e0-36"
72
+ "uid": "19e6-36"
73
73
  }
74
74
  ]
75
75
  },
76
- "c4e0-36": {
76
+ "19e6-36": {
77
77
  "id": "/packages/react-router/src/index.tsx",
78
78
  "moduleParts": {
79
- "index.production.js": "c4e0-37"
79
+ "index.production.js": "19e6-37"
80
80
  },
81
81
  "imported": [
82
82
  {
83
- "uid": "c4e0-32"
83
+ "uid": "19e6-32"
84
84
  },
85
85
  {
86
- "uid": "c4e0-38"
86
+ "uid": "19e6-38"
87
87
  },
88
88
  {
89
- "uid": "c4e0-39"
89
+ "uid": "19e6-39"
90
90
  },
91
91
  {
92
- "uid": "c4e0-34"
92
+ "uid": "19e6-34"
93
93
  }
94
94
  ],
95
95
  "importedBy": [],
96
96
  "isEntry": true
97
97
  },
98
- "c4e0-38": {
98
+ "19e6-38": {
99
99
  "id": "react",
100
100
  "moduleParts": {},
101
101
  "imported": [],
102
102
  "importedBy": [
103
103
  {
104
- "uid": "c4e0-36"
104
+ "uid": "19e6-36"
105
105
  }
106
106
  ],
107
107
  "isExternal": true
108
108
  },
109
- "c4e0-39": {
109
+ "19e6-39": {
110
110
  "id": "use-sync-external-store/shim",
111
111
  "moduleParts": {},
112
112
  "imported": [],
113
113
  "importedBy": [
114
114
  {
115
- "uid": "c4e0-36"
115
+ "uid": "19e6-36"
116
116
  }
117
117
  ],
118
118
  "isExternal": true
@@ -65,13 +65,9 @@ declare type RouterProps<TRouteConfig extends AnyRouteConfig = RouteConfig, TAll
65
65
  children?: React.ReactNode;
66
66
  };
67
67
  declare function RouterProvider<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo>({ children, router, ...rest }: RouterProps<TRouteConfig, TAllRouteInfo>): JSX.Element;
68
- declare function useRouter(): Router;
69
- declare function useMatches(): RouteMatch[];
70
- declare function useParentMatches(): RouteMatch[];
71
- declare function useMatch<T>(): RouteMatch;
72
68
  declare function Outlet(): JSX.Element | null;
73
69
  declare function DefaultCatchBoundary({ error }: {
74
70
  error: any;
75
71
  }): JSX.Element;
76
72
 
77
- export { DefaultCatchBoundary, MatchesProvider, MatchesProviderProps, Outlet, PromptProps, RouterProps, RouterProvider, createReactRouter, useMatch, useMatches, useParentMatches, useRouter };
73
+ export { DefaultCatchBoundary, MatchesProvider, MatchesProviderProps, Outlet, PromptProps, RouterProps, RouterProvider, createReactRouter };
@@ -1029,6 +1029,7 @@
1029
1029
  let router = {
1030
1030
  options: originalOptions,
1031
1031
  listeners: [],
1032
+ removeActionQueue: [],
1032
1033
  // Resolved after construction
1033
1034
  basepath: '',
1034
1035
  routeTree: undefined,
@@ -1152,12 +1153,14 @@
1152
1153
  strictParseParams: true
1153
1154
  });
1154
1155
  const toMatches = router.matchRoutes(pathname);
1155
- const prevParams = (_last = last(fromMatches)) == null ? void 0 : _last.params;
1156
+
1157
+ const prevParams = _extends$1({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
1158
+
1156
1159
  let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
1157
1160
 
1158
1161
  if (nextParams) {
1159
1162
  toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
1160
- Object.assign(nextParams, fn(nextParams));
1163
+ Object.assign({}, nextParams, fn(nextParams));
1161
1164
  });
1162
1165
  }
1163
1166
 
@@ -1262,20 +1265,30 @@
1262
1265
  if (next) {
1263
1266
  // Ingest the new location
1264
1267
  router.location = next;
1265
- } // Cancel any pending matches
1268
+ } // Clear out old actions
1269
+
1270
+
1271
+ router.removeActionQueue.forEach(_ref => {
1272
+ let {
1273
+ action,
1274
+ actionState
1275
+ } = _ref;
1276
+
1277
+ if (router.state.currentAction === actionState) {
1278
+ router.state.currentAction = undefined;
1279
+ }
1266
1280
 
1281
+ if (action.current === actionState) {
1282
+ action.current = undefined;
1283
+ }
1284
+ });
1285
+ router.removeActionQueue = []; // Cancel any pending matches
1267
1286
 
1268
1287
  router.cancelMatches(); // Match the routes
1269
1288
 
1270
1289
  const unloadedMatches = router.matchRoutes(location.pathname, {
1271
1290
  strictParseParams: true
1272
1291
  });
1273
- unloadedMatches.forEach((match, index) => {
1274
- const parent = unloadedMatches[index - 1];
1275
- const child = unloadedMatches[index + 1];
1276
- if (parent) match.__.setParentMatch(parent);
1277
- if (child) match.__.addChildMatch(child);
1278
- });
1279
1292
  router.state = _extends$1({}, router.state, {
1280
1293
  pending: {
1281
1294
  matches: unloadedMatches,
@@ -1456,6 +1469,7 @@
1456
1469
  };
1457
1470
 
1458
1471
  recurse([router.routeTree]);
1472
+ cascadeLoaderData(matches);
1459
1473
  return matches;
1460
1474
  },
1461
1475
  loadMatches: async (resolvedMatches, loaderOpts) => {
@@ -1493,7 +1507,7 @@
1493
1507
  const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
1494
1508
  [...router.state.matches, ...((_router$state$pending5 = (_router$state$pending6 = router.state.pending) == null ? void 0 : _router$state$pending6.matches) != null ? _router$state$pending5 : [])].forEach(match => {
1495
1509
  if (unloadedMatchIds.includes(match.matchId)) {
1496
- match.isInvalid = true;
1510
+ match.invalidate();
1497
1511
  }
1498
1512
  });
1499
1513
  },
@@ -1534,14 +1548,15 @@
1534
1548
  const next = router.buildNext(location);
1535
1549
  return router.commitLocation(next, location.replace);
1536
1550
  },
1537
- navigate: async _ref => {
1551
+ navigate: async _ref2 => {
1538
1552
  let {
1539
1553
  from,
1540
1554
  to = '.',
1541
1555
  search,
1542
1556
  hash,
1543
- replace
1544
- } = _ref;
1557
+ replace,
1558
+ params
1559
+ } = _ref2;
1545
1560
  // If this link simply reloads the current route,
1546
1561
  // make sure it has a new key so it will trigger a data refresh
1547
1562
  // If this `to` is a valid external URL, return
@@ -1560,11 +1575,13 @@
1560
1575
  from: fromString,
1561
1576
  to: toString,
1562
1577
  search,
1563
- hash
1578
+ hash,
1579
+ replace,
1580
+ params
1564
1581
  });
1565
1582
  },
1566
- buildLink: _ref2 => {
1567
- var _preload, _ref3, _ref4;
1583
+ buildLink: _ref3 => {
1584
+ var _preload, _ref4, _ref5;
1568
1585
 
1569
1586
  let {
1570
1587
  from,
@@ -1579,7 +1596,7 @@
1579
1596
  preloadMaxAge: userPreloadMaxAge,
1580
1597
  preloadDelay: userPreloadDelay,
1581
1598
  disabled
1582
- } = _ref2;
1599
+ } = _ref3;
1583
1600
 
1584
1601
  // If this link simply reloads the current route,
1585
1602
  // make sure it has a new key so it will trigger a data refresh
@@ -1603,8 +1620,8 @@
1603
1620
  };
1604
1621
  const next = router.buildNext(nextOpts);
1605
1622
  preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
1606
- const preloadMaxAge = (_ref3 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref3 : 2000;
1607
- const preloadDelay = (_ref4 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref4 : 50; // Compare path/hash for matches
1623
+ const preloadMaxAge = (_ref4 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref4 : 2000;
1624
+ const preloadDelay = (_ref5 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref5 : 50; // Compare path/hash for matches
1608
1625
 
1609
1626
  const pathIsEqual = router.state.location.pathname === next.pathname;
1610
1627
  const currentPathSplit = router.state.location.pathname.split('/');
@@ -1678,11 +1695,11 @@
1678
1695
  },
1679
1696
  __experimental__createSnapshot: () => {
1680
1697
  return _extends$1({}, router.state, {
1681
- matches: router.state.matches.map(_ref5 => {
1698
+ matches: router.state.matches.map(_ref6 => {
1682
1699
  let {
1683
1700
  routeLoaderData: loaderData,
1684
1701
  matchId
1685
- } = _ref5;
1702
+ } = _ref6;
1686
1703
  return {
1687
1704
  matchId,
1688
1705
  loaderData
@@ -1732,10 +1749,12 @@
1732
1749
  status: 'pending',
1733
1750
  submission
1734
1751
  };
1752
+ action.current = actionState;
1735
1753
  action.latest = actionState;
1736
1754
  action.pending.push(actionState);
1737
1755
  router.state = _extends$1({}, router.state, {
1738
- action: actionState
1756
+ currentAction: actionState,
1757
+ latestAction: actionState
1739
1758
  });
1740
1759
  router.notify();
1741
1760
 
@@ -1759,11 +1778,10 @@
1759
1778
  actionState.status = 'error';
1760
1779
  } finally {
1761
1780
  action.pending = action.pending.filter(d => d !== actionState);
1762
-
1763
- if (actionState === router.state.action) {
1764
- router.state.action = undefined;
1765
- }
1766
-
1781
+ router.removeActionQueue.push({
1782
+ action,
1783
+ actionState
1784
+ });
1767
1785
  router.notify();
1768
1786
  }
1769
1787
  }
@@ -1850,16 +1868,17 @@
1850
1868
  clearTimeout(routeMatch.__.pendingMinTimeout);
1851
1869
  delete routeMatch.__.pendingMinPromise;
1852
1870
  },
1853
- setParentMatch: parentMatch => {
1854
- routeMatch.parentMatch = parentMatch;
1855
- },
1856
- addChildMatch: childMatch => {
1857
- if (routeMatch.childMatches.find(d => d.matchId === childMatch.matchId)) {
1858
- return;
1859
- }
1860
-
1861
- routeMatch.childMatches.push(childMatch);
1862
- },
1871
+ // setParentMatch: (parentMatch?: RouteMatch) => {
1872
+ // routeMatch.parentMatch = parentMatch
1873
+ // },
1874
+ // addChildMatch: (childMatch: RouteMatch) => {
1875
+ // if (
1876
+ // routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
1877
+ // ) {
1878
+ // return
1879
+ // }
1880
+ // routeMatch.childMatches.push(childMatch)
1881
+ // },
1863
1882
  validate: () => {
1864
1883
  var _routeMatch$parentMat, _routeMatch$parentMat2;
1865
1884
 
@@ -1896,6 +1915,9 @@
1896
1915
 
1897
1916
  routeMatch.__.cancelPending();
1898
1917
  },
1918
+ invalidate: () => {
1919
+ routeMatch.isInvalid = true;
1920
+ },
1899
1921
  load: async () => {
1900
1922
  const id = '' + Date.now() + Math.random();
1901
1923
  routeMatch.__.latestId = id; // If the match was in an error state, set it
@@ -1963,7 +1985,6 @@
1963
1985
  }
1964
1986
 
1965
1987
  routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1966
- cascadeLoaderData(routeMatch);
1967
1988
  routeMatch.error = undefined;
1968
1989
  routeMatch.status = 'success';
1969
1990
  routeMatch.updatedAt = Date.now();
@@ -2023,16 +2044,14 @@
2023
2044
  return routeMatch;
2024
2045
  }
2025
2046
 
2026
- function cascadeLoaderData(routeMatch) {
2027
- if (routeMatch.parentMatch) {
2028
- routeMatch.loaderData = replaceEqualDeep(routeMatch.loaderData, _extends$1({}, routeMatch.parentMatch.loaderData, routeMatch.routeLoaderData));
2029
- }
2047
+ function cascadeLoaderData(matches) {
2048
+ matches.forEach((match, index) => {
2049
+ const parent = matches[index - 1];
2030
2050
 
2031
- if (routeMatch.childMatches.length) {
2032
- routeMatch.childMatches.forEach(childMatch => {
2033
- cascadeLoaderData(childMatch);
2034
- });
2035
- }
2051
+ if (parent) {
2052
+ match.loaderData = replaceEqualDeep(match.loaderData, _extends$1({}, parent.loaderData, match.routeLoaderData));
2053
+ }
2054
+ });
2036
2055
  }
2037
2056
 
2038
2057
  function matchPathname(currentPathname, matchLocation) {
@@ -2564,29 +2583,33 @@
2564
2583
  value: router.state.matches
2565
2584
  }, children != null ? children : /*#__PURE__*/React__namespace.createElement(Outlet, null)));
2566
2585
  }
2586
+
2567
2587
  function useRouter() {
2568
2588
  const value = React__namespace.useContext(routerContext);
2569
2589
  warning(!value, 'useRouter must be used inside a <Router> component!');
2570
2590
  useRouterSubscription(value.router);
2571
2591
  return value.router;
2572
2592
  }
2593
+
2573
2594
  function useMatches() {
2574
2595
  return React__namespace.useContext(matchesContext);
2575
- }
2576
- function useParentMatches() {
2577
- const router = useRouter();
2578
-
2579
- const match = _useMatch();
2596
+ } // function useParentMatches(): RouteMatch[] {
2597
+ // const router = useRouter()
2598
+ // const match = useMatch()
2599
+ // const matches = router.state.matches
2600
+ // return matches.slice(
2601
+ // 0,
2602
+ // matches.findIndex((d) => d.matchId === match.matchId) - 1,
2603
+ // )
2604
+ // }
2580
2605
 
2581
- const matches = router.state.matches;
2582
- return matches.slice(0, matches.findIndex(d => d.matchId === match.matchId) - 1);
2583
- }
2584
2606
 
2585
2607
  function _useMatch() {
2586
2608
  var _useMatches;
2587
2609
 
2588
2610
  return (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
2589
2611
  }
2612
+
2590
2613
  function Outlet() {
2591
2614
  var _ref3, _childMatch$options$c;
2592
2615
 
@@ -2745,10 +2768,6 @@
2745
2768
  exports.resolvePath = _resolvePath;
2746
2769
  exports.rootRouteId = rootRouteId;
2747
2770
  exports.stringifySearchWith = stringifySearchWith;
2748
- exports.useMatch = _useMatch;
2749
- exports.useMatches = useMatches;
2750
- exports.useParentMatches = useParentMatches;
2751
- exports.useRouter = useRouter;
2752
2771
  exports.warning = warning;
2753
2772
 
2754
2773
  Object.defineProperty(exports, '__esModule', { value: true });