@tanstack/react-router 0.0.1-beta.80 → 0.0.1-beta.82

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.
@@ -7,7 +7,7 @@
7
7
  "name": "index.production.js",
8
8
  "children": [
9
9
  {
10
- "uid": "5504-109",
10
+ "uid": "ea8f-113",
11
11
  "name": "\u0000rollupPluginBabelHelpers.js"
12
12
  },
13
13
  {
@@ -15,11 +15,11 @@
15
15
  "children": [
16
16
  {
17
17
  "name": "tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
18
- "uid": "5504-111"
18
+ "uid": "ea8f-115"
19
19
  },
20
20
  {
21
21
  "name": "tiny-warning@1.0.3/node_modules/tiny-warning/dist/tiny-warning.esm.js",
22
- "uid": "5504-113"
22
+ "uid": "ea8f-117"
23
23
  }
24
24
  ]
25
25
  },
@@ -28,19 +28,19 @@
28
28
  "children": [
29
29
  {
30
30
  "name": "store/build/esm/index.js",
31
- "uid": "5504-115"
31
+ "uid": "ea8f-119"
32
32
  },
33
33
  {
34
34
  "name": "router/build/esm/index.js",
35
- "uid": "5504-117"
35
+ "uid": "ea8f-121"
36
36
  },
37
37
  {
38
38
  "name": "react-store/build/esm/index.js",
39
- "uid": "5504-119"
39
+ "uid": "ea8f-123"
40
40
  },
41
41
  {
42
42
  "name": "react-router/src/index.tsx",
43
- "uid": "5504-121"
43
+ "uid": "ea8f-125"
44
44
  }
45
45
  ]
46
46
  }
@@ -50,176 +50,182 @@
50
50
  "isRoot": true
51
51
  },
52
52
  "nodeParts": {
53
- "5504-109": {
53
+ "ea8f-113": {
54
54
  "renderedLength": 429,
55
55
  "gzipLength": 238,
56
56
  "brotliLength": 0,
57
- "mainUid": "5504-108"
57
+ "mainUid": "ea8f-112"
58
58
  },
59
- "5504-111": {
59
+ "ea8f-115": {
60
60
  "renderedLength": 181,
61
61
  "gzipLength": 129,
62
62
  "brotliLength": 0,
63
- "mainUid": "5504-110"
63
+ "mainUid": "ea8f-114"
64
64
  },
65
- "5504-113": {
65
+ "ea8f-117": {
66
66
  "renderedLength": 44,
67
67
  "gzipLength": 62,
68
68
  "brotliLength": 0,
69
- "mainUid": "5504-112"
69
+ "mainUid": "ea8f-116"
70
70
  },
71
- "5504-115": {
72
- "renderedLength": 1288,
73
- "gzipLength": 497,
71
+ "ea8f-119": {
72
+ "renderedLength": 2382,
73
+ "gzipLength": 809,
74
74
  "brotliLength": 0,
75
- "mainUid": "5504-114"
75
+ "mainUid": "ea8f-118"
76
76
  },
77
- "5504-117": {
78
- "renderedLength": 49433,
79
- "gzipLength": 11720,
77
+ "ea8f-121": {
78
+ "renderedLength": 51237,
79
+ "gzipLength": 11956,
80
80
  "brotliLength": 0,
81
- "mainUid": "5504-116"
81
+ "mainUid": "ea8f-120"
82
82
  },
83
- "5504-119": {
84
- "renderedLength": 1571,
85
- "gzipLength": 594,
83
+ "ea8f-123": {
84
+ "renderedLength": 477,
85
+ "gzipLength": 284,
86
86
  "brotliLength": 0,
87
- "mainUid": "5504-118"
87
+ "mainUid": "ea8f-122"
88
88
  },
89
- "5504-121": {
90
- "renderedLength": 12297,
91
- "gzipLength": 3115,
89
+ "ea8f-125": {
90
+ "renderedLength": 12276,
91
+ "gzipLength": 3105,
92
92
  "brotliLength": 0,
93
- "mainUid": "5504-120"
93
+ "mainUid": "ea8f-124"
94
94
  }
95
95
  },
96
96
  "nodeMetas": {
97
- "5504-108": {
97
+ "ea8f-112": {
98
98
  "id": "\u0000rollupPluginBabelHelpers.js",
99
99
  "moduleParts": {
100
- "index.production.js": "5504-109"
100
+ "index.production.js": "ea8f-113"
101
101
  },
102
102
  "imported": [],
103
103
  "importedBy": [
104
104
  {
105
- "uid": "5504-120"
105
+ "uid": "ea8f-124"
106
106
  }
107
107
  ]
108
108
  },
109
- "5504-110": {
109
+ "ea8f-114": {
110
110
  "id": "/node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
111
111
  "moduleParts": {
112
- "index.production.js": "5504-111"
112
+ "index.production.js": "ea8f-115"
113
113
  },
114
114
  "imported": [],
115
115
  "importedBy": [
116
116
  {
117
- "uid": "5504-116"
117
+ "uid": "ea8f-120"
118
118
  }
119
119
  ]
120
120
  },
121
- "5504-112": {
121
+ "ea8f-116": {
122
122
  "id": "/node_modules/.pnpm/tiny-warning@1.0.3/node_modules/tiny-warning/dist/tiny-warning.esm.js",
123
123
  "moduleParts": {
124
- "index.production.js": "5504-113"
124
+ "index.production.js": "ea8f-117"
125
125
  },
126
126
  "imported": [],
127
127
  "importedBy": [
128
128
  {
129
- "uid": "5504-116"
129
+ "uid": "ea8f-120"
130
130
  }
131
131
  ]
132
132
  },
133
- "5504-114": {
133
+ "ea8f-118": {
134
134
  "id": "/packages/store/build/esm/index.js",
135
135
  "moduleParts": {
136
- "index.production.js": "5504-115"
136
+ "index.production.js": "ea8f-119"
137
137
  },
138
138
  "imported": [],
139
139
  "importedBy": [
140
140
  {
141
- "uid": "5504-116"
141
+ "uid": "ea8f-120"
142
+ },
143
+ {
144
+ "uid": "ea8f-122"
142
145
  }
143
146
  ]
144
147
  },
145
- "5504-116": {
148
+ "ea8f-120": {
146
149
  "id": "/packages/router/build/esm/index.js",
147
150
  "moduleParts": {
148
- "index.production.js": "5504-117"
151
+ "index.production.js": "ea8f-121"
149
152
  },
150
153
  "imported": [
151
154
  {
152
- "uid": "5504-110"
155
+ "uid": "ea8f-114"
153
156
  },
154
157
  {
155
- "uid": "5504-112"
158
+ "uid": "ea8f-116"
156
159
  },
157
160
  {
158
- "uid": "5504-114"
161
+ "uid": "ea8f-118"
159
162
  }
160
163
  ],
161
164
  "importedBy": [
162
165
  {
163
- "uid": "5504-120"
166
+ "uid": "ea8f-124"
164
167
  }
165
168
  ]
166
169
  },
167
- "5504-118": {
170
+ "ea8f-122": {
168
171
  "id": "/packages/react-store/build/esm/index.js",
169
172
  "moduleParts": {
170
- "index.production.js": "5504-119"
173
+ "index.production.js": "ea8f-123"
171
174
  },
172
175
  "imported": [
173
176
  {
174
- "uid": "5504-123"
177
+ "uid": "ea8f-118"
178
+ },
179
+ {
180
+ "uid": "ea8f-127"
175
181
  }
176
182
  ],
177
183
  "importedBy": [
178
184
  {
179
- "uid": "5504-120"
185
+ "uid": "ea8f-124"
180
186
  }
181
187
  ]
182
188
  },
183
- "5504-120": {
189
+ "ea8f-124": {
184
190
  "id": "/packages/react-router/src/index.tsx",
185
191
  "moduleParts": {
186
- "index.production.js": "5504-121"
192
+ "index.production.js": "ea8f-125"
187
193
  },
188
194
  "imported": [
189
195
  {
190
- "uid": "5504-108"
196
+ "uid": "ea8f-112"
191
197
  },
192
198
  {
193
- "uid": "5504-122"
199
+ "uid": "ea8f-126"
194
200
  },
195
201
  {
196
- "uid": "5504-116"
202
+ "uid": "ea8f-120"
197
203
  },
198
204
  {
199
- "uid": "5504-118"
205
+ "uid": "ea8f-122"
200
206
  }
201
207
  ],
202
208
  "importedBy": [],
203
209
  "isEntry": true
204
210
  },
205
- "5504-122": {
211
+ "ea8f-126": {
206
212
  "id": "react",
207
213
  "moduleParts": {},
208
214
  "imported": [],
209
215
  "importedBy": [
210
216
  {
211
- "uid": "5504-120"
217
+ "uid": "ea8f-124"
212
218
  }
213
219
  ],
214
220
  "isExternal": true
215
221
  },
216
- "5504-123": {
222
+ "ea8f-127": {
217
223
  "id": "use-sync-external-store/shim/with-selector",
218
224
  "moduleParts": {},
219
225
  "imported": [],
220
226
  "importedBy": [
221
227
  {
222
- "uid": "5504-118"
228
+ "uid": "ea8f-122"
223
229
  }
224
230
  ],
225
231
  "isExternal": true
@@ -125,6 +125,47 @@
125
125
  this.#flush();
126
126
  };
127
127
  }
128
+ function shallow(objA, objB) {
129
+ if (Object.is(objA, objB)) {
130
+ return true;
131
+ }
132
+ if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
133
+ return false;
134
+ }
135
+
136
+ // if (objA instanceof Map && objB instanceof Map) {
137
+ // if (objA.size !== objB.size) return false
138
+
139
+ // for (const [key, value] of objA) {
140
+ // if (!Object.is(value, objB.get(key))) {
141
+ // return false
142
+ // }
143
+ // }
144
+ // return true
145
+ // }
146
+
147
+ // if (objA instanceof Set && objB instanceof Set) {
148
+ // if (objA.size !== objB.size) return false
149
+
150
+ // for (const value of objA) {
151
+ // if (!objB.has(value)) {
152
+ // return false
153
+ // }
154
+ // }
155
+ // return true
156
+ // }
157
+
158
+ const keysA = Object.keys(objA);
159
+ if (keysA.length !== Object.keys(objB).length) {
160
+ return false;
161
+ }
162
+ for (let i = 0; i < keysA.length; i++) {
163
+ if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
164
+ return false;
165
+ }
166
+ }
167
+ return true;
168
+ }
128
169
 
129
170
  /**
130
171
  * router
@@ -1129,23 +1170,57 @@
1129
1170
  return matches;
1130
1171
  };
1131
1172
  loadMatches = async (resolvedMatches, location, opts) => {
1173
+ let firstBadMatchIndex;
1174
+
1132
1175
  // Check each match middleware to see if the route can be accessed
1133
- await Promise.all(resolvedMatches.map(async match => {
1134
- try {
1135
- await match.route.options.beforeLoad?.({
1136
- router: this,
1137
- match
1138
- });
1139
- } catch (err) {
1176
+ try {
1177
+ await Promise.all(resolvedMatches.map(async (match, index) => {
1178
+ try {
1179
+ await match.route.options.beforeLoad?.({
1180
+ router: this,
1181
+ match
1182
+ });
1183
+ } catch (err) {
1184
+ if (isRedirect(err)) {
1185
+ throw err;
1186
+ }
1187
+ firstBadMatchIndex = firstBadMatchIndex ?? index;
1188
+ const errorHandler = match.route.options.onBeforeLoadError ?? match.route.options.onError;
1189
+ try {
1190
+ errorHandler?.(err);
1191
+ } catch (errorHandlerErr) {
1192
+ if (isRedirect(errorHandlerErr)) {
1193
+ throw errorHandlerErr;
1194
+ }
1195
+ match.__store.setState(s => ({
1196
+ ...s,
1197
+ error: errorHandlerErr,
1198
+ status: 'error',
1199
+ updatedAt: Date.now()
1200
+ }));
1201
+ return;
1202
+ }
1203
+ match.__store.setState(s => ({
1204
+ ...s,
1205
+ error: err,
1206
+ status: 'error',
1207
+ updatedAt: Date.now()
1208
+ }));
1209
+ }
1210
+ }));
1211
+ } catch (err) {
1212
+ if (isRedirect(err)) {
1140
1213
  if (!opts?.preload) {
1141
- match.route.options.onBeforeLoadError?.(err);
1214
+ this.navigate(err);
1142
1215
  }
1143
- match.route.options.onError?.(err);
1144
- throw err;
1216
+ return;
1145
1217
  }
1146
- }));
1147
- const matchPromises = resolvedMatches.map(async (match, index) => {
1148
- const parentMatch = resolvedMatches[index - 1];
1218
+ throw err; // we should never end up here
1219
+ }
1220
+
1221
+ const validResolvedMatches = resolvedMatches.slice(0, firstBadMatchIndex);
1222
+ const matchPromises = validResolvedMatches.map(async (match, index) => {
1223
+ const parentMatch = validResolvedMatches[index - 1];
1149
1224
  match.__load({
1150
1225
  preload: opts?.preload,
1151
1226
  location,
@@ -1621,7 +1696,8 @@
1621
1696
  if (isRedirect(err)) {
1622
1697
  throw err;
1623
1698
  }
1624
- this.route.options.onValidateSearchError?.(err);
1699
+ const errorHandler = this.route.options.onValidateSearchError ?? this.route.options.onError;
1700
+ errorHandler?.(err);
1625
1701
  const error = new Error('Invalid search params found', {
1626
1702
  cause: err
1627
1703
  });
@@ -1634,22 +1710,27 @@
1634
1710
  search,
1635
1711
  routeSearch
1636
1712
  } = this.#resolveSearchInfo(opts);
1637
- const routeContext = this.route.options.getContext?.({
1638
- parentContext: this.parentMatch?.routeContext ?? {},
1639
- context: this.parentMatch?.context ?? this.router?.options.context ?? {},
1640
- params: this.params,
1641
- search
1642
- }) || {};
1643
- const context = {
1644
- ...(this.parentMatch?.context ?? this.router?.options.context),
1645
- ...routeContext
1646
- };
1647
- return {
1648
- routeSearch,
1649
- search,
1650
- context,
1651
- routeContext
1652
- };
1713
+ try {
1714
+ const routeContext = this.route.options.getContext?.({
1715
+ parentContext: this.parentMatch?.routeContext ?? {},
1716
+ context: this.parentMatch?.context ?? this.router?.options.context ?? {},
1717
+ params: this.params,
1718
+ search
1719
+ }) || {};
1720
+ const context = {
1721
+ ...(this.parentMatch?.context ?? this.router?.options.context),
1722
+ ...routeContext
1723
+ };
1724
+ return {
1725
+ routeSearch,
1726
+ search,
1727
+ context,
1728
+ routeContext
1729
+ };
1730
+ } catch (err) {
1731
+ this.route.options.onError?.(err);
1732
+ throw err;
1733
+ }
1653
1734
  };
1654
1735
  __load = async opts => {
1655
1736
  this.parentMatch = opts.parentMatch;
@@ -1658,10 +1739,11 @@
1658
1739
  info = this.#resolveInfo(opts);
1659
1740
  } catch (err) {
1660
1741
  if (isRedirect(err)) {
1661
- this.router.navigate(err);
1742
+ if (!opts?.preload) {
1743
+ this.router.navigate(err);
1744
+ }
1662
1745
  return;
1663
1746
  }
1664
- this.route.options.onError?.(err);
1665
1747
  this.__store.setState(s => ({
1666
1748
  ...s,
1667
1749
  status: 'error',
@@ -1737,11 +1819,29 @@
1737
1819
  }));
1738
1820
  } catch (err) {
1739
1821
  if (isRedirect(err)) {
1740
- this.router.navigate(err);
1822
+ if (!opts?.preload) {
1823
+ this.router.navigate(err);
1824
+ }
1825
+ return;
1826
+ }
1827
+ const errorHandler = this.route.options.onLoadError ?? this.route.options.onError;
1828
+ try {
1829
+ errorHandler?.(err);
1830
+ } catch (errorHandlerErr) {
1831
+ if (isRedirect(errorHandlerErr)) {
1832
+ if (!opts?.preload) {
1833
+ this.router.navigate(errorHandlerErr);
1834
+ }
1835
+ return;
1836
+ }
1837
+ this.__store.setState(s => ({
1838
+ ...s,
1839
+ error: errorHandlerErr,
1840
+ status: 'error',
1841
+ updatedAt: Date.now()
1842
+ }));
1741
1843
  return;
1742
1844
  }
1743
- this.route.options.onLoadError?.(err);
1744
- this.route.options.onError?.(err);
1745
1845
  this.__store.setState(s => ({
1746
1846
  ...s,
1747
1847
  error: err,
@@ -1772,47 +1872,6 @@
1772
1872
  const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, compareShallow ? shallow : undefined);
1773
1873
  return slice;
1774
1874
  }
1775
- function shallow(objA, objB) {
1776
- if (Object.is(objA, objB)) {
1777
- return true;
1778
- }
1779
- if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
1780
- return false;
1781
- }
1782
-
1783
- // if (objA instanceof Map && objB instanceof Map) {
1784
- // if (objA.size !== objB.size) return false
1785
-
1786
- // for (const [key, value] of objA) {
1787
- // if (!Object.is(value, objB.get(key))) {
1788
- // return false
1789
- // }
1790
- // }
1791
- // return true
1792
- // }
1793
-
1794
- // if (objA instanceof Set && objB instanceof Set) {
1795
- // if (objA.size !== objB.size) return false
1796
-
1797
- // for (const value of objA) {
1798
- // if (!objB.has(value)) {
1799
- // return false
1800
- // }
1801
- // }
1802
- // return true
1803
- // }
1804
-
1805
- const keysA = Object.keys(objA);
1806
- if (keysA.length !== Object.keys(objB).length) {
1807
- return false;
1808
- }
1809
- for (let i = 0; i < keysA.length; i++) {
1810
- if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
1811
- return false;
1812
- }
1813
- }
1814
- return true;
1815
- }
1816
1875
 
1817
1876
  //
1818
1877
 
@@ -2076,18 +2135,6 @@
2076
2135
  const router = useRouterContext();
2077
2136
  useStore(match.__store, store => [store.status, store.error], true);
2078
2137
  const defaultPending = React__namespace.useCallback(() => null, []);
2079
- const Inner = React__namespace.useCallback(props => {
2080
- if (props.match.state.status === 'error') {
2081
- throw props.match.state.error;
2082
- }
2083
- if (props.match.state.status === 'success') {
2084
- return /*#__PURE__*/React__namespace.createElement(props.match.component ?? router.options.defaultComponent ?? Outlet);
2085
- }
2086
- if (props.match.state.status === 'pending') {
2087
- throw props.match.__loadPromise;
2088
- }
2089
- invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
2090
- }, []);
2091
2138
  const PendingComponent = match.pendingComponent ?? router.options.defaultPendingComponent ?? defaultPending;
2092
2139
  const errorComponent = match.errorComponent ?? router.options.defaultErrorComponent;
2093
2140
  const ResolvedSuspenseBoundary = match.route.options.wrapInSuspense ?? true ? React__namespace.Suspense : SafeFragment;
@@ -2106,6 +2153,19 @@
2106
2153
  match: match
2107
2154
  }))));
2108
2155
  }
2156
+ function Inner(props) {
2157
+ const router = useRouterContext();
2158
+ if (props.match.state.status === 'error') {
2159
+ throw props.match.state.error;
2160
+ }
2161
+ if (props.match.state.status === 'success') {
2162
+ return /*#__PURE__*/React__namespace.createElement(props.match.component ?? router.options.defaultComponent ?? Outlet);
2163
+ }
2164
+ if (props.match.state.status === 'pending') {
2165
+ throw props.match.__loadPromise;
2166
+ }
2167
+ invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
2168
+ }
2109
2169
  function SafeFragment(props) {
2110
2170
  return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, props.children);
2111
2171
  }