@tanstack/router-core 0.0.1-beta.51 → 0.0.1-beta.52
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.
- package/build/cjs/history.js +2 -7
- package/build/cjs/history.js.map +1 -1
- package/build/cjs/routeMatch.js +2 -2
- package/build/cjs/routeMatch.js.map +1 -1
- package/build/cjs/router.js +12 -8
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +16 -17
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +151 -151
- package/build/types/index.d.ts +1 -0
- package/build/umd/index.development.js +16 -17
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/history.ts +2 -7
- package/src/routeMatch.ts +2 -2
- package/src/router.ts +15 -9
package/package.json
CHANGED
package/src/history.ts
CHANGED
|
@@ -146,13 +146,8 @@ export function createMemoryHistory(
|
|
|
146
146
|
|
|
147
147
|
return createHistory({
|
|
148
148
|
getLocation,
|
|
149
|
-
listener: (
|
|
150
|
-
|
|
151
|
-
// We might need to handle the hashchange event in the future
|
|
152
|
-
// window.addEventListener(hashChangeEvent, onUpdate)
|
|
153
|
-
return () => {
|
|
154
|
-
window.removeEventListener(popStateEvent, onUpdate)
|
|
155
|
-
}
|
|
149
|
+
listener: () => {
|
|
150
|
+
return () => {}
|
|
156
151
|
},
|
|
157
152
|
pushState: (path, state) => {
|
|
158
153
|
currentState = {
|
package/src/routeMatch.ts
CHANGED
|
@@ -95,7 +95,7 @@ export class RouteMatch<
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
setLoaderData = (loaderData: TRouteInfo['routeLoaderData']) => {
|
|
99
99
|
batch(() => {
|
|
100
100
|
this.store.setState((s) => {
|
|
101
101
|
s.routeLoaderData = loaderData
|
|
@@ -197,7 +197,7 @@ export class RouteMatch<
|
|
|
197
197
|
if (this.route.options.loader) {
|
|
198
198
|
const data = await this.router.loadMatchData(this)
|
|
199
199
|
if ((latestPromise = checkLatest())) return latestPromise
|
|
200
|
-
this
|
|
200
|
+
this.setLoaderData(data)
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
this.store.setState((s) => {
|
package/src/router.ts
CHANGED
|
@@ -295,6 +295,7 @@ export class Router<
|
|
|
295
295
|
'stringifySearch' | 'parseSearch' | 'context'
|
|
296
296
|
>
|
|
297
297
|
history!: RouterHistory
|
|
298
|
+
#unsubHistory?: () => void
|
|
298
299
|
basepath: string
|
|
299
300
|
// __location: Location<TAllRouteInfo['fullSearchSchema']>
|
|
300
301
|
routeTree!: Route<TAllRouteInfo, RouteInfo>
|
|
@@ -341,10 +342,6 @@ export class Router<
|
|
|
341
342
|
this.load()
|
|
342
343
|
}
|
|
343
344
|
|
|
344
|
-
const unsubHistory = this.history.listen(() => {
|
|
345
|
-
this.load(this.#parseLocation(this.store.state.latestLocation))
|
|
346
|
-
})
|
|
347
|
-
|
|
348
345
|
const visibilityChangeEvent = 'visibilitychange'
|
|
349
346
|
const focusEvent = 'focus'
|
|
350
347
|
|
|
@@ -358,7 +355,6 @@ export class Router<
|
|
|
358
355
|
}
|
|
359
356
|
|
|
360
357
|
return () => {
|
|
361
|
-
unsubHistory()
|
|
362
358
|
if (window.removeEventListener) {
|
|
363
359
|
// Be sure to unsubscribe if a new handler is set
|
|
364
360
|
|
|
@@ -384,15 +380,22 @@ export class Router<
|
|
|
384
380
|
!this.history ||
|
|
385
381
|
(this.options.history && this.options.history !== this.history)
|
|
386
382
|
) {
|
|
383
|
+
if (this.#unsubHistory) {
|
|
384
|
+
this.#unsubHistory()
|
|
385
|
+
}
|
|
386
|
+
|
|
387
387
|
this.history =
|
|
388
|
-
this.options
|
|
389
|
-
|
|
390
|
-
: createBrowserHistory()!
|
|
388
|
+
this.options.history ??
|
|
389
|
+
(isServer ? createMemoryHistory() : createBrowserHistory()!)
|
|
391
390
|
|
|
392
391
|
this.store.setState((s) => {
|
|
393
392
|
s.latestLocation = this.#parseLocation()
|
|
394
393
|
s.currentLocation = s.latestLocation
|
|
395
394
|
})
|
|
395
|
+
|
|
396
|
+
this.#unsubHistory = this.history.listen(() => {
|
|
397
|
+
this.load(this.#parseLocation(this.store.state.latestLocation))
|
|
398
|
+
})
|
|
396
399
|
}
|
|
397
400
|
|
|
398
401
|
const { basepath, routeConfig } = this.options
|
|
@@ -1114,7 +1117,10 @@ export class Router<
|
|
|
1114
1117
|
dehydratedMatch && dehydratedMatch.id === match.id,
|
|
1115
1118
|
'Oh no! There was a hydration mismatch when attempting to rethis.store the state of the router! 😬',
|
|
1116
1119
|
)
|
|
1117
|
-
|
|
1120
|
+
match.store.setState((s) => {
|
|
1121
|
+
Object.assign(s, dehydratedMatch.state)
|
|
1122
|
+
})
|
|
1123
|
+
match.setLoaderData(dehydratedMatch.state.routeLoaderData)
|
|
1118
1124
|
})
|
|
1119
1125
|
|
|
1120
1126
|
currentMatches.forEach((match) => match.__validate())
|