@tanstack/react-router 0.0.1-beta.51 → 0.0.1-beta.53

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": "8d97-81",
10
+ "uid": "a738-81",
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": "8d97-83"
18
+ "uid": "a738-83"
19
19
  },
20
20
  {
21
21
  "name": "immer@9.0.16/node_modules/immer/dist/immer.esm.mjs",
22
- "uid": "8d97-85"
22
+ "uid": "a738-85"
23
23
  }
24
24
  ]
25
25
  },
@@ -28,17 +28,17 @@
28
28
  "children": [
29
29
  {
30
30
  "name": "router-core/build/esm/index.js",
31
- "uid": "8d97-87"
31
+ "uid": "a738-87"
32
32
  },
33
33
  {
34
34
  "name": "react-router/src",
35
35
  "children": [
36
36
  {
37
- "uid": "8d97-89",
37
+ "uid": "a738-89",
38
38
  "name": "useStore.ts"
39
39
  },
40
40
  {
41
- "uid": "8d97-91",
41
+ "uid": "a738-91",
42
42
  "name": "index.tsx"
43
43
  }
44
44
  ]
@@ -51,155 +51,155 @@
51
51
  "isRoot": true
52
52
  },
53
53
  "nodeParts": {
54
- "8d97-81": {
54
+ "a738-81": {
55
55
  "renderedLength": 429,
56
56
  "gzipLength": 238,
57
57
  "brotliLength": 0,
58
- "mainUid": "8d97-80"
58
+ "mainUid": "a738-80"
59
59
  },
60
- "8d97-83": {
60
+ "a738-83": {
61
61
  "renderedLength": 181,
62
62
  "gzipLength": 129,
63
63
  "brotliLength": 0,
64
- "mainUid": "8d97-82"
64
+ "mainUid": "a738-82"
65
65
  },
66
- "8d97-85": {
66
+ "a738-85": {
67
67
  "renderedLength": 8203,
68
68
  "gzipLength": 3238,
69
69
  "brotliLength": 0,
70
- "mainUid": "8d97-84"
70
+ "mainUid": "a738-84"
71
71
  },
72
- "8d97-87": {
73
- "renderedLength": 56666,
74
- "gzipLength": 13446,
72
+ "a738-87": {
73
+ "renderedLength": 56569,
74
+ "gzipLength": 13422,
75
75
  "brotliLength": 0,
76
- "mainUid": "8d97-86"
76
+ "mainUid": "a738-86"
77
77
  },
78
- "8d97-89": {
78
+ "a738-89": {
79
79
  "renderedLength": 1347,
80
80
  "gzipLength": 484,
81
81
  "brotliLength": 0,
82
- "mainUid": "8d97-88"
82
+ "mainUid": "a738-88"
83
83
  },
84
- "8d97-91": {
84
+ "a738-91": {
85
85
  "renderedLength": 12608,
86
86
  "gzipLength": 3327,
87
87
  "brotliLength": 0,
88
- "mainUid": "8d97-90"
88
+ "mainUid": "a738-90"
89
89
  }
90
90
  },
91
91
  "nodeMetas": {
92
- "8d97-80": {
92
+ "a738-80": {
93
93
  "id": "\u0000rollupPluginBabelHelpers.js",
94
94
  "moduleParts": {
95
- "index.production.js": "8d97-81"
95
+ "index.production.js": "a738-81"
96
96
  },
97
97
  "imported": [],
98
98
  "importedBy": [
99
99
  {
100
- "uid": "8d97-90"
100
+ "uid": "a738-90"
101
101
  }
102
102
  ]
103
103
  },
104
- "8d97-82": {
104
+ "a738-82": {
105
105
  "id": "/node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
106
106
  "moduleParts": {
107
- "index.production.js": "8d97-83"
107
+ "index.production.js": "a738-83"
108
108
  },
109
109
  "imported": [],
110
110
  "importedBy": [
111
111
  {
112
- "uid": "8d97-86"
112
+ "uid": "a738-86"
113
113
  }
114
114
  ]
115
115
  },
116
- "8d97-84": {
116
+ "a738-84": {
117
117
  "id": "/node_modules/.pnpm/immer@9.0.16/node_modules/immer/dist/immer.esm.mjs",
118
118
  "moduleParts": {
119
- "index.production.js": "8d97-85"
119
+ "index.production.js": "a738-85"
120
120
  },
121
121
  "imported": [],
122
122
  "importedBy": [
123
123
  {
124
- "uid": "8d97-86"
124
+ "uid": "a738-86"
125
125
  }
126
126
  ]
127
127
  },
128
- "8d97-86": {
128
+ "a738-86": {
129
129
  "id": "/packages/router-core/build/esm/index.js",
130
130
  "moduleParts": {
131
- "index.production.js": "8d97-87"
131
+ "index.production.js": "a738-87"
132
132
  },
133
133
  "imported": [
134
134
  {
135
- "uid": "8d97-82"
135
+ "uid": "a738-82"
136
136
  },
137
137
  {
138
- "uid": "8d97-84"
138
+ "uid": "a738-84"
139
139
  }
140
140
  ],
141
141
  "importedBy": [
142
142
  {
143
- "uid": "8d97-90"
143
+ "uid": "a738-90"
144
144
  }
145
145
  ]
146
146
  },
147
- "8d97-88": {
147
+ "a738-88": {
148
148
  "id": "/packages/react-router/src/useStore.ts",
149
149
  "moduleParts": {
150
- "index.production.js": "8d97-89"
150
+ "index.production.js": "a738-89"
151
151
  },
152
152
  "imported": [
153
153
  {
154
- "uid": "8d97-93"
154
+ "uid": "a738-93"
155
155
  }
156
156
  ],
157
157
  "importedBy": [
158
158
  {
159
- "uid": "8d97-90"
159
+ "uid": "a738-90"
160
160
  }
161
161
  ]
162
162
  },
163
- "8d97-90": {
163
+ "a738-90": {
164
164
  "id": "/packages/react-router/src/index.tsx",
165
165
  "moduleParts": {
166
- "index.production.js": "8d97-91"
166
+ "index.production.js": "a738-91"
167
167
  },
168
168
  "imported": [
169
169
  {
170
- "uid": "8d97-80"
170
+ "uid": "a738-80"
171
171
  },
172
172
  {
173
- "uid": "8d97-92"
173
+ "uid": "a738-92"
174
174
  },
175
175
  {
176
- "uid": "8d97-86"
176
+ "uid": "a738-86"
177
177
  },
178
178
  {
179
- "uid": "8d97-88"
179
+ "uid": "a738-88"
180
180
  }
181
181
  ],
182
182
  "importedBy": [],
183
183
  "isEntry": true
184
184
  },
185
- "8d97-92": {
185
+ "a738-92": {
186
186
  "id": "react",
187
187
  "moduleParts": {},
188
188
  "imported": [],
189
189
  "importedBy": [
190
190
  {
191
- "uid": "8d97-90"
191
+ "uid": "a738-90"
192
192
  }
193
193
  ],
194
194
  "isExternal": true
195
195
  },
196
- "8d97-93": {
196
+ "a738-93": {
197
197
  "id": "use-sync-external-store/shim/with-selector",
198
198
  "moduleParts": {},
199
199
  "imported": [],
200
200
  "importedBy": [
201
201
  {
202
- "uid": "8d97-88"
202
+ "uid": "a738-88"
203
203
  }
204
204
  ],
205
205
  "isExternal": true
@@ -99,9 +99,9 @@ declare function useParams<TFrom extends keyof RegisteredAllRouteInfo['routeInfo
99
99
  from: TFrom;
100
100
  track?: (search: TDefaultSelected) => TSelected;
101
101
  }): TSelected;
102
- declare function useNavigate<TDefaultFrom extends keyof RegisteredAllRouteInfo['routeInfoById'] = '/'>(defaultOpts: {
102
+ declare function useNavigate<TDefaultFrom extends keyof RegisteredAllRouteInfo['routeInfoById'] = '/'>(defaultOpts?: {
103
103
  from?: TDefaultFrom;
104
- }): <TFrom extends string = TDefaultFrom, TTo extends string = ".">(opts: MakeLinkOptions<TFrom, TTo>) => Promise<void>;
104
+ }): <TFrom extends string = TDefaultFrom, TTo extends string = ".">(opts?: MakeLinkOptions<TFrom, TTo> | undefined) => Promise<void>;
105
105
  declare function useMatchRoute(): <TFrom extends ValidFromPath<AnyAllRouteInfo> = "/", TTo extends string = ".">(opts: MakeUseMatchRouteOptions<TFrom, TTo>) => false;
106
106
  declare function MatchRoute<TFrom extends ValidFromPath<RegisteredAllRouteInfo> = '/', TTo extends string = '.'>(props: MakeMatchRouteOptions<TFrom, TTo>): any;
107
107
  declare function Outlet(): JSX.Element | null;
@@ -167,13 +167,8 @@
167
167
  const getLocation = () => parseLocation(entries[index], currentState);
168
168
  return createHistory({
169
169
  getLocation,
170
- listener: onUpdate => {
171
- window.addEventListener(popStateEvent, onUpdate);
172
- // We might need to handle the hashchange event in the future
173
- // window.addEventListener(hashChangeEvent, onUpdate)
174
- return () => {
175
- window.removeEventListener(popStateEvent, onUpdate);
176
- };
170
+ listener: () => {
171
+ return () => {};
177
172
  },
178
173
  pushState: (path, state) => {
179
174
  currentState = {
@@ -202,10 +197,9 @@
202
197
  function parseLocation(href, state) {
203
198
  let hashIndex = href.indexOf('#');
204
199
  let searchIndex = href.indexOf('?');
205
- const pathEnd = Math.min(hashIndex, searchIndex);
206
200
  return {
207
201
  href,
208
- pathname: pathEnd > -1 ? href.substring(0, pathEnd) : href,
202
+ pathname: href.substring(0, hashIndex > 0 ? searchIndex > 0 ? Math.min(hashIndex, searchIndex) : hashIndex : searchIndex > 0 ? searchIndex : href.length),
209
203
  hash: hashIndex > -1 ? href.substring(hashIndex, searchIndex) : '',
210
204
  search: searchIndex > -1 ? href.substring(searchIndex) : '',
211
205
  state
@@ -742,7 +736,7 @@
742
736
  this.store.setState(s => s.status = 'success');
743
737
  }
744
738
  }
745
- #setLoaderData = loaderData => {
739
+ setLoaderData = loaderData => {
746
740
  batch(() => {
747
741
  this.store.setState(s => {
748
742
  s.routeLoaderData = loaderData;
@@ -817,7 +811,7 @@
817
811
  if (this.route.options.loader) {
818
812
  const data = await this.router.loadMatchData(this);
819
813
  if (latestPromise = checkLatest()) return latestPromise;
820
- this.#setLoaderData(data);
814
+ this.setLoaderData(data);
821
815
  }
822
816
  this.store.setState(s => {
823
817
  s.error = undefined;
@@ -1002,8 +996,7 @@
1002
996
  throw new Error('Failed to fetch match data');
1003
997
  };
1004
998
  class Router {
1005
- // __location: Location<TAllRouteInfo['fullSearchSchema']>
1006
-
999
+ #unsubHistory;
1007
1000
  startedLoadingAt = Date.now();
1008
1001
  resolveNavigation = () => {};
1009
1002
  constructor(options) {
@@ -1035,9 +1028,6 @@
1035
1028
  if (!this.store.state.currentMatches.length) {
1036
1029
  this.load();
1037
1030
  }
1038
- const unsubHistory = this.history.listen(() => {
1039
- this.load(this.#parseLocation(this.store.state.latestLocation));
1040
- });
1041
1031
  const visibilityChangeEvent = 'visibilitychange';
1042
1032
  const focusEvent = 'focus';
1043
1033
 
@@ -1050,7 +1040,6 @@
1050
1040
  window.addEventListener(focusEvent, this.#onFocus, false);
1051
1041
  }
1052
1042
  return () => {
1053
- unsubHistory();
1054
1043
  if (window.removeEventListener) {
1055
1044
  // Be sure to unsubscribe if a new handler is set
1056
1045
 
@@ -1064,11 +1053,17 @@
1064
1053
  update = opts => {
1065
1054
  Object.assign(this.options, opts);
1066
1055
  if (!this.history || this.options.history && this.options.history !== this.history) {
1067
- this.history = this.options?.history ?? isServer ? createMemoryHistory() : createBrowserHistory();
1056
+ if (this.#unsubHistory) {
1057
+ this.#unsubHistory();
1058
+ }
1059
+ this.history = this.options.history ?? (isServer ? createMemoryHistory() : createBrowserHistory());
1068
1060
  this.store.setState(s => {
1069
1061
  s.latestLocation = this.#parseLocation();
1070
1062
  s.currentLocation = s.latestLocation;
1071
1063
  });
1064
+ this.#unsubHistory = this.history.listen(() => {
1065
+ this.load(this.#parseLocation(this.store.state.latestLocation));
1066
+ });
1072
1067
  }
1073
1068
  const {
1074
1069
  basepath,
@@ -1582,7 +1577,10 @@
1582
1577
  currentMatches.forEach((match, index) => {
1583
1578
  const dehydratedMatch = dehydratedRouter.state.currentMatches[index];
1584
1579
  invariant(dehydratedMatch && dehydratedMatch.id === match.id, 'Oh no! There was a hydration mismatch when attempting to rethis.store the state of the router! 😬');
1585
- Object.assign(match, dehydratedMatch);
1580
+ match.store.setState(s => {
1581
+ Object.assign(s, dehydratedMatch.state);
1582
+ });
1583
+ match.setLoaderData(dehydratedMatch.state.routeLoaderData);
1586
1584
  });
1587
1585
  currentMatches.forEach(match => match.__validate());
1588
1586
  Object.assign(s, {