@tanstack/react-router 0.0.1-beta.63 → 0.0.1-beta.64

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,31 +7,31 @@
7
7
  "name": "index.production.js",
8
8
  "children": [
9
9
  {
10
- "uid": "cf24-103",
10
+ "uid": "8d6c-103",
11
11
  "name": "\u0000rollupPluginBabelHelpers.js"
12
12
  },
13
13
  {
14
14
  "name": "node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
15
- "uid": "cf24-105"
15
+ "uid": "8d6c-105"
16
16
  },
17
17
  {
18
18
  "name": "packages",
19
19
  "children": [
20
20
  {
21
21
  "name": "store/build/esm/index.js",
22
- "uid": "cf24-107"
22
+ "uid": "8d6c-107"
23
23
  },
24
24
  {
25
25
  "name": "router/build/esm/index.js",
26
- "uid": "cf24-109"
26
+ "uid": "8d6c-109"
27
27
  },
28
28
  {
29
29
  "name": "react-store/build/esm/index.js",
30
- "uid": "cf24-111"
30
+ "uid": "8d6c-111"
31
31
  },
32
32
  {
33
33
  "name": "react-router/src/index.tsx",
34
- "uid": "cf24-113"
34
+ "uid": "8d6c-113"
35
35
  }
36
36
  ]
37
37
  }
@@ -41,155 +41,155 @@
41
41
  "isRoot": true
42
42
  },
43
43
  "nodeParts": {
44
- "cf24-103": {
44
+ "8d6c-103": {
45
45
  "renderedLength": 429,
46
46
  "gzipLength": 238,
47
47
  "brotliLength": 0,
48
- "mainUid": "cf24-102"
48
+ "mainUid": "8d6c-102"
49
49
  },
50
- "cf24-105": {
50
+ "8d6c-105": {
51
51
  "renderedLength": 181,
52
52
  "gzipLength": 129,
53
53
  "brotliLength": 0,
54
- "mainUid": "cf24-104"
54
+ "mainUid": "8d6c-104"
55
55
  },
56
- "cf24-107": {
56
+ "8d6c-107": {
57
57
  "renderedLength": 1288,
58
58
  "gzipLength": 497,
59
59
  "brotliLength": 0,
60
- "mainUid": "cf24-106"
60
+ "mainUid": "8d6c-106"
61
61
  },
62
- "cf24-109": {
63
- "renderedLength": 44953,
64
- "gzipLength": 10850,
62
+ "8d6c-109": {
63
+ "renderedLength": 45412,
64
+ "gzipLength": 10895,
65
65
  "brotliLength": 0,
66
- "mainUid": "cf24-108"
66
+ "mainUid": "8d6c-108"
67
67
  },
68
- "cf24-111": {
68
+ "8d6c-111": {
69
69
  "renderedLength": 1571,
70
70
  "gzipLength": 594,
71
71
  "brotliLength": 0,
72
- "mainUid": "cf24-110"
72
+ "mainUid": "8d6c-110"
73
73
  },
74
- "cf24-113": {
75
- "renderedLength": 12098,
76
- "gzipLength": 3161,
74
+ "8d6c-113": {
75
+ "renderedLength": 12077,
76
+ "gzipLength": 3154,
77
77
  "brotliLength": 0,
78
- "mainUid": "cf24-112"
78
+ "mainUid": "8d6c-112"
79
79
  }
80
80
  },
81
81
  "nodeMetas": {
82
- "cf24-102": {
82
+ "8d6c-102": {
83
83
  "id": "\u0000rollupPluginBabelHelpers.js",
84
84
  "moduleParts": {
85
- "index.production.js": "cf24-103"
85
+ "index.production.js": "8d6c-103"
86
86
  },
87
87
  "imported": [],
88
88
  "importedBy": [
89
89
  {
90
- "uid": "cf24-112"
90
+ "uid": "8d6c-112"
91
91
  }
92
92
  ]
93
93
  },
94
- "cf24-104": {
94
+ "8d6c-104": {
95
95
  "id": "/node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
96
96
  "moduleParts": {
97
- "index.production.js": "cf24-105"
97
+ "index.production.js": "8d6c-105"
98
98
  },
99
99
  "imported": [],
100
100
  "importedBy": [
101
101
  {
102
- "uid": "cf24-108"
102
+ "uid": "8d6c-108"
103
103
  }
104
104
  ]
105
105
  },
106
- "cf24-106": {
106
+ "8d6c-106": {
107
107
  "id": "/packages/store/build/esm/index.js",
108
108
  "moduleParts": {
109
- "index.production.js": "cf24-107"
109
+ "index.production.js": "8d6c-107"
110
110
  },
111
111
  "imported": [],
112
112
  "importedBy": [
113
113
  {
114
- "uid": "cf24-108"
114
+ "uid": "8d6c-108"
115
115
  }
116
116
  ]
117
117
  },
118
- "cf24-108": {
118
+ "8d6c-108": {
119
119
  "id": "/packages/router/build/esm/index.js",
120
120
  "moduleParts": {
121
- "index.production.js": "cf24-109"
121
+ "index.production.js": "8d6c-109"
122
122
  },
123
123
  "imported": [
124
124
  {
125
- "uid": "cf24-104"
125
+ "uid": "8d6c-104"
126
126
  },
127
127
  {
128
- "uid": "cf24-106"
128
+ "uid": "8d6c-106"
129
129
  }
130
130
  ],
131
131
  "importedBy": [
132
132
  {
133
- "uid": "cf24-112"
133
+ "uid": "8d6c-112"
134
134
  }
135
135
  ]
136
136
  },
137
- "cf24-110": {
137
+ "8d6c-110": {
138
138
  "id": "/packages/react-store/build/esm/index.js",
139
139
  "moduleParts": {
140
- "index.production.js": "cf24-111"
140
+ "index.production.js": "8d6c-111"
141
141
  },
142
142
  "imported": [
143
143
  {
144
- "uid": "cf24-115"
144
+ "uid": "8d6c-115"
145
145
  }
146
146
  ],
147
147
  "importedBy": [
148
148
  {
149
- "uid": "cf24-112"
149
+ "uid": "8d6c-112"
150
150
  }
151
151
  ]
152
152
  },
153
- "cf24-112": {
153
+ "8d6c-112": {
154
154
  "id": "/packages/react-router/src/index.tsx",
155
155
  "moduleParts": {
156
- "index.production.js": "cf24-113"
156
+ "index.production.js": "8d6c-113"
157
157
  },
158
158
  "imported": [
159
159
  {
160
- "uid": "cf24-102"
160
+ "uid": "8d6c-102"
161
161
  },
162
162
  {
163
- "uid": "cf24-114"
163
+ "uid": "8d6c-114"
164
164
  },
165
165
  {
166
- "uid": "cf24-108"
166
+ "uid": "8d6c-108"
167
167
  },
168
168
  {
169
- "uid": "cf24-110"
169
+ "uid": "8d6c-110"
170
170
  }
171
171
  ],
172
172
  "importedBy": [],
173
173
  "isEntry": true
174
174
  },
175
- "cf24-114": {
175
+ "8d6c-114": {
176
176
  "id": "react",
177
177
  "moduleParts": {},
178
178
  "imported": [],
179
179
  "importedBy": [
180
180
  {
181
- "uid": "cf24-112"
181
+ "uid": "8d6c-112"
182
182
  }
183
183
  ],
184
184
  "isExternal": true
185
185
  },
186
- "cf24-115": {
186
+ "8d6c-115": {
187
187
  "id": "use-sync-external-store/shim/with-selector",
188
188
  "moduleParts": {},
189
189
  "imported": [],
190
190
  "importedBy": [
191
191
  {
192
- "uid": "cf24-110"
192
+ "uid": "8d6c-110"
193
193
  }
194
194
  ],
195
195
  "isExternal": true
@@ -686,8 +686,6 @@
686
686
  // const config = rootRoute.addChildren([aRoute.addChildren([bRoute])])
687
687
  // // ^?
688
688
 
689
- //
690
-
691
689
  const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
692
690
  class RouteMatch {
693
691
  abortController = new AbortController();
@@ -721,40 +719,42 @@
721
719
  #hasLoaders = () => {
722
720
  return !!(this.route.options.onLoad || componentTypes.some(d => this.route.options[d]?.preload));
723
721
  };
724
- __init = opts => {
722
+ __commit = () => {
723
+ const {
724
+ routeSearch,
725
+ search,
726
+ context,
727
+ routeContext
728
+ } = this.#resolveInfo({
729
+ location: this.router.state.currentLocation
730
+ });
731
+ this.context = context;
732
+ this.routeContext = routeContext;
733
+ this.store.setState(s => ({
734
+ ...s,
735
+ routeSearch: replaceEqualDeep(s.routeSearch, routeSearch),
736
+ search: replaceEqualDeep(s.search, search)
737
+ }));
738
+ };
739
+ cancel = () => {
740
+ this.abortController?.abort();
741
+ };
742
+ #resolveSearchInfo = opts => {
725
743
  // Validate the search params and stabilize them
726
- this.parentMatch = opts.parentMatch;
727
- const parentSearch = this.parentMatch?.state.search ?? this.router.state.latestLocation.search;
744
+ const parentSearchInfo = this.parentMatch ? this.parentMatch.#resolveSearchInfo(opts) : {
745
+ search: opts.location.search,
746
+ routeSearch: opts.location.search
747
+ };
728
748
  try {
729
749
  const validator = typeof this.route.options.validateSearch === 'object' ? this.route.options.validateSearch.parse : this.route.options.validateSearch;
730
- let nextSearch = validator?.(parentSearch) ?? {};
731
- this.store.setState(s => ({
732
- ...s,
733
- routeSearch: nextSearch,
734
- search: {
735
- ...parentSearch,
736
- ...nextSearch
737
- }
738
- }));
739
- componentTypes.map(async type => {
740
- const component = this.route.options[type];
741
- if (typeof this[type] !== 'function') {
742
- this[type] = component;
743
- }
744
- });
745
- const parent = this.parentMatch;
746
- this.routeContext = this.route.options.getContext?.({
747
- parentContext: parent?.routeContext,
748
- context: parent?.context,
749
- params: this.params,
750
- search: this.state.search
751
- }) || {};
752
- this.context = parent ? {
753
- ...parent.context,
754
- ...this.routeContext
755
- } : {
756
- ...this.router?.options.context,
757
- ...this.routeContext
750
+ const routeSearch = validator?.(parentSearchInfo.search) ?? {};
751
+ const search = {
752
+ ...parentSearchInfo.search,
753
+ ...routeSearch
754
+ };
755
+ return {
756
+ routeSearch,
757
+ search
758
758
  };
759
759
  } catch (err) {
760
760
  console.error(err);
@@ -762,27 +762,65 @@
762
762
  cause: err
763
763
  });
764
764
  error.code = 'INVALID_SEARCH_PARAMS';
765
+ throw error;
766
+ }
767
+ };
768
+ #resolveInfo = opts => {
769
+ const {
770
+ search,
771
+ routeSearch
772
+ } = this.#resolveSearchInfo(opts);
773
+ const routeContext = this.route.options.getContext?.({
774
+ parentContext: this.parentMatch?.routeContext ?? {},
775
+ context: this.parentMatch?.context ?? this.router?.options.context ?? {},
776
+ params: this.params,
777
+ search
778
+ }) || {};
779
+ const context = {
780
+ ...(this.parentMatch?.context ?? this.router?.options.context),
781
+ ...routeContext
782
+ };
783
+ return {
784
+ routeSearch,
785
+ search,
786
+ context,
787
+ routeContext
788
+ };
789
+ };
790
+ __load = async opts => {
791
+ this.parentMatch = opts.parentMatch;
792
+ let info;
793
+ try {
794
+ info = this.#resolveInfo(opts);
795
+ } catch (err) {
765
796
  this.store.setState(s => ({
766
797
  ...s,
767
798
  status: 'error',
768
- error: error
799
+ error: err
769
800
  }));
770
801
 
771
802
  // Do not proceed with loading the route
772
803
  return;
773
804
  }
774
- };
775
- cancel = () => {
776
- this.abortController?.abort();
777
- };
778
- load = async opts => {
805
+ const {
806
+ routeSearch,
807
+ search,
808
+ context,
809
+ routeContext
810
+ } = info;
811
+ componentTypes.map(async type => {
812
+ const component = this.route.options[type];
813
+ if (typeof this[type] !== 'function') {
814
+ this[type] = component;
815
+ }
816
+ });
817
+
779
818
  // If the match is invalid, errored or idle, trigger it to load
780
- if (this.state.status !== 'pending') {
781
- await this.fetch(opts);
819
+ if (this.state.status === 'pending') {
820
+ return;
782
821
  }
783
- };
784
- #latestId = '';
785
- fetch = async opts => {
822
+
823
+ // TODO: Should load promises be tracked based on location?
786
824
  this.__loadPromise = Promise.resolve().then(async () => {
787
825
  const loadId = '' + Date.now() + Math.random();
788
826
  this.#latestId = loadId;
@@ -790,17 +828,16 @@
790
828
  return loadId !== this.#latestId ? this.__loadPromise : undefined;
791
829
  };
792
830
  let latestPromise;
793
- this.store.batch(() => {
794
- // If the match was in an error state, set it
795
- // to a loading state again. Otherwise, keep it
796
- // as loading or resolved
797
- if (this.state.status === 'idle') {
798
- this.store.setState(s => ({
799
- ...s,
800
- status: 'pending'
801
- }));
802
- }
803
- });
831
+
832
+ // If the match was in an error state, set it
833
+ // to a loading state again. Otherwise, keep it
834
+ // as loading or resolved
835
+ if (this.state.status === 'idle') {
836
+ this.store.setState(s => ({
837
+ ...s,
838
+ status: 'pending'
839
+ }));
840
+ }
804
841
  const componentsPromise = (async () => {
805
842
  // then run all component and data loaders in parallel
806
843
  // For each component type, potentially load it asynchronously
@@ -816,11 +853,12 @@
816
853
  if (this.route.options.onLoad) {
817
854
  return this.route.options.onLoad({
818
855
  params: this.params,
819
- search: this.state.search,
856
+ routeSearch,
857
+ search,
820
858
  signal: this.abortController.signal,
821
859
  preload: !!opts?.preload,
822
- routeContext: this.routeContext,
823
- context: this.context
860
+ routeContext: routeContext,
861
+ context: context
824
862
  });
825
863
  }
826
864
  return;
@@ -848,6 +886,7 @@
848
886
  });
849
887
  return this.__loadPromise;
850
888
  };
889
+ #latestId = '';
851
890
  }
852
891
 
853
892
  const defaultParseSearch = parseSearchWith(JSON.parse);
@@ -1053,7 +1092,7 @@
1053
1092
 
1054
1093
  // Load the matches
1055
1094
  try {
1056
- await this.loadMatches(matches
1095
+ await this.loadMatches(matches, this.state.pendingLocation
1057
1096
  // opts
1058
1097
  );
1059
1098
  } catch (err) {
@@ -1105,6 +1144,7 @@
1105
1144
  search: d.state.search
1106
1145
  });
1107
1146
  });
1147
+ const prevLocation = this.state.currentLocation;
1108
1148
  this.store.setState(s => ({
1109
1149
  ...s,
1110
1150
  status: 'idle',
@@ -1113,7 +1153,12 @@
1113
1153
  pendingLocation: undefined,
1114
1154
  pendingMatches: undefined
1115
1155
  }));
1116
- this.options.onRouteChange?.();
1156
+ matches.forEach(match => {
1157
+ match.__commit();
1158
+ });
1159
+ if (prevLocation.href !== this.state.currentLocation.href) {
1160
+ this.options.onRouteChange?.();
1161
+ }
1117
1162
  this.resolveNavigation();
1118
1163
  };
1119
1164
  getRoute = id => {
@@ -1126,7 +1171,7 @@
1126
1171
  const matches = this.matchRoutes(next.pathname, {
1127
1172
  strictParseParams: true
1128
1173
  });
1129
- await this.loadMatches(matches);
1174
+ await this.loadMatches(matches, next);
1130
1175
  return matches;
1131
1176
  };
1132
1177
  preloadRoute = async (navigateOpts = this.state.latestLocation) => {
@@ -1134,7 +1179,7 @@
1134
1179
  const matches = this.matchRoutes(next.pathname, {
1135
1180
  strictParseParams: true
1136
1181
  });
1137
- await this.loadMatches(matches, {
1182
+ await this.loadMatches(matches, next, {
1138
1183
  preload: true
1139
1184
  });
1140
1185
  return matches;
@@ -1206,9 +1251,7 @@
1206
1251
  findInRouteTree([this.routeTree]);
1207
1252
  return matches;
1208
1253
  };
1209
- loadMatches = async (resolvedMatches, opts) => {
1210
- initMatches(resolvedMatches);
1211
-
1254
+ loadMatches = async (resolvedMatches, location, opts) => {
1212
1255
  // Check each match middleware to see if the route can be accessed
1213
1256
  await Promise.all(resolvedMatches.map(async match => {
1214
1257
  try {
@@ -1224,22 +1267,15 @@
1224
1267
  }
1225
1268
  }));
1226
1269
  const matchPromises = resolvedMatches.map(async (match, index) => {
1227
- const prevMatch = resolvedMatches[1];
1228
- match.state.search;
1229
-
1230
- // if (opts?.filter && !opts.filter(match)) {
1231
- // return
1232
- // }
1233
-
1234
- match.load({
1235
- preload: opts?.preload
1270
+ const parentMatch = resolvedMatches[index - 1];
1271
+ match.__load({
1272
+ preload: opts?.preload,
1273
+ location,
1274
+ parentMatch
1236
1275
  });
1237
- if (match.state.status !== 'success' && match.__loadPromise) {
1238
- // Wait for the first sign of activity from the match
1239
- await match.__loadPromise;
1240
- }
1241
- if (prevMatch) {
1242
- await prevMatch.__loadPromise;
1276
+ await match.__loadPromise;
1277
+ if (parentMatch) {
1278
+ await parentMatch.__loadPromise;
1243
1279
  }
1244
1280
  });
1245
1281
  await Promise.all(matchPromises);
@@ -1302,7 +1338,6 @@
1302
1338
  return false;
1303
1339
  }
1304
1340
  if (opts?.includeSearch ?? true) {
1305
- console.log(baseLocation.search, next.search, partialDeepEqual(baseLocation.search, next.search));
1306
1341
  return partialDeepEqual(baseLocation.search, next.search) ? match : false;
1307
1342
  }
1308
1343
  return match;
@@ -1317,8 +1352,6 @@
1317
1352
  replace,
1318
1353
  activeOptions,
1319
1354
  preload,
1320
- preloadMaxAge: userPreloadMaxAge,
1321
- preloadGcMaxAge: userPreloadGcMaxAge,
1322
1355
  preloadDelay: userPreloadDelay,
1323
1356
  disabled
1324
1357
  }) => {
@@ -1438,7 +1471,6 @@
1438
1471
  ...dehydratedMatch.state
1439
1472
  }));
1440
1473
  });
1441
- initMatches(currentMatches);
1442
1474
  return {
1443
1475
  ...s,
1444
1476
  ...dehydratedRouter.state,
@@ -1577,14 +1609,6 @@
1577
1609
  function isCtrlEvent(e) {
1578
1610
  return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
1579
1611
  }
1580
- function initMatches(matches) {
1581
- matches.forEach((match, index) => {
1582
- const parentMatch = matches[index - 1];
1583
- match.__init({
1584
- parentMatch
1585
- });
1586
- });
1587
- }
1588
1612
 
1589
1613
  /**
1590
1614
  * react-store
@@ -1677,7 +1701,6 @@
1677
1701
  to = '.',
1678
1702
  preload,
1679
1703
  preloadDelay,
1680
- preloadMaxAge,
1681
1704
  replace,
1682
1705
  // element props
1683
1706
  style,