@tanstack/react-router 1.45.2 → 1.45.4
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/dist/cjs/CatchBoundary.cjs +1 -1
- package/dist/cjs/CatchBoundary.cjs.map +1 -1
- package/dist/cjs/CatchBoundary.d.cts +1 -1
- package/dist/cjs/Match.cjs +24 -34
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +4 -1
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +5 -2
- package/dist/cjs/RouterProvider.cjs +0 -8
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/RouterProvider.d.cts +1 -4
- package/dist/cjs/Transitioner.cjs +5 -1
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/index.cjs +0 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +1 -0
- package/dist/cjs/router.cjs +464 -407
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +22 -10
- package/dist/esm/CatchBoundary.d.ts +1 -1
- package/dist/esm/CatchBoundary.js +1 -1
- package/dist/esm/CatchBoundary.js.map +1 -1
- package/dist/esm/Match.js +24 -34
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.d.ts +5 -2
- package/dist/esm/Matches.js +4 -1
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +1 -4
- package/dist/esm/RouterProvider.js +1 -9
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/Transitioner.js +5 -1
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/route.d.ts +1 -0
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +22 -10
- package/dist/esm/router.js +466 -409
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -2
- package/src/CatchBoundary.tsx +7 -3
- package/src/Match.tsx +45 -36
- package/src/Matches.tsx +10 -3
- package/src/RouterProvider.tsx +0 -11
- package/src/Transitioner.tsx +5 -1
- package/src/index.tsx +0 -1
- package/src/route.ts +1 -0
- package/src/router.ts +647 -565
package/src/CatchBoundary.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import type { ErrorRouteComponent } from './route'
|
|
|
3
3
|
import type { ErrorInfo } from 'react'
|
|
4
4
|
|
|
5
5
|
export function CatchBoundary(props: {
|
|
6
|
-
getResetKey: () => string
|
|
6
|
+
getResetKey: () => number | string
|
|
7
7
|
children: React.ReactNode
|
|
8
8
|
errorComponent?: ErrorRouteComponent
|
|
9
9
|
onCatch?: (error: Error, errorInfo: ErrorInfo) => void
|
|
@@ -29,7 +29,7 @@ export function CatchBoundary(props: {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
class CatchBoundaryImpl extends React.Component<{
|
|
32
|
-
getResetKey: () => string
|
|
32
|
+
getResetKey: () => number | string
|
|
33
33
|
children: (props: {
|
|
34
34
|
error: Error | null
|
|
35
35
|
reset: () => void
|
|
@@ -64,8 +64,12 @@ class CatchBoundaryImpl extends React.Component<{
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
render() {
|
|
67
|
+
// If the resetKey has changed, don't render the error
|
|
67
68
|
return this.props.children({
|
|
68
|
-
error:
|
|
69
|
+
error:
|
|
70
|
+
this.state.resetKey !== this.props.getResetKey()
|
|
71
|
+
? null
|
|
72
|
+
: this.state.error,
|
|
69
73
|
reset: () => {
|
|
70
74
|
this.reset()
|
|
71
75
|
},
|
package/src/Match.tsx
CHANGED
|
@@ -63,7 +63,7 @@ export function Match({ matchId }: { matchId: string }) {
|
|
|
63
63
|
: SafeFragment
|
|
64
64
|
|
|
65
65
|
const resetKey = useRouterState({
|
|
66
|
-
select: (s) => s.
|
|
66
|
+
select: (s) => s.loadedAt,
|
|
67
67
|
})
|
|
68
68
|
|
|
69
69
|
return (
|
|
@@ -108,23 +108,44 @@ function MatchInner({ matchId }: { matchId: string }): any {
|
|
|
108
108
|
|
|
109
109
|
const route = router.routesById[routeId]!
|
|
110
110
|
|
|
111
|
-
const
|
|
111
|
+
const matchIndex = useRouterState({
|
|
112
|
+
select: (s) => {
|
|
113
|
+
return s.matches.findIndex((d) => d.id === matchId)
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
const match = useRouterState({
|
|
112
118
|
select: (s) => {
|
|
113
|
-
const matchIndex = s.matches.findIndex((d) => d.id === matchId)
|
|
114
119
|
const match = s.matches[matchIndex]!
|
|
115
|
-
return [
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
]),
|
|
123
|
-
matchIndex,
|
|
124
|
-
] as const
|
|
120
|
+
return pick(match, [
|
|
121
|
+
'id',
|
|
122
|
+
'status',
|
|
123
|
+
'error',
|
|
124
|
+
'loadPromise',
|
|
125
|
+
'minPendingPromise',
|
|
126
|
+
])
|
|
125
127
|
},
|
|
126
128
|
})
|
|
127
129
|
|
|
130
|
+
// function useChangedDiff(value: any) {
|
|
131
|
+
// const ref = React.useRef(value)
|
|
132
|
+
// const changed = ref.current !== value
|
|
133
|
+
// if (changed) {
|
|
134
|
+
// console.log(
|
|
135
|
+
// 'Changed:',
|
|
136
|
+
// value,
|
|
137
|
+
// Object.fromEntries(
|
|
138
|
+
// Object.entries(value).filter(
|
|
139
|
+
// ([key, val]) => val !== ref.current[key],
|
|
140
|
+
// ),
|
|
141
|
+
// ),
|
|
142
|
+
// )
|
|
143
|
+
// }
|
|
144
|
+
// ref.current = value
|
|
145
|
+
// }
|
|
146
|
+
|
|
147
|
+
// useChangedDiff(match)
|
|
148
|
+
|
|
128
149
|
const RouteErrorComponent =
|
|
129
150
|
(route.options.errorComponent ?? router.options.defaultErrorComponent) ||
|
|
130
151
|
ErrorComponent
|
|
@@ -190,36 +211,24 @@ function MatchInner({ matchId }: { matchId: string }): any {
|
|
|
190
211
|
|
|
191
212
|
if (pendingMinMs && !match.minPendingPromise) {
|
|
192
213
|
// Create a promise that will resolve after the minPendingMs
|
|
193
|
-
match.minPendingPromise = createControlledPromise()
|
|
194
|
-
|
|
195
214
|
if (!router.isServer) {
|
|
215
|
+
const minPendingPromise = createControlledPromise<void>()
|
|
216
|
+
|
|
196
217
|
Promise.resolve().then(() => {
|
|
197
|
-
router.
|
|
198
|
-
...
|
|
199
|
-
|
|
200
|
-
d.id === match.id
|
|
201
|
-
? { ...d, minPendingPromise: createControlledPromise() }
|
|
202
|
-
: d,
|
|
203
|
-
),
|
|
218
|
+
router.updateMatch(match.id, (prev) => ({
|
|
219
|
+
...prev,
|
|
220
|
+
minPendingPromise,
|
|
204
221
|
}))
|
|
205
222
|
})
|
|
206
223
|
|
|
207
224
|
setTimeout(() => {
|
|
225
|
+
minPendingPromise.resolve()
|
|
226
|
+
|
|
208
227
|
// We've handled the minPendingPromise, so we can delete it
|
|
209
|
-
router.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
d.id === match.id
|
|
214
|
-
? {
|
|
215
|
-
...d,
|
|
216
|
-
minPendingPromise:
|
|
217
|
-
(d.minPendingPromise?.resolve(), undefined),
|
|
218
|
-
}
|
|
219
|
-
: d,
|
|
220
|
-
),
|
|
221
|
-
}
|
|
222
|
-
})
|
|
228
|
+
router.updateMatch(match.id, (prev) => ({
|
|
229
|
+
...prev,
|
|
230
|
+
minPendingPromise: undefined,
|
|
231
|
+
}))
|
|
223
232
|
}, pendingMinMs)
|
|
224
233
|
}
|
|
225
234
|
}
|
package/src/Matches.tsx
CHANGED
|
@@ -47,8 +47,10 @@ export interface RouteMatch<
|
|
|
47
47
|
paramsError: unknown
|
|
48
48
|
searchError: unknown
|
|
49
49
|
updatedAt: number
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
componentsPromise?: Promise<Array<void>>
|
|
51
|
+
loadPromise?: ControlledPromise<void>
|
|
52
|
+
beforeLoadPromise?: ControlledPromise<void>
|
|
53
|
+
loaderPromise?: ControlledPromise<void>
|
|
52
54
|
loaderData?: TLoaderData
|
|
53
55
|
routeContext: TRouteContext
|
|
54
56
|
context: TAllContext
|
|
@@ -66,6 +68,7 @@ export interface RouteMatch<
|
|
|
66
68
|
globalNotFound?: boolean
|
|
67
69
|
staticData: StaticDataRouteOption
|
|
68
70
|
minPendingPromise?: ControlledPromise<void>
|
|
71
|
+
pendingTimeout?: ReturnType<typeof setTimeout>
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
export type MakeRouteMatch<
|
|
@@ -132,7 +135,7 @@ function MatchesInner() {
|
|
|
132
135
|
})
|
|
133
136
|
|
|
134
137
|
const resetKey = useRouterState({
|
|
135
|
-
select: (s) => s.
|
|
138
|
+
select: (s) => s.loadedAt,
|
|
136
139
|
})
|
|
137
140
|
|
|
138
141
|
return (
|
|
@@ -183,6 +186,10 @@ export type UseMatchRouteOptions<
|
|
|
183
186
|
export function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {
|
|
184
187
|
const router = useRouter()
|
|
185
188
|
|
|
189
|
+
useRouterState({
|
|
190
|
+
select: (s) => [s.location.href, s.resolvedLocation.href, s.status],
|
|
191
|
+
})
|
|
192
|
+
|
|
186
193
|
return React.useCallback(
|
|
187
194
|
<
|
|
188
195
|
TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -104,17 +104,6 @@ export function RouterProvider<
|
|
|
104
104
|
)
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
export function getRouteMatch<TRouteTree extends AnyRoute>(
|
|
108
|
-
state: RouterState<TRouteTree>,
|
|
109
|
-
id: string,
|
|
110
|
-
): undefined | MakeRouteMatch<TRouteTree> {
|
|
111
|
-
return [
|
|
112
|
-
...state.cachedMatches,
|
|
113
|
-
...(state.pendingMatches ?? []),
|
|
114
|
-
...state.matches,
|
|
115
|
-
].find((d) => d.id === id)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
107
|
export type RouterProps<
|
|
119
108
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
120
109
|
TDehydrated extends Record<string, any> = Record<string, any>,
|
package/src/Transitioner.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import * as React from 'react'
|
|
|
2
2
|
import { pick, useLayoutEffect, usePrevious } from './utils'
|
|
3
3
|
import { useRouter } from './useRouter'
|
|
4
4
|
import { useRouterState } from './useRouterState'
|
|
5
|
+
import { trimPathRight } from '.'
|
|
5
6
|
|
|
6
7
|
export function Transitioner() {
|
|
7
8
|
const router = useRouter()
|
|
@@ -40,7 +41,10 @@ export function Transitioner() {
|
|
|
40
41
|
state: true,
|
|
41
42
|
})
|
|
42
43
|
|
|
43
|
-
if (
|
|
44
|
+
if (
|
|
45
|
+
trimPathRight(router.latestLocation.href) !==
|
|
46
|
+
trimPathRight(nextLocation.href)
|
|
47
|
+
) {
|
|
44
48
|
router.commitLocation({ ...nextLocation, replace: true })
|
|
45
49
|
}
|
|
46
50
|
|
package/src/index.tsx
CHANGED