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

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": "298b-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": "298b-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": "298b-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": "298b-119"
32
32
  },
33
33
  {
34
34
  "name": "router/build/esm/index.js",
35
- "uid": "5504-117"
35
+ "uid": "298b-121"
36
36
  },
37
37
  {
38
38
  "name": "react-store/build/esm/index.js",
39
- "uid": "5504-119"
39
+ "uid": "298b-123"
40
40
  },
41
41
  {
42
42
  "name": "react-router/src/index.tsx",
43
- "uid": "5504-121"
43
+ "uid": "298b-125"
44
44
  }
45
45
  ]
46
46
  }
@@ -50,176 +50,182 @@
50
50
  "isRoot": true
51
51
  },
52
52
  "nodeParts": {
53
- "5504-109": {
53
+ "298b-113": {
54
54
  "renderedLength": 429,
55
55
  "gzipLength": 238,
56
56
  "brotliLength": 0,
57
- "mainUid": "5504-108"
57
+ "mainUid": "298b-112"
58
58
  },
59
- "5504-111": {
59
+ "298b-115": {
60
60
  "renderedLength": 181,
61
61
  "gzipLength": 129,
62
62
  "brotliLength": 0,
63
- "mainUid": "5504-110"
63
+ "mainUid": "298b-114"
64
64
  },
65
- "5504-113": {
65
+ "298b-117": {
66
66
  "renderedLength": 44,
67
67
  "gzipLength": 62,
68
68
  "brotliLength": 0,
69
- "mainUid": "5504-112"
69
+ "mainUid": "298b-116"
70
70
  },
71
- "5504-115": {
72
- "renderedLength": 1288,
73
- "gzipLength": 497,
71
+ "298b-119": {
72
+ "renderedLength": 2382,
73
+ "gzipLength": 809,
74
74
  "brotliLength": 0,
75
- "mainUid": "5504-114"
75
+ "mainUid": "298b-118"
76
76
  },
77
- "5504-117": {
78
- "renderedLength": 49433,
79
- "gzipLength": 11720,
77
+ "298b-121": {
78
+ "renderedLength": 50465,
79
+ "gzipLength": 11828,
80
80
  "brotliLength": 0,
81
- "mainUid": "5504-116"
81
+ "mainUid": "298b-120"
82
82
  },
83
- "5504-119": {
84
- "renderedLength": 1571,
85
- "gzipLength": 594,
83
+ "298b-123": {
84
+ "renderedLength": 477,
85
+ "gzipLength": 284,
86
86
  "brotliLength": 0,
87
- "mainUid": "5504-118"
87
+ "mainUid": "298b-122"
88
88
  },
89
- "5504-121": {
90
- "renderedLength": 12297,
91
- "gzipLength": 3115,
89
+ "298b-125": {
90
+ "renderedLength": 12276,
91
+ "gzipLength": 3105,
92
92
  "brotliLength": 0,
93
- "mainUid": "5504-120"
93
+ "mainUid": "298b-124"
94
94
  }
95
95
  },
96
96
  "nodeMetas": {
97
- "5504-108": {
97
+ "298b-112": {
98
98
  "id": "\u0000rollupPluginBabelHelpers.js",
99
99
  "moduleParts": {
100
- "index.production.js": "5504-109"
100
+ "index.production.js": "298b-113"
101
101
  },
102
102
  "imported": [],
103
103
  "importedBy": [
104
104
  {
105
- "uid": "5504-120"
105
+ "uid": "298b-124"
106
106
  }
107
107
  ]
108
108
  },
109
- "5504-110": {
109
+ "298b-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": "298b-115"
113
113
  },
114
114
  "imported": [],
115
115
  "importedBy": [
116
116
  {
117
- "uid": "5504-116"
117
+ "uid": "298b-120"
118
118
  }
119
119
  ]
120
120
  },
121
- "5504-112": {
121
+ "298b-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": "298b-117"
125
125
  },
126
126
  "imported": [],
127
127
  "importedBy": [
128
128
  {
129
- "uid": "5504-116"
129
+ "uid": "298b-120"
130
130
  }
131
131
  ]
132
132
  },
133
- "5504-114": {
133
+ "298b-118": {
134
134
  "id": "/packages/store/build/esm/index.js",
135
135
  "moduleParts": {
136
- "index.production.js": "5504-115"
136
+ "index.production.js": "298b-119"
137
137
  },
138
138
  "imported": [],
139
139
  "importedBy": [
140
140
  {
141
- "uid": "5504-116"
141
+ "uid": "298b-120"
142
+ },
143
+ {
144
+ "uid": "298b-122"
142
145
  }
143
146
  ]
144
147
  },
145
- "5504-116": {
148
+ "298b-120": {
146
149
  "id": "/packages/router/build/esm/index.js",
147
150
  "moduleParts": {
148
- "index.production.js": "5504-117"
151
+ "index.production.js": "298b-121"
149
152
  },
150
153
  "imported": [
151
154
  {
152
- "uid": "5504-110"
155
+ "uid": "298b-114"
153
156
  },
154
157
  {
155
- "uid": "5504-112"
158
+ "uid": "298b-116"
156
159
  },
157
160
  {
158
- "uid": "5504-114"
161
+ "uid": "298b-118"
159
162
  }
160
163
  ],
161
164
  "importedBy": [
162
165
  {
163
- "uid": "5504-120"
166
+ "uid": "298b-124"
164
167
  }
165
168
  ]
166
169
  },
167
- "5504-118": {
170
+ "298b-122": {
168
171
  "id": "/packages/react-store/build/esm/index.js",
169
172
  "moduleParts": {
170
- "index.production.js": "5504-119"
173
+ "index.production.js": "298b-123"
171
174
  },
172
175
  "imported": [
173
176
  {
174
- "uid": "5504-123"
177
+ "uid": "298b-118"
178
+ },
179
+ {
180
+ "uid": "298b-127"
175
181
  }
176
182
  ],
177
183
  "importedBy": [
178
184
  {
179
- "uid": "5504-120"
185
+ "uid": "298b-124"
180
186
  }
181
187
  ]
182
188
  },
183
- "5504-120": {
189
+ "298b-124": {
184
190
  "id": "/packages/react-router/src/index.tsx",
185
191
  "moduleParts": {
186
- "index.production.js": "5504-121"
192
+ "index.production.js": "298b-125"
187
193
  },
188
194
  "imported": [
189
195
  {
190
- "uid": "5504-108"
196
+ "uid": "298b-112"
191
197
  },
192
198
  {
193
- "uid": "5504-122"
199
+ "uid": "298b-126"
194
200
  },
195
201
  {
196
- "uid": "5504-116"
202
+ "uid": "298b-120"
197
203
  },
198
204
  {
199
- "uid": "5504-118"
205
+ "uid": "298b-122"
200
206
  }
201
207
  ],
202
208
  "importedBy": [],
203
209
  "isEntry": true
204
210
  },
205
- "5504-122": {
211
+ "298b-126": {
206
212
  "id": "react",
207
213
  "moduleParts": {},
208
214
  "imported": [],
209
215
  "importedBy": [
210
216
  {
211
- "uid": "5504-120"
217
+ "uid": "298b-124"
212
218
  }
213
219
  ],
214
220
  "isExternal": true
215
221
  },
216
- "5504-123": {
222
+ "298b-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": "298b-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
@@ -1130,20 +1171,31 @@
1130
1171
  };
1131
1172
  loadMatches = async (resolvedMatches, location, opts) => {
1132
1173
  // 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) {
1174
+ try {
1175
+ await Promise.all(resolvedMatches.map(async match => {
1176
+ try {
1177
+ await match.route.options.beforeLoad?.({
1178
+ router: this,
1179
+ match
1180
+ });
1181
+ } catch (err) {
1182
+ if (isRedirect(err)) {
1183
+ throw err;
1184
+ }
1185
+ const errorHandler = match.route.options.onBeforeLoadError ?? match.route.options.onError;
1186
+ errorHandler?.(err);
1187
+ throw err;
1188
+ }
1189
+ }));
1190
+ } catch (err) {
1191
+ if (isRedirect(err)) {
1140
1192
  if (!opts?.preload) {
1141
- match.route.options.onBeforeLoadError?.(err);
1193
+ this.navigate(err);
1142
1194
  }
1143
- match.route.options.onError?.(err);
1144
- throw err;
1195
+ return;
1145
1196
  }
1146
- }));
1197
+ throw err;
1198
+ }
1147
1199
  const matchPromises = resolvedMatches.map(async (match, index) => {
1148
1200
  const parentMatch = resolvedMatches[index - 1];
1149
1201
  match.__load({
@@ -1621,7 +1673,8 @@
1621
1673
  if (isRedirect(err)) {
1622
1674
  throw err;
1623
1675
  }
1624
- this.route.options.onValidateSearchError?.(err);
1676
+ const errorHandler = this.route.options.onValidateSearchError ?? this.route.options.onError;
1677
+ errorHandler?.(err);
1625
1678
  const error = new Error('Invalid search params found', {
1626
1679
  cause: err
1627
1680
  });
@@ -1634,22 +1687,27 @@
1634
1687
  search,
1635
1688
  routeSearch
1636
1689
  } = 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
- };
1690
+ try {
1691
+ const routeContext = this.route.options.getContext?.({
1692
+ parentContext: this.parentMatch?.routeContext ?? {},
1693
+ context: this.parentMatch?.context ?? this.router?.options.context ?? {},
1694
+ params: this.params,
1695
+ search
1696
+ }) || {};
1697
+ const context = {
1698
+ ...(this.parentMatch?.context ?? this.router?.options.context),
1699
+ ...routeContext
1700
+ };
1701
+ return {
1702
+ routeSearch,
1703
+ search,
1704
+ context,
1705
+ routeContext
1706
+ };
1707
+ } catch (err) {
1708
+ this.route.options.onError?.(err);
1709
+ throw err;
1710
+ }
1653
1711
  };
1654
1712
  __load = async opts => {
1655
1713
  this.parentMatch = opts.parentMatch;
@@ -1658,10 +1716,11 @@
1658
1716
  info = this.#resolveInfo(opts);
1659
1717
  } catch (err) {
1660
1718
  if (isRedirect(err)) {
1661
- this.router.navigate(err);
1719
+ if (!opts?.preload) {
1720
+ this.router.navigate(err);
1721
+ }
1662
1722
  return;
1663
1723
  }
1664
- this.route.options.onError?.(err);
1665
1724
  this.__store.setState(s => ({
1666
1725
  ...s,
1667
1726
  status: 'error',
@@ -1737,11 +1796,29 @@
1737
1796
  }));
1738
1797
  } catch (err) {
1739
1798
  if (isRedirect(err)) {
1740
- this.router.navigate(err);
1799
+ if (!opts?.preload) {
1800
+ this.router.navigate(err);
1801
+ }
1802
+ return;
1803
+ }
1804
+ const errorHandler = this.route.options.onLoadError ?? this.route.options.onError;
1805
+ try {
1806
+ errorHandler?.(err);
1807
+ } catch (errorHandlerErr) {
1808
+ if (isRedirect(errorHandlerErr)) {
1809
+ if (!opts?.preload) {
1810
+ this.router.navigate(errorHandlerErr);
1811
+ }
1812
+ return;
1813
+ }
1814
+ this.__store.setState(s => ({
1815
+ ...s,
1816
+ error: errorHandlerErr,
1817
+ status: 'error',
1818
+ updatedAt: Date.now()
1819
+ }));
1741
1820
  return;
1742
1821
  }
1743
- this.route.options.onLoadError?.(err);
1744
- this.route.options.onError?.(err);
1745
1822
  this.__store.setState(s => ({
1746
1823
  ...s,
1747
1824
  error: err,
@@ -1772,47 +1849,6 @@
1772
1849
  const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, compareShallow ? shallow : undefined);
1773
1850
  return slice;
1774
1851
  }
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
1852
 
1817
1853
  //
1818
1854
 
@@ -2076,18 +2112,6 @@
2076
2112
  const router = useRouterContext();
2077
2113
  useStore(match.__store, store => [store.status, store.error], true);
2078
2114
  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
2115
  const PendingComponent = match.pendingComponent ?? router.options.defaultPendingComponent ?? defaultPending;
2092
2116
  const errorComponent = match.errorComponent ?? router.options.defaultErrorComponent;
2093
2117
  const ResolvedSuspenseBoundary = match.route.options.wrapInSuspense ?? true ? React__namespace.Suspense : SafeFragment;
@@ -2106,6 +2130,19 @@
2106
2130
  match: match
2107
2131
  }))));
2108
2132
  }
2133
+ function Inner(props) {
2134
+ const router = useRouterContext();
2135
+ if (props.match.state.status === 'error') {
2136
+ throw props.match.state.error;
2137
+ }
2138
+ if (props.match.state.status === 'success') {
2139
+ return /*#__PURE__*/React__namespace.createElement(props.match.component ?? router.options.defaultComponent ?? Outlet);
2140
+ }
2141
+ if (props.match.state.status === 'pending') {
2142
+ throw props.match.__loadPromise;
2143
+ }
2144
+ invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
2145
+ }
2109
2146
  function SafeFragment(props) {
2110
2147
  return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, props.children);
2111
2148
  }