@tanstack/router-core 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.
- package/build/cjs/history.js +3 -9
- 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 +17 -19
- 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 +2 -1
- package/build/umd/index.development.js +17 -19
- 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 +14 -9
- package/src/routeMatch.ts +2 -2
- package/src/router.ts +22 -11
package/package.json
CHANGED
package/src/history.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// This implementation attempts to be more lightweight by
|
|
3
3
|
// making assumptions about the way TanStack Router works
|
|
4
4
|
|
|
5
|
+
import { match } from 'assert'
|
|
6
|
+
|
|
5
7
|
export interface RouterHistory {
|
|
6
8
|
location: RouterLocation
|
|
7
9
|
listen: (cb: () => void) => () => void
|
|
@@ -146,13 +148,8 @@ export function createMemoryHistory(
|
|
|
146
148
|
|
|
147
149
|
return createHistory({
|
|
148
150
|
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
|
-
}
|
|
151
|
+
listener: () => {
|
|
152
|
+
return () => {}
|
|
156
153
|
},
|
|
157
154
|
pushState: (path, state) => {
|
|
158
155
|
currentState = {
|
|
@@ -182,11 +179,19 @@ export function createMemoryHistory(
|
|
|
182
179
|
function parseLocation(href: string, state: any): RouterLocation {
|
|
183
180
|
let hashIndex = href.indexOf('#')
|
|
184
181
|
let searchIndex = href.indexOf('?')
|
|
185
|
-
const pathEnd = Math.min(hashIndex, searchIndex)
|
|
186
182
|
|
|
187
183
|
return {
|
|
188
184
|
href,
|
|
189
|
-
pathname:
|
|
185
|
+
pathname: href.substring(
|
|
186
|
+
0,
|
|
187
|
+
hashIndex > 0
|
|
188
|
+
? searchIndex > 0
|
|
189
|
+
? Math.min(hashIndex, searchIndex)
|
|
190
|
+
: hashIndex
|
|
191
|
+
: searchIndex > 0
|
|
192
|
+
? searchIndex
|
|
193
|
+
: href.length,
|
|
194
|
+
),
|
|
190
195
|
hash: hashIndex > -1 ? href.substring(hashIndex, searchIndex) : '',
|
|
191
196
|
search: searchIndex > -1 ? href.substring(searchIndex) : '',
|
|
192
197
|
state,
|
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
|
|
@@ -817,7 +820,12 @@ export class Router<
|
|
|
817
820
|
}
|
|
818
821
|
}
|
|
819
822
|
|
|
820
|
-
invalidateRoute = async
|
|
823
|
+
invalidateRoute = async <
|
|
824
|
+
TFrom extends ValidFromPath<TAllRouteInfo> = '/',
|
|
825
|
+
TTo extends string = '.',
|
|
826
|
+
>(
|
|
827
|
+
opts: ToOptions<TAllRouteInfo, TFrom, TTo>,
|
|
828
|
+
) => {
|
|
821
829
|
const next = this.buildNext(opts)
|
|
822
830
|
const unloadedMatchIds = this.matchRoutes(next.pathname).map((d) => d.id)
|
|
823
831
|
|
|
@@ -1007,7 +1015,7 @@ export class Router<
|
|
|
1007
1015
|
) {
|
|
1008
1016
|
e.preventDefault()
|
|
1009
1017
|
if (pathIsEqual && !search && !hash) {
|
|
1010
|
-
this.invalidateRoute(nextOpts)
|
|
1018
|
+
this.invalidateRoute(nextOpts as any)
|
|
1011
1019
|
}
|
|
1012
1020
|
|
|
1013
1021
|
// All is well? Navigate!
|
|
@@ -1114,7 +1122,10 @@ export class Router<
|
|
|
1114
1122
|
dehydratedMatch && dehydratedMatch.id === match.id,
|
|
1115
1123
|
'Oh no! There was a hydration mismatch when attempting to rethis.store the state of the router! 😬',
|
|
1116
1124
|
)
|
|
1117
|
-
|
|
1125
|
+
match.store.setState((s) => {
|
|
1126
|
+
Object.assign(s, dehydratedMatch.state)
|
|
1127
|
+
})
|
|
1128
|
+
match.setLoaderData(dehydratedMatch.state.routeLoaderData)
|
|
1118
1129
|
})
|
|
1119
1130
|
|
|
1120
1131
|
currentMatches.forEach((match) => match.__validate())
|