@tanstack/react-router 1.52.4 → 1.53.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.52.4",
3
+ "version": "1.53.0",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/Matches.tsx CHANGED
@@ -352,8 +352,8 @@ export function MatchRoute<
352
352
  return params ? props.children : null
353
353
  }
354
354
 
355
- export type MakeRouteMatches<
356
- TRouter extends AnyRouter = AnyRouter,
355
+ export type MakeRouteMatchUnion<
356
+ TRouter extends AnyRouter = RegisteredRouter,
357
357
  TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,
358
358
  > = TRoute extends any
359
359
  ? RouteMatch<
@@ -369,7 +369,7 @@ export type MakeRouteMatches<
369
369
 
370
370
  export function useMatches<
371
371
  TRouter extends AnyRouter = RegisteredRouter,
372
- TRouteMatch = MakeRouteMatches<TRouter>,
372
+ TRouteMatch = MakeRouteMatchUnion<TRouter>,
373
373
  T = Array<TRouteMatch>,
374
374
  >(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {
375
375
  return useRouterState({
package/src/route.ts CHANGED
@@ -11,7 +11,7 @@ import { rootRouteId } from './root'
11
11
  import type * as React from 'react'
12
12
  import type { RootRouteId } from './root'
13
13
  import type { UseNavigateResult } from './useNavigate'
14
- import type { MakeRouteMatch, RouteMatch } from './Matches'
14
+ import type { MakeRouteMatch, MakeRouteMatchUnion, RouteMatch } from './Matches'
15
15
  import type { NavigateOptions, ParsePathParams, ToMaskOptions } from './link'
16
16
  import type { ParsedLocation } from './location'
17
17
  import type { RouteById, RouteIds, RoutePaths } from './routeInfo'
@@ -285,6 +285,7 @@ export interface ContextOptions<
285
285
  navigate: NavigateFn
286
286
  buildLocation: BuildLocationFn
287
287
  cause: 'preload' | 'enter' | 'stay'
288
+ matches: Array<MakeRouteMatchUnion>
288
289
  }
289
290
 
290
291
  export interface RouteContextOptions<
package/src/router.ts CHANGED
@@ -1264,6 +1264,7 @@ export class Router<
1264
1264
  cause: match.cause,
1265
1265
  abortController: match.abortController,
1266
1266
  preload: !!match.preload,
1267
+ matches,
1267
1268
  }
1268
1269
 
1269
1270
  // Get the route context
@@ -1971,12 +1972,38 @@ export class Router<
1971
1972
  const existingMatch = this.getMatch(matchId)!
1972
1973
  const parentMatchId = matches[index - 1]?.id
1973
1974
 
1975
+ const route = this.looseRoutesById[routeId]!
1976
+
1977
+ const pendingMs =
1978
+ route.options.pendingMs ?? this.options.defaultPendingMs
1979
+
1980
+ const shouldPending = !!(
1981
+ onReady &&
1982
+ !this.isServer &&
1983
+ !preload &&
1984
+ (route.options.loader || route.options.beforeLoad) &&
1985
+ typeof pendingMs === 'number' &&
1986
+ pendingMs !== Infinity &&
1987
+ (route.options.pendingComponent ??
1988
+ this.options.defaultPendingComponent)
1989
+ )
1990
+
1974
1991
  if (
1975
1992
  // If we are in the middle of a load, either of these will be present
1976
1993
  // (not to be confused with `loadPromise`, which is always defined)
1977
1994
  existingMatch.beforeLoadPromise ||
1978
1995
  existingMatch.loaderPromise
1979
1996
  ) {
1997
+ if (shouldPending) {
1998
+ setTimeout(() => {
1999
+ try {
2000
+ // Update the match and prematurely resolve the loadMatches promise so that
2001
+ // the pending component can start rendering
2002
+ triggerOnReady()
2003
+ } catch {}
2004
+ }, pendingMs)
2005
+ }
2006
+
1980
2007
  // Wait for the beforeLoad to resolve before we continue
1981
2008
  await existingMatch.beforeLoadPromise
1982
2009
  } else {
@@ -1990,23 +2017,8 @@ export class Router<
1990
2017
  beforeLoadPromise: createControlledPromise<void>(),
1991
2018
  }))
1992
2019
 
1993
- const route = this.looseRoutesById[routeId]!
1994
2020
  const abortController = new AbortController()
1995
2021
 
1996
- const pendingMs =
1997
- route.options.pendingMs ?? this.options.defaultPendingMs
1998
-
1999
- const shouldPending = !!(
2000
- onReady &&
2001
- !this.isServer &&
2002
- !preload &&
2003
- (route.options.loader || route.options.beforeLoad) &&
2004
- typeof pendingMs === 'number' &&
2005
- pendingMs !== Infinity &&
2006
- (route.options.pendingComponent ??
2007
- this.options.defaultPendingComponent)
2008
- )
2009
-
2010
2022
  let pendingTimeout: ReturnType<typeof setTimeout>
2011
2023
 
2012
2024
  if (shouldPending) {
@@ -2069,6 +2081,7 @@ export class Router<
2069
2081
  this.navigate({ ...opts, _fromLocation: location }),
2070
2082
  buildLocation: this.buildLocation,
2071
2083
  cause: preload ? 'preload' : cause,
2084
+ matches,
2072
2085
  }
2073
2086
 
2074
2087
  let beforeLoadContext =