@tanstack/react-router 0.0.1-beta.4 → 0.0.1-beta.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":"0d6e-59","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"0d6e-61"},{"name":"react-router/src/index.tsx","uid":"0d6e-63"}]}]}],"isRoot":true},"nodeParts":{"0d6e-59":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"0d6e-58"},"0d6e-61":{"renderedLength":74844,"gzipLength":15588,"brotliLength":0,"mainUid":"0d6e-60"},"0d6e-63":{"renderedLength":12726,"gzipLength":3316,"brotliLength":0,"mainUid":"0d6e-62"}},"nodeMetas":{"0d6e-58":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"0d6e-59"},"imported":[],"importedBy":[{"uid":"0d6e-62"}]},"0d6e-60":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"0d6e-61"},"imported":[],"importedBy":[{"uid":"0d6e-62"}]},"0d6e-62":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"0d6e-63"},"imported":[{"uid":"0d6e-58"},{"uid":"0d6e-64"},{"uid":"0d6e-65"},{"uid":"0d6e-60"}],"importedBy":[],"isEntry":true},"0d6e-64":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"0d6e-62"}],"isExternal":true},"0d6e-65":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"0d6e-62"}],"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":"ec84-59","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"ec84-61"},{"name":"react-router/src/index.tsx","uid":"ec84-63"}]}]}],"isRoot":true},"nodeParts":{"ec84-59":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"ec84-58"},"ec84-61":{"renderedLength":75898,"gzipLength":15769,"brotliLength":0,"mainUid":"ec84-60"},"ec84-63":{"renderedLength":12607,"gzipLength":3287,"brotliLength":0,"mainUid":"ec84-62"}},"nodeMetas":{"ec84-58":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"ec84-59"},"imported":[],"importedBy":[{"uid":"ec84-62"}]},"ec84-60":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"ec84-61"},"imported":[],"importedBy":[{"uid":"ec84-62"}]},"ec84-62":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"ec84-63"},"imported":[{"uid":"ec84-58"},{"uid":"ec84-64"},{"uid":"ec84-65"},{"uid":"ec84-60"}],"importedBy":[],"isEntry":true},"ec84-64":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"ec84-62"}],"isExternal":true},"ec84-65":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"ec84-62"}],"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": "0d6e-67",
10
+ "uid": "ec84-67",
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": "0d6e-69"
18
+ "uid": "ec84-69"
19
19
  },
20
20
  {
21
21
  "name": "react-router/src/index.tsx",
22
- "uid": "0d6e-71"
22
+ "uid": "ec84-71"
23
23
  }
24
24
  ]
25
25
  }
@@ -29,90 +29,90 @@
29
29
  "isRoot": true
30
30
  },
31
31
  "nodeParts": {
32
- "0d6e-67": {
32
+ "ec84-67": {
33
33
  "renderedLength": 798,
34
34
  "gzipLength": 366,
35
35
  "brotliLength": 0,
36
- "mainUid": "0d6e-66"
36
+ "mainUid": "ec84-66"
37
37
  },
38
- "0d6e-69": {
39
- "renderedLength": 74844,
40
- "gzipLength": 15588,
38
+ "ec84-69": {
39
+ "renderedLength": 75898,
40
+ "gzipLength": 15769,
41
41
  "brotliLength": 0,
42
- "mainUid": "0d6e-68"
42
+ "mainUid": "ec84-68"
43
43
  },
44
- "0d6e-71": {
45
- "renderedLength": 12726,
46
- "gzipLength": 3316,
44
+ "ec84-71": {
45
+ "renderedLength": 12607,
46
+ "gzipLength": 3287,
47
47
  "brotliLength": 0,
48
- "mainUid": "0d6e-70"
48
+ "mainUid": "ec84-70"
49
49
  }
50
50
  },
51
51
  "nodeMetas": {
52
- "0d6e-66": {
52
+ "ec84-66": {
53
53
  "id": "\u0000rollupPluginBabelHelpers.js",
54
54
  "moduleParts": {
55
- "index.production.js": "0d6e-67"
55
+ "index.production.js": "ec84-67"
56
56
  },
57
57
  "imported": [],
58
58
  "importedBy": [
59
59
  {
60
- "uid": "0d6e-70"
60
+ "uid": "ec84-70"
61
61
  }
62
62
  ]
63
63
  },
64
- "0d6e-68": {
64
+ "ec84-68": {
65
65
  "id": "/packages/router-core/build/esm/index.js",
66
66
  "moduleParts": {
67
- "index.production.js": "0d6e-69"
67
+ "index.production.js": "ec84-69"
68
68
  },
69
69
  "imported": [],
70
70
  "importedBy": [
71
71
  {
72
- "uid": "0d6e-70"
72
+ "uid": "ec84-70"
73
73
  }
74
74
  ]
75
75
  },
76
- "0d6e-70": {
76
+ "ec84-70": {
77
77
  "id": "/packages/react-router/src/index.tsx",
78
78
  "moduleParts": {
79
- "index.production.js": "0d6e-71"
79
+ "index.production.js": "ec84-71"
80
80
  },
81
81
  "imported": [
82
82
  {
83
- "uid": "0d6e-66"
83
+ "uid": "ec84-66"
84
84
  },
85
85
  {
86
- "uid": "0d6e-72"
86
+ "uid": "ec84-72"
87
87
  },
88
88
  {
89
- "uid": "0d6e-73"
89
+ "uid": "ec84-73"
90
90
  },
91
91
  {
92
- "uid": "0d6e-68"
92
+ "uid": "ec84-68"
93
93
  }
94
94
  ],
95
95
  "importedBy": [],
96
96
  "isEntry": true
97
97
  },
98
- "0d6e-72": {
98
+ "ec84-72": {
99
99
  "id": "react",
100
100
  "moduleParts": {},
101
101
  "imported": [],
102
102
  "importedBy": [
103
103
  {
104
- "uid": "0d6e-70"
104
+ "uid": "ec84-70"
105
105
  }
106
106
  ],
107
107
  "isExternal": true
108
108
  },
109
- "0d6e-73": {
109
+ "ec84-73": {
110
110
  "id": "use-sync-external-store/shim",
111
111
  "moduleParts": {},
112
112
  "imported": [],
113
113
  "importedBy": [
114
114
  {
115
- "uid": "0d6e-70"
115
+ "uid": "ec84-70"
116
116
  }
117
117
  ],
118
118
  "isExternal": true
@@ -991,6 +991,11 @@
991
991
 
992
992
  return updater;
993
993
  }
994
+ function pick(parent, keys) {
995
+ return keys.reduce((obj, key) => {
996
+ obj[key] = parent[key];
997
+ }, {});
998
+ }
994
999
 
995
1000
  function joinPaths(paths) {
996
1001
  return cleanPath(paths.filter(Boolean).join('/'));
@@ -1786,7 +1791,6 @@
1786
1791
  matches: [],
1787
1792
  actions: {},
1788
1793
  loaders: {},
1789
- loaderData: {},
1790
1794
  lastUpdated: Date.now(),
1791
1795
  isFetching: false,
1792
1796
  isPreloading: false
@@ -1809,6 +1813,26 @@
1809
1813
  cascadeLoaderData(router.state.matches);
1810
1814
  router.listeners.forEach(listener => listener(router));
1811
1815
  },
1816
+ dehydrateState: () => {
1817
+ router.state;
1818
+ return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
1819
+ matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
1820
+ });
1821
+ },
1822
+ hydrateState: dehydratedState => {
1823
+ // Match the routes
1824
+ const matches = router.matchRoutes(router.location.pathname, {
1825
+ strictParseParams: true
1826
+ });
1827
+ router.state = _extends({}, router.state, dehydratedState, {
1828
+ matches: matches.map(match => {
1829
+ const dehydratedMatch = dehydratedState.matches.find(d => d.matchId === match.matchId);
1830
+ invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
1831
+ Object.assign(match, dehydratedMatch);
1832
+ return match;
1833
+ })
1834
+ });
1835
+ },
1812
1836
  mount: () => {
1813
1837
  const next = router.__.buildLocation({
1814
1838
  to: '.',
@@ -1820,11 +1844,11 @@
1820
1844
 
1821
1845
  if (next.href !== router.location.href) {
1822
1846
  router.__.commitLocation(next, true);
1823
- } else {
1824
- router.loadLocation();
1825
1847
  }
1826
1848
 
1827
- const unsub = history.listen(event => {
1849
+ router.loadLocation();
1850
+ const unsub = router.history.listen(event => {
1851
+ console.log(event.location);
1828
1852
  router.loadLocation(router.__.parseLocation(event.location, router.location));
1829
1853
  }); // addEventListener does not exist in React Native, but window does
1830
1854
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@@ -1846,6 +1870,17 @@
1846
1870
  router.loadLocation();
1847
1871
  },
1848
1872
  update: opts => {
1873
+ const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
1874
+
1875
+ if (!router.location || newHistory) {
1876
+ if (opts != null && opts.history) {
1877
+ router.history = opts.history;
1878
+ }
1879
+
1880
+ router.location = router.__.parseLocation(router.history.location);
1881
+ router.state.location = router.location;
1882
+ }
1883
+
1849
1884
  Object.assign(router.options, opts);
1850
1885
  const {
1851
1886
  basepath,
@@ -1894,7 +1929,7 @@
1894
1929
 
1895
1930
  router.cancelMatches(); // Match the routes
1896
1931
 
1897
- const matches = router.matchRoutes(location.pathname, {
1932
+ const matches = router.matchRoutes(router.location.pathname, {
1898
1933
  strictParseParams: true
1899
1934
  });
1900
1935
  router.state = _extends({}, router.state, {
@@ -2357,11 +2392,7 @@
2357
2392
  const recurseRoutes = (routeConfigs, parent) => {
2358
2393
  return routeConfigs.map(routeConfig => {
2359
2394
  const routeOptions = routeConfig.options;
2360
- const route = createRoute(routeConfig, routeOptions, parent, router); // {
2361
- // pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
2362
- // pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
2363
- // }
2364
-
2395
+ const route = createRoute(routeConfig, routeOptions, parent, router);
2365
2396
  const existingRoute = router.routesById[route.routeId];
2366
2397
 
2367
2398
  if (existingRoute) {
@@ -2496,8 +2527,6 @@
2496
2527
  }
2497
2528
  }
2498
2529
  };
2499
- router.location = router.__.parseLocation(history.location);
2500
- router.state.location = router.location;
2501
2530
  router.update(userOptions); // Allow frameworks to hook into the router creation
2502
2531
 
2503
2532
  router.options.createRouter == null ? void 0 : router.options.createRouter(router);
@@ -2802,13 +2831,6 @@
2802
2831
  this.state = {
2803
2832
  error: false
2804
2833
  };
2805
-
2806
- this.reset = () => {
2807
- this.setState({
2808
- error: false,
2809
- info: false
2810
- });
2811
- };
2812
2834
  }
2813
2835
 
2814
2836
  componentDidCatch(error, info) {
@@ -2924,6 +2946,7 @@
2924
2946
  exports.matchPathname = matchPathname;
2925
2947
  exports.parsePathname = parsePathname;
2926
2948
  exports.parseSearchWith = parseSearchWith;
2949
+ exports.pick = pick;
2927
2950
  exports.replaceEqualDeep = replaceEqualDeep;
2928
2951
  exports.resolvePath = resolvePath;
2929
2952
  exports.rootRouteId = rootRouteId;