@tanstack/react-router 0.0.1-beta.236 → 0.0.1-beta.237
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/Matches.js +3 -5
- package/build/cjs/Matches.js.map +1 -1
- package/build/cjs/RouterProvider.js +34 -19
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/esm/index.js +37 -24
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/umd/index.development.js +37 -24
- 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 +2 -2
- package/src/Matches.tsx +3 -3
- package/src/RouterProvider.tsx +45 -20
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.237",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@tanstack/store": "^0.1.3",
|
|
45
45
|
"tiny-invariant": "^1.3.1",
|
|
46
46
|
"tiny-warning": "^1.0.3",
|
|
47
|
-
"@tanstack/history": "0.0.1-beta.
|
|
47
|
+
"@tanstack/history": "0.0.1-beta.237"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/Matches.tsx
CHANGED
|
@@ -47,13 +47,13 @@ export interface RouteMatch<
|
|
|
47
47
|
export type AnyRouteMatch = RouteMatch<any>
|
|
48
48
|
|
|
49
49
|
export function Matches() {
|
|
50
|
-
const
|
|
50
|
+
const router = useRouter()
|
|
51
51
|
const routerState = useRouterState()
|
|
52
52
|
const matches = routerState.pendingMatches?.some((d) => d.showPending)
|
|
53
53
|
? routerState.pendingMatches
|
|
54
54
|
: routerState.matches
|
|
55
|
-
const locationKey =
|
|
56
|
-
const route = routesById[rootRouteId]!
|
|
55
|
+
const locationKey = router.latestLocation.state.key
|
|
56
|
+
const route = router.routesById[rootRouteId]!
|
|
57
57
|
|
|
58
58
|
const errorComponent = React.useCallback(
|
|
59
59
|
(props: any) => {
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
RouterOptions,
|
|
20
20
|
RouterState,
|
|
21
21
|
} from './router'
|
|
22
|
-
import { NoInfer, PickAsRequired, useLayoutEffect } from './utils'
|
|
22
|
+
import { NoInfer, PickAsRequired, pick, useLayoutEffect } from './utils'
|
|
23
23
|
import { MatchRouteOptions } from './Matches'
|
|
24
24
|
import { RouteMatch } from './Matches'
|
|
25
25
|
|
|
@@ -87,7 +87,11 @@ export function RouterProvider<
|
|
|
87
87
|
},
|
|
88
88
|
} as any)
|
|
89
89
|
|
|
90
|
-
const inner =
|
|
90
|
+
const inner = (
|
|
91
|
+
<routerContext.Provider value={router}>
|
|
92
|
+
<RouterProviderInner<TRouteTree, TDehydrated> router={router} />
|
|
93
|
+
</routerContext.Provider>
|
|
94
|
+
)
|
|
91
95
|
|
|
92
96
|
if (router.options.Wrap) {
|
|
93
97
|
return <router.options.Wrap>{inner}</router.options.Wrap>
|
|
@@ -100,6 +104,21 @@ function RouterProviderInner<
|
|
|
100
104
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
101
105
|
TDehydrated extends Record<string, any> = Record<string, any>,
|
|
102
106
|
>({ router }: RouterProps<TRouteTree, TDehydrated>) {
|
|
107
|
+
return (
|
|
108
|
+
<>
|
|
109
|
+
<Matches />
|
|
110
|
+
<Transitioner />
|
|
111
|
+
</>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function Transitioner() {
|
|
116
|
+
const router = useRouter()
|
|
117
|
+
const routerState = useRouterState({
|
|
118
|
+
select: (s) =>
|
|
119
|
+
pick(s, ['isLoading', 'location', 'resolvedLocation', 'isTransitioning']),
|
|
120
|
+
})
|
|
121
|
+
|
|
103
122
|
const [isTransitioning, startReactTransition] = React.useTransition()
|
|
104
123
|
|
|
105
124
|
router.startReactTransition = startReactTransition
|
|
@@ -114,19 +133,27 @@ function RouterProviderInner<
|
|
|
114
133
|
}, [isTransitioning])
|
|
115
134
|
|
|
116
135
|
const tryLoad = () => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
136
|
+
const apply = (cb: () => void) => {
|
|
137
|
+
if (!routerState.isTransitioning) {
|
|
138
|
+
startReactTransition(() => cb())
|
|
139
|
+
} else {
|
|
140
|
+
cb()
|
|
141
|
+
}
|
|
122
142
|
}
|
|
123
|
-
|
|
143
|
+
|
|
144
|
+
apply(() => {
|
|
145
|
+
try {
|
|
146
|
+
router.load()
|
|
147
|
+
} catch (err) {
|
|
148
|
+
console.error(err)
|
|
149
|
+
}
|
|
150
|
+
})
|
|
124
151
|
}
|
|
125
152
|
|
|
126
153
|
useLayoutEffect(() => {
|
|
127
154
|
const unsub = router.history.subscribe(() => {
|
|
128
155
|
router.latestLocation = router.parseLocation(router.latestLocation)
|
|
129
|
-
if (
|
|
156
|
+
if (routerState.location !== router.latestLocation) {
|
|
130
157
|
tryLoad()
|
|
131
158
|
}
|
|
132
159
|
})
|
|
@@ -138,7 +165,7 @@ function RouterProviderInner<
|
|
|
138
165
|
state: true,
|
|
139
166
|
})
|
|
140
167
|
|
|
141
|
-
if (
|
|
168
|
+
if (routerState.location.href !== nextLocation.href) {
|
|
142
169
|
router.commitLocation({ ...nextLocation, replace: true })
|
|
143
170
|
}
|
|
144
171
|
|
|
@@ -150,14 +177,16 @@ function RouterProviderInner<
|
|
|
150
177
|
useLayoutEffect(() => {
|
|
151
178
|
if (
|
|
152
179
|
!isTransitioning &&
|
|
153
|
-
|
|
180
|
+
!routerState.isLoading &&
|
|
181
|
+
routerState.resolvedLocation !== routerState.location
|
|
154
182
|
) {
|
|
183
|
+
console.log('onResolved', routerState.location)
|
|
155
184
|
router.emit({
|
|
156
185
|
type: 'onResolved',
|
|
157
|
-
fromLocation:
|
|
158
|
-
toLocation:
|
|
186
|
+
fromLocation: routerState.resolvedLocation,
|
|
187
|
+
toLocation: routerState.location,
|
|
159
188
|
pathChanged:
|
|
160
|
-
|
|
189
|
+
routerState.location!.href !== routerState.resolvedLocation?.href,
|
|
161
190
|
})
|
|
162
191
|
router.pendingMatches = []
|
|
163
192
|
|
|
@@ -167,7 +196,7 @@ function RouterProviderInner<
|
|
|
167
196
|
resolvedLocation: s.location,
|
|
168
197
|
}))
|
|
169
198
|
}
|
|
170
|
-
}, [isTransitioning])
|
|
199
|
+
}, [isTransitioning, routerState.isLoading])
|
|
171
200
|
|
|
172
201
|
useLayoutEffect(() => {
|
|
173
202
|
if (!window.__TSR_DEHYDRATED__) {
|
|
@@ -175,11 +204,7 @@ function RouterProviderInner<
|
|
|
175
204
|
}
|
|
176
205
|
}, [])
|
|
177
206
|
|
|
178
|
-
return
|
|
179
|
-
<routerContext.Provider value={router}>
|
|
180
|
-
<Matches />
|
|
181
|
-
</routerContext.Provider>
|
|
182
|
-
)
|
|
207
|
+
return null
|
|
183
208
|
}
|
|
184
209
|
|
|
185
210
|
export function getRouteMatch<TRouteTree extends AnyRoute>(
|