@tanstack/react-router 1.91.2 → 1.91.3

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.91.2",
3
+ "version": "1.91.3",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/router.ts CHANGED
@@ -1224,6 +1224,16 @@ export class Router<
1224
1224
 
1225
1225
  const matches: Array<AnyRouteMatch> = []
1226
1226
 
1227
+ const getParentContext = (parentMatch?: AnyRouteMatch) => {
1228
+ const parentMatchId = parentMatch?.id
1229
+
1230
+ const parentContext = !parentMatchId
1231
+ ? ((this.options.context as any) ?? {})
1232
+ : (parentMatch.context ?? this.options.context ?? {})
1233
+
1234
+ return parentContext
1235
+ }
1236
+
1227
1237
  matchedRoutes.forEach((route, index) => {
1228
1238
  // Take each matched route and resolve + validate its search params
1229
1239
  // This has to happen serially because each route's search params
@@ -1361,17 +1371,6 @@ export class Router<
1361
1371
  }
1362
1372
  }
1363
1373
 
1364
- const headFnContent = route.options.head?.({
1365
- matches,
1366
- match,
1367
- params: match.params,
1368
- loaderData: match.loaderData ?? undefined,
1369
- })
1370
-
1371
- match.links = headFnContent?.links
1372
- match.scripts = headFnContent?.scripts
1373
- match.meta = headFnContent?.meta
1374
-
1375
1374
  // If it's already a success, update the headers
1376
1375
  // These may get updated again if the match is refreshed
1377
1376
  // due to being stale
@@ -1389,11 +1388,7 @@ export class Router<
1389
1388
  // update the searchError if there is one
1390
1389
  match.searchError = searchError
1391
1390
 
1392
- const parentMatchId = parentMatch?.id
1393
-
1394
- const parentContext = !parentMatchId
1395
- ? ((this.options.context as any) ?? {})
1396
- : (parentMatch.context ?? this.options.context ?? {})
1391
+ const parentContext = getParentContext(parentMatch)
1397
1392
 
1398
1393
  match.context = {
1399
1394
  ...parentContext,
@@ -1401,13 +1396,23 @@ export class Router<
1401
1396
  ...match.__beforeLoadContext,
1402
1397
  }
1403
1398
 
1399
+ matches.push(match)
1400
+ })
1401
+
1402
+ matches.forEach((match, index) => {
1403
+ const route = this.looseRoutesById[match.routeId]!
1404
+ const existingMatch = this.getMatch(match.id)
1405
+
1404
1406
  // only execute `context` if we are not just building a location
1405
1407
  if (!existingMatch && opts?._buildLocation !== true) {
1408
+ const parentMatch = matches[index - 1]
1409
+ const parentContext = getParentContext(parentMatch)
1410
+
1406
1411
  // Update the match's context
1407
1412
  const contextFnContext: RouteContextOptions<any, any, any, any> = {
1408
- deps: loaderDeps,
1413
+ deps: match.loaderDeps,
1409
1414
  params: match.params,
1410
- context: match.context,
1415
+ context: parentContext,
1411
1416
  location: next,
1412
1417
  navigate: (opts: any) =>
1413
1418
  this.navigate({ ...opts, _fromLocation: next }),
@@ -1428,10 +1433,19 @@ export class Router<
1428
1433
  }
1429
1434
  }
1430
1435
 
1431
- matches.push(match)
1436
+ const headFnContent = route.options.head?.({
1437
+ matches,
1438
+ match,
1439
+ params: match.params,
1440
+ loaderData: match.loaderData ?? undefined,
1441
+ })
1442
+
1443
+ match.links = headFnContent?.links
1444
+ match.scripts = headFnContent?.scripts
1445
+ match.meta = headFnContent?.meta
1432
1446
  })
1433
1447
 
1434
- return matches as any
1448
+ return matches
1435
1449
  }
1436
1450
 
1437
1451
  getMatchedRoutes = (next: ParsedLocation, dest?: BuildNextOptions) => {