@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.
@@ -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: string }
40
- static getDerivedStateFromProps(props: any) {
41
- return { resetKey: props.getResetKey() }
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 router.getMatch(match.id)?._nonReactive.displayPendingPromise
306
+ throw getMatchPromise(match, 'displayPendingPromise')
291
307
  }
292
308
 
293
309
  if (match._forcePending) {
294
- throw router.getMatch(match.id)?._nonReactive.minPendingPromise
310
+ throw getMatchPromise(match, 'minPendingPromise')
295
311
  }
296
312
 
297
313
  if (match.status === 'pending') {
298
- throw router.getMatch(match.id)?._nonReactive.loadPromise
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 router.getMatch(match.id)?._nonReactive.loadPromise
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 router.getMatch(match.id)?._nonReactive.displayPendingPromise
403
+ throw getMatchPromise(match, 'displayPendingPromise')
388
404
  }
389
405
 
390
406
  if (match._forcePending) {
391
- throw router.getMatch(match.id)?._nonReactive.minPendingPromise
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 router.getMatch(match.id)?._nonReactive.loadPromise
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
- // Redirects should be handled by the router transition. If we happen to
432
- // encounter a redirect here, it's a bug. Let's warn, but render nothing.
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
- // warning(
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?: RouteByPath<
184
- TRouter['routeTree'],
185
- ResolveRelativePath<TFrom, NoInfer<TTo>>
186
- >['types']['allParams'],
180
+ params?: Expand<
181
+ ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']
182
+ >,
187
183
  ) => React.ReactNode)
188
184
  | React.ReactNode
189
185
  }
package/src/link.tsx CHANGED
@@ -64,6 +64,7 @@ export function useLinkProps<
64
64
  to,
65
65
  preload: userPreload,
66
66
  preloadDelay: userPreloadDelay,
67
+ preloadIntentProximity: _preloadIntentProximity,
67
68
  hashScrollIntoView,
68
69
  replace,
69
70
  startTransition,