@depup/tanstack__react-router 1.168.10-depup.1 → 1.168.13-depup.0
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/README.md +2 -2
- package/changes.json +1 -1
- package/dist/cjs/CatchBoundary.cjs +8 -6
- package/dist/cjs/CatchBoundary.cjs.map +1 -1
- package/dist/cjs/Match.cjs +11 -8
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +2 -2
- package/dist/cjs/link.cjs +1 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/esm/CatchBoundary.js +8 -6
- package/dist/esm/CatchBoundary.js.map +1 -1
- package/dist/esm/Match.js +11 -8
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.d.ts +2 -2
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/link.js +1 -1
- package/dist/esm/link.js.map +1 -1
- package/package.json +3 -3
- package/src/CatchBoundary.tsx +14 -20
- package/src/Match.tsx +28 -14
- package/src/Matches.tsx +3 -7
- package/src/link.tsx +1 -0
package/src/CatchBoundary.tsx
CHANGED
|
@@ -36,9 +36,19 @@ class CatchBoundaryImpl extends React.Component<{
|
|
|
36
36
|
}) => React.ReactNode
|
|
37
37
|
onCatch?: (error: Error, errorInfo: ErrorInfo) => void
|
|
38
38
|
}> {
|
|
39
|
-
state = { error: null } as { error: Error | null; resetKey
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
state = { error: null } as { error: Error | null; resetKey?: string | number }
|
|
40
|
+
|
|
41
|
+
static getDerivedStateFromProps(
|
|
42
|
+
props: { getResetKey: () => string | number },
|
|
43
|
+
state: { resetKey?: string | number; error: Error | null },
|
|
44
|
+
) {
|
|
45
|
+
const resetKey = props.getResetKey()
|
|
46
|
+
|
|
47
|
+
if (state.error && state.resetKey !== resetKey) {
|
|
48
|
+
return { resetKey, error: null }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return { resetKey }
|
|
42
52
|
}
|
|
43
53
|
static getDerivedStateFromError(error: Error) {
|
|
44
54
|
return { error }
|
|
@@ -46,30 +56,14 @@ class CatchBoundaryImpl extends React.Component<{
|
|
|
46
56
|
reset() {
|
|
47
57
|
this.setState({ error: null })
|
|
48
58
|
}
|
|
49
|
-
componentDidUpdate(
|
|
50
|
-
prevProps: Readonly<{
|
|
51
|
-
getResetKey: () => string
|
|
52
|
-
children: (props: { error: any; reset: () => void }) => any
|
|
53
|
-
onCatch?: ((error: any, info: any) => void) | undefined
|
|
54
|
-
}>,
|
|
55
|
-
prevState: any,
|
|
56
|
-
): void {
|
|
57
|
-
if (prevState.error && prevState.resetKey !== this.state.resetKey) {
|
|
58
|
-
this.reset()
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
59
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
62
60
|
if (this.props.onCatch) {
|
|
63
61
|
this.props.onCatch(error, errorInfo)
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
64
|
render() {
|
|
67
|
-
// If the resetKey has changed, don't render the error
|
|
68
65
|
return this.props.children({
|
|
69
|
-
error:
|
|
70
|
-
this.state.resetKey !== this.props.getResetKey()
|
|
71
|
-
? null
|
|
72
|
-
: this.state.error,
|
|
66
|
+
error: this.state.error,
|
|
73
67
|
reset: () => {
|
|
74
68
|
this.reset()
|
|
75
69
|
},
|
package/src/Match.tsx
CHANGED
|
@@ -259,6 +259,22 @@ export const MatchInner = React.memo(function MatchInnerImpl({
|
|
|
259
259
|
}): any {
|
|
260
260
|
const router = useRouter()
|
|
261
261
|
|
|
262
|
+
const getMatchPromise = (
|
|
263
|
+
match: {
|
|
264
|
+
id: string
|
|
265
|
+
_nonReactive: {
|
|
266
|
+
displayPendingPromise?: Promise<void>
|
|
267
|
+
minPendingPromise?: Promise<void>
|
|
268
|
+
loadPromise?: Promise<void>
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
key: 'displayPendingPromise' | 'minPendingPromise' | 'loadPromise',
|
|
272
|
+
) => {
|
|
273
|
+
return (
|
|
274
|
+
router.getMatch(match.id)?._nonReactive[key] ?? match._nonReactive[key]
|
|
275
|
+
)
|
|
276
|
+
}
|
|
277
|
+
|
|
262
278
|
if (isServer ?? router.isServer) {
|
|
263
279
|
const match = router.stores.activeMatchStoresById.get(matchId)?.state
|
|
264
280
|
if (!match) {
|
|
@@ -287,15 +303,15 @@ export const MatchInner = React.memo(function MatchInnerImpl({
|
|
|
287
303
|
const out = Comp ? <Comp key={key} /> : <Outlet />
|
|
288
304
|
|
|
289
305
|
if (match._displayPending) {
|
|
290
|
-
throw
|
|
306
|
+
throw getMatchPromise(match, 'displayPendingPromise')
|
|
291
307
|
}
|
|
292
308
|
|
|
293
309
|
if (match._forcePending) {
|
|
294
|
-
throw
|
|
310
|
+
throw getMatchPromise(match, 'minPendingPromise')
|
|
295
311
|
}
|
|
296
312
|
|
|
297
313
|
if (match.status === 'pending') {
|
|
298
|
-
throw
|
|
314
|
+
throw getMatchPromise(match, 'loadPromise')
|
|
299
315
|
}
|
|
300
316
|
|
|
301
317
|
if (match.status === 'notFound') {
|
|
@@ -317,7 +333,7 @@ export const MatchInner = React.memo(function MatchInnerImpl({
|
|
|
317
333
|
|
|
318
334
|
invariant()
|
|
319
335
|
}
|
|
320
|
-
throw
|
|
336
|
+
throw getMatchPromise(match, 'loadPromise')
|
|
321
337
|
}
|
|
322
338
|
|
|
323
339
|
if (match.status === 'error') {
|
|
@@ -384,11 +400,11 @@ export const MatchInner = React.memo(function MatchInnerImpl({
|
|
|
384
400
|
}, [key, route.options.component, router.options.defaultComponent])
|
|
385
401
|
|
|
386
402
|
if (match._displayPending) {
|
|
387
|
-
throw
|
|
403
|
+
throw getMatchPromise(match, 'displayPendingPromise')
|
|
388
404
|
}
|
|
389
405
|
|
|
390
406
|
if (match._forcePending) {
|
|
391
|
-
throw
|
|
407
|
+
throw getMatchPromise(match, 'minPendingPromise')
|
|
392
408
|
}
|
|
393
409
|
|
|
394
410
|
// see also hydrate() in packages/router-core/src/ssr/ssr-client.ts
|
|
@@ -413,7 +429,7 @@ export const MatchInner = React.memo(function MatchInnerImpl({
|
|
|
413
429
|
}
|
|
414
430
|
}
|
|
415
431
|
}
|
|
416
|
-
throw
|
|
432
|
+
throw getMatchPromise(match, 'loadPromise')
|
|
417
433
|
}
|
|
418
434
|
|
|
419
435
|
if (match.status === 'notFound') {
|
|
@@ -428,8 +444,10 @@ export const MatchInner = React.memo(function MatchInnerImpl({
|
|
|
428
444
|
}
|
|
429
445
|
|
|
430
446
|
if (match.status === 'redirected') {
|
|
431
|
-
//
|
|
432
|
-
//
|
|
447
|
+
// A match can be observed as redirected during an in-flight transition,
|
|
448
|
+
// especially when pending UI is already rendering. Suspend on the match's
|
|
449
|
+
// load promise so React can abandon this stale render and continue the
|
|
450
|
+
// redirect transition.
|
|
433
451
|
if (!isRedirect(match.error)) {
|
|
434
452
|
if (process.env.NODE_ENV !== 'production') {
|
|
435
453
|
throw new Error('Invariant failed: Expected a redirect error')
|
|
@@ -438,11 +456,7 @@ export const MatchInner = React.memo(function MatchInnerImpl({
|
|
|
438
456
|
invariant()
|
|
439
457
|
}
|
|
440
458
|
|
|
441
|
-
|
|
442
|
-
// false,
|
|
443
|
-
// 'Tried to render a redirected route match! This is a weird circumstance, please file an issue!',
|
|
444
|
-
// )
|
|
445
|
-
throw router.getMatch(match.id)?._nonReactive.loadPromise
|
|
459
|
+
throw getMatchPromise(match, 'loadPromise')
|
|
446
460
|
}
|
|
447
461
|
|
|
448
462
|
if (match.status === 'error') {
|
package/src/Matches.tsx
CHANGED
|
@@ -22,11 +22,8 @@ import type {
|
|
|
22
22
|
MakeRouteMatchUnion,
|
|
23
23
|
MaskOptions,
|
|
24
24
|
MatchRouteOptions,
|
|
25
|
-
NoInfer,
|
|
26
25
|
RegisteredRouter,
|
|
27
|
-
ResolveRelativePath,
|
|
28
26
|
ResolveRoute,
|
|
29
|
-
RouteByPath,
|
|
30
27
|
ToSubOptionsProps,
|
|
31
28
|
} from '@tanstack/router-core'
|
|
32
29
|
|
|
@@ -180,10 +177,9 @@ export type MakeMatchRouteOptions<
|
|
|
180
177
|
// If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns
|
|
181
178
|
children?:
|
|
182
179
|
| ((
|
|
183
|
-
params?:
|
|
184
|
-
TRouter['
|
|
185
|
-
|
|
186
|
-
>['types']['allParams'],
|
|
180
|
+
params?: Expand<
|
|
181
|
+
ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']
|
|
182
|
+
>,
|
|
187
183
|
) => React.ReactNode)
|
|
188
184
|
| React.ReactNode
|
|
189
185
|
}
|