@tanstack/react-router 1.81.14 → 1.82.1

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.81.14",
3
+ "version": "1.82.1",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/Matches.tsx CHANGED
@@ -170,9 +170,9 @@ export interface RouteMatch<
170
170
  loaderDeps: TLoaderDeps
171
171
  preload: boolean
172
172
  invalid: boolean
173
- meta?: Array<React.JSX.IntrinsicElements['meta']>
174
- links?: Array<React.JSX.IntrinsicElements['link']>
175
- scripts?: Array<React.JSX.IntrinsicElements['script']>
173
+ meta?: Array<React.JSX.IntrinsicElements['meta'] | undefined>
174
+ links?: Array<React.JSX.IntrinsicElements['link'] | undefined>
175
+ scripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>
176
176
  headers?: Record<string, string>
177
177
  globalNotFound?: boolean
178
178
  staticData: StaticDataRouteOption
package/src/route.ts CHANGED
@@ -17,6 +17,7 @@ import type * as React from 'react'
17
17
  import type { RootRouteId } from './root'
18
18
  import type { UseNavigateResult } from './useNavigate'
19
19
  import type {
20
+ AnyRouteMatch,
20
21
  MakeRouteMatchFromRoute,
21
22
  MakeRouteMatchUnion,
22
23
  RouteMatch,
@@ -434,7 +435,10 @@ export interface UpdatableRouteOptions<
434
435
  TLoaderDeps
435
436
  >,
436
437
  ) => void
437
- meta?: (ctx: {
438
+ headers?: (ctx: {
439
+ loaderData: ResolveLoaderData<TLoaderFn>
440
+ }) => Record<string, string>
441
+ head?: (ctx: {
438
442
  matches: Array<
439
443
  RouteMatch<
440
444
  TRouteId,
@@ -466,13 +470,12 @@ export interface UpdatableRouteOptions<
466
470
  TLoaderDeps
467
471
  >
468
472
  params: ResolveAllParamsFromParent<TParentRoute, TParams>
469
- loaderData: ResolveLoaderData<TLoaderFn>
470
- }) => Array<React.JSX.IntrinsicElements['meta']>
471
- links?: () => Array<React.JSX.IntrinsicElements['link']>
472
- scripts?: () => Array<React.JSX.IntrinsicElements['script']>
473
- headers?: (ctx: {
474
- loaderData: ResolveLoaderData<TLoaderFn>
475
- }) => Record<string, string>
473
+ loaderData: ResolveLoaderData<TLoaderFn> | undefined
474
+ }) => {
475
+ links?: AnyRouteMatch['links']
476
+ scripts?: AnyRouteMatch['scripts']
477
+ meta?: AnyRouteMatch['meta']
478
+ }
476
479
  ssr?: boolean
477
480
  }
478
481
 
package/src/router.ts CHANGED
@@ -1298,25 +1298,30 @@ export class Router<
1298
1298
  : loaderDeps,
1299
1299
  invalid: false,
1300
1300
  preload: false,
1301
- links: route.options.links?.(),
1302
- scripts: route.options.scripts?.(),
1301
+ links: undefined,
1302
+ scripts: undefined,
1303
+ meta: undefined,
1303
1304
  staticData: route.options.staticData || {},
1304
1305
  loadPromise: createControlledPromise(),
1305
1306
  fullPath: route.fullPath,
1306
1307
  }
1307
1308
  }
1308
1309
 
1309
- // If it's already a success, update the meta and headers
1310
+ const headFnContent = route.options.head?.({
1311
+ matches,
1312
+ match,
1313
+ params: match.params,
1314
+ loaderData: match.loaderData ?? undefined,
1315
+ })
1316
+
1317
+ match.links = headFnContent?.links
1318
+ match.scripts = headFnContent?.scripts
1319
+ match.meta = headFnContent?.meta
1320
+
1321
+ // If it's already a success, update the headers
1310
1322
  // These may get updated again if the match is refreshed
1311
1323
  // due to being stale
1312
1324
  if (match.status === 'success') {
1313
- match.meta = route.options.meta?.({
1314
- matches,
1315
- match,
1316
- params: match.params,
1317
- loaderData: match.loaderData,
1318
- })
1319
-
1320
1325
  match.headers = route.options.headers?.({
1321
1326
  loaderData: match.loaderData,
1322
1327
  })
@@ -2516,12 +2521,13 @@ export class Router<
2516
2521
 
2517
2522
  await potentialPendingMinPromise()
2518
2523
 
2519
- const meta = route.options.meta?.({
2524
+ const headFnContent = route.options.head?.({
2520
2525
  matches,
2521
2526
  match: this.getMatch(matchId)!,
2522
2527
  params: this.getMatch(matchId)!.params,
2523
2528
  loaderData,
2524
2529
  })
2530
+ const meta = headFnContent?.meta
2525
2531
 
2526
2532
  const headers = route.options.headers?.({
2527
2533
  loaderData,