@tanstack/react-router 1.63.2 → 1.63.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.63.2",
3
+ "version": "1.63.4",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/route.ts CHANGED
@@ -201,9 +201,9 @@ export type FileBaseRouteOptions<
201
201
  (
202
202
  ctx: RouteContextOptions<
203
203
  TParentRoute,
204
- TSearchValidator,
205
204
  TParams,
206
- TRouterContext
205
+ TRouterContext,
206
+ TLoaderDeps
207
207
  >,
208
208
  ) => any
209
209
  >
@@ -272,9 +272,8 @@ export type BaseRouteOptions<
272
272
 
273
273
  export interface ContextOptions<
274
274
  in out TParentRoute extends AnyRoute,
275
- in out TSearchValidator,
276
275
  in out TParams,
277
- > extends FullSearchSchemaOption<TParentRoute, TSearchValidator> {
276
+ > {
278
277
  abortController: AbortController
279
278
  preload: boolean
280
279
  params: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>
@@ -290,10 +289,11 @@ export interface ContextOptions<
290
289
 
291
290
  export interface RouteContextOptions<
292
291
  in out TParentRoute extends AnyRoute,
293
- in out TSearchValidator,
294
292
  in out TParams,
295
293
  in out TRouterContext,
296
- > extends ContextOptions<TParentRoute, TSearchValidator, TParams> {
294
+ in out TLoaderDeps,
295
+ > extends ContextOptions<TParentRoute, TParams> {
296
+ deps: TLoaderDeps
297
297
  context: Expand<RouteContextParameter<TParentRoute, TRouterContext>>
298
298
  }
299
299
 
@@ -303,7 +303,8 @@ export interface BeforeLoadContextOptions<
303
303
  in out TParams,
304
304
  in out TRouterContext,
305
305
  in out TRouteContextFn,
306
- > extends ContextOptions<TParentRoute, TSearchValidator, TParams> {
306
+ > extends ContextOptions<TParentRoute, TParams>,
307
+ FullSearchSchemaOption<TParentRoute, TSearchValidator> {
307
308
  context: Expand<
308
309
  BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>
309
310
  >
package/src/router.ts CHANGED
@@ -82,8 +82,6 @@ import type { NotFoundError } from './not-found'
82
82
  import type { NavigateOptions, ResolveRelativePath, ToOptions } from './link'
83
83
  import type { RouterTransformer } from './transformer'
84
84
 
85
- //
86
-
87
85
  declare global {
88
86
  interface Window {
89
87
  __TSR__?: {
@@ -600,7 +598,11 @@ export function createRouter<
600
598
  >(options)
601
599
  }
602
600
 
603
- type MatchRoutesOpts = { preload?: boolean; throwOnError?: boolean }
601
+ type MatchRoutesOpts = {
602
+ preload?: boolean
603
+ throwOnError?: boolean
604
+ _buildLocation?: boolean
605
+ }
604
606
 
605
607
  export class Router<
606
608
  in out TRouteTree extends AnyRoute,
@@ -991,10 +993,8 @@ export class Router<
991
993
 
992
994
  public matchRoutes(
993
995
  pathnameOrNext: string | ParsedLocation,
994
- locationSearchOrOpts?:
995
- | AnySearchSchema
996
- | { preload?: boolean; throwOnError?: boolean },
997
- opts?: { preload?: boolean; throwOnError?: boolean },
996
+ locationSearchOrOpts?: AnySearchSchema | MatchRoutesOpts,
997
+ opts?: MatchRoutesOpts,
998
998
  ) {
999
999
  if (typeof pathnameOrNext === 'string') {
1000
1000
  return this.matchRoutesInternal(
@@ -1011,7 +1011,7 @@ export class Router<
1011
1011
 
1012
1012
  private matchRoutesInternal(
1013
1013
  next: ParsedLocation,
1014
- opts?: { preload?: boolean; throwOnError?: boolean },
1014
+ opts?: MatchRoutesOpts,
1015
1015
  ): Array<AnyRouteMatch> {
1016
1016
  let routeParams: Record<string, string> = {}
1017
1017
 
@@ -1081,9 +1081,6 @@ export class Router<
1081
1081
  return rootRouteId
1082
1082
  })()
1083
1083
 
1084
- // Existing matches are matches that are already loaded along with
1085
- // pending matches that are still loading
1086
-
1087
1084
  const parseErrors = matchedRoutes.map((route) => {
1088
1085
  let parsedParamsError
1089
1086
 
@@ -1182,6 +1179,9 @@ export class Router<
1182
1179
  // Waste not, want not. If we already have a match for this route,
1183
1180
  // reuse it. This is important for layout routes, which might stick
1184
1181
  // around between navigation actions that only change leaf routes.
1182
+
1183
+ // Existing matches are matches that are already loaded along with
1184
+ // pending matches that are still loading
1185
1185
  const existingMatch = this.getMatch(matchId)
1186
1186
 
1187
1187
  const cause = this.state.matches.find((d) => d.id === matchId)
@@ -1274,28 +1274,31 @@ export class Router<
1274
1274
  ...match.__beforeLoadContext,
1275
1275
  }
1276
1276
 
1277
- // Update the match's context
1278
- const contextFnContext: RouteContextOptions<any, any, any, any> = {
1279
- search: match.search,
1280
- params: match.params,
1281
- context: match.context,
1282
- location: next,
1283
- navigate: (opts: any) =>
1284
- this.navigate({ ...opts, _fromLocation: next }),
1285
- buildLocation: this.buildLocation,
1286
- cause: match.cause,
1287
- abortController: match.abortController,
1288
- preload: !!match.preload,
1289
- matches,
1290
- }
1277
+ // only execute `context` if we are not just building a location
1278
+ if (!existingMatch && opts?._buildLocation !== true) {
1279
+ // Update the match's context
1280
+ const contextFnContext: RouteContextOptions<any, any, any, any> = {
1281
+ deps: loaderDeps,
1282
+ params: match.params,
1283
+ context: match.context,
1284
+ location: next,
1285
+ navigate: (opts: any) =>
1286
+ this.navigate({ ...opts, _fromLocation: next }),
1287
+ buildLocation: this.buildLocation,
1288
+ cause: match.cause,
1289
+ abortController: match.abortController,
1290
+ preload: !!match.preload,
1291
+ matches,
1292
+ }
1291
1293
 
1292
- // Get the route context
1293
- match.__routeContext = route.options.context?.(contextFnContext) ?? {}
1294
+ // Get the route context
1295
+ match.__routeContext = route.options.context?.(contextFnContext) ?? {}
1294
1296
 
1295
- match.context = {
1296
- ...parentContext,
1297
- ...match.__routeContext,
1298
- ...match.__beforeLoadContext,
1297
+ match.context = {
1298
+ ...parentContext,
1299
+ ...match.__routeContext,
1300
+ ...match.__beforeLoadContext,
1301
+ }
1299
1302
  }
1300
1303
 
1301
1304
  matches.push(match)
@@ -1327,7 +1330,7 @@ export class Router<
1327
1330
  matches?: Array<MakeRouteMatch<TRouteTree>>,
1328
1331
  ): ParsedLocation => {
1329
1332
  const fromMatches = dest._fromLocation
1330
- ? this.matchRoutes(dest._fromLocation)
1333
+ ? this.matchRoutes(dest._fromLocation, { _buildLocation: true })
1331
1334
  : this.state.matches
1332
1335
 
1333
1336
  const fromMatch =
@@ -1506,9 +1509,9 @@ export class Router<
1506
1509
  }
1507
1510
  }
1508
1511
 
1509
- const nextMatches = this.matchRoutes(next)
1512
+ const nextMatches = this.matchRoutes(next, { _buildLocation: true })
1510
1513
  const maskedMatches = maskedNext
1511
- ? this.matchRoutes(maskedNext)
1514
+ ? this.matchRoutes(maskedNext, { _buildLocation: true })
1512
1515
  : undefined
1513
1516
  const maskedFinal = maskedNext
1514
1517
  ? build(maskedDest, maskedMatches)
@@ -2254,10 +2257,8 @@ export class Router<
2254
2257
  route._lazyPromise ||
2255
2258
  (route.lazyFn
2256
2259
  ? route.lazyFn().then((lazyRoute) => {
2257
- Object.assign(
2258
- route.options,
2259
- lazyRoute.options,
2260
- )
2260
+ const { id, ...options } = lazyRoute.options
2261
+ Object.assign(route.options, options)
2261
2262
  })
2262
2263
  : Promise.resolve())
2263
2264