@tanstack/react-router 1.104.1 → 1.105.5

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.
Files changed (49) hide show
  1. package/dist/cjs/Asset.cjs +41 -0
  2. package/dist/cjs/Asset.cjs.map +1 -0
  3. package/dist/cjs/Asset.d.cts +2 -0
  4. package/dist/cjs/HeadContent.cjs +138 -0
  5. package/dist/cjs/HeadContent.cjs.map +1 -0
  6. package/dist/cjs/HeadContent.d.cts +7 -0
  7. package/dist/cjs/Matches.cjs.map +1 -1
  8. package/dist/cjs/Matches.d.cts +1 -0
  9. package/dist/cjs/Scripts.cjs +50 -0
  10. package/dist/cjs/Scripts.cjs.map +1 -0
  11. package/dist/cjs/Scripts.d.cts +1 -0
  12. package/dist/cjs/index.cjs +6 -0
  13. package/dist/cjs/index.cjs.map +1 -1
  14. package/dist/cjs/index.d.cts +3 -0
  15. package/dist/cjs/route.cjs.map +1 -1
  16. package/dist/cjs/route.d.cts +10 -7
  17. package/dist/cjs/router.cjs +19 -13
  18. package/dist/cjs/router.cjs.map +1 -1
  19. package/dist/cjs/useNavigate.cjs +9 -5
  20. package/dist/cjs/useNavigate.cjs.map +1 -1
  21. package/dist/esm/Asset.d.ts +2 -0
  22. package/dist/esm/Asset.js +41 -0
  23. package/dist/esm/Asset.js.map +1 -0
  24. package/dist/esm/HeadContent.d.ts +7 -0
  25. package/dist/esm/HeadContent.js +122 -0
  26. package/dist/esm/HeadContent.js.map +1 -0
  27. package/dist/esm/Matches.d.ts +1 -0
  28. package/dist/esm/Matches.js.map +1 -1
  29. package/dist/esm/Scripts.d.ts +1 -0
  30. package/dist/esm/Scripts.js +50 -0
  31. package/dist/esm/Scripts.js.map +1 -0
  32. package/dist/esm/index.d.ts +3 -0
  33. package/dist/esm/index.js +6 -0
  34. package/dist/esm/index.js.map +1 -1
  35. package/dist/esm/route.d.ts +10 -7
  36. package/dist/esm/route.js.map +1 -1
  37. package/dist/esm/router.js +19 -13
  38. package/dist/esm/router.js.map +1 -1
  39. package/dist/esm/useNavigate.js +9 -5
  40. package/dist/esm/useNavigate.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/Asset.tsx +40 -0
  43. package/src/HeadContent.tsx +151 -0
  44. package/src/Matches.tsx +1 -0
  45. package/src/Scripts.tsx +64 -0
  46. package/src/index.tsx +4 -0
  47. package/src/route.ts +71 -32
  48. package/src/router.ts +14 -8
  49. package/src/useNavigate.tsx +15 -6
@@ -59,6 +59,12 @@ export type MakeRemountDepsOptionsUnion<TRouteTree extends AnyRoute = Registered
59
59
  export interface BeforeLoadContextOptions<in out TParentRoute extends AnyRoute, in out TSearchValidator, in out TParams, in out TRouterContext, in out TRouteContextFn> extends ContextOptions<TParentRoute, TParams>, FullSearchSchemaOption<TParentRoute, TSearchValidator> {
60
60
  context: Expand<BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>>;
61
61
  }
62
+ type AssetFnContextOptions<in out TRouteId, in out TFullPath, in out TParentRoute extends AnyRoute, in out TParams, in out TSearchValidator, in out TLoaderFn, in out TRouterContext, in out TRouteContextFn, in out TBeforeLoadFn, in out TLoaderDeps> = {
63
+ matches: Array<RouteMatch<TRouteId, TFullPath, ResolveAllParamsFromParent<TParentRoute, TParams>, ResolveFullSearchSchema<TParentRoute, TSearchValidator>, ResolveLoaderData<TLoaderFn>, ResolveAllContext<TParentRoute, TRouterContext, TRouteContextFn, TBeforeLoadFn>, TLoaderDeps>>;
64
+ match: RouteMatch<TRouteId, TFullPath, ResolveAllParamsFromParent<TParentRoute, TParams>, ResolveFullSearchSchema<TParentRoute, TSearchValidator>, ResolveLoaderData<TLoaderFn>, ResolveAllContext<TParentRoute, TRouterContext, TRouteContextFn, TBeforeLoadFn>, TLoaderDeps>;
65
+ params: ResolveAllParamsFromParent<TParentRoute, TParams>;
66
+ loaderData: ResolveLoaderData<TLoaderFn>;
67
+ };
62
68
  export interface UpdatableRouteOptions<in out TParentRoute extends AnyRoute, in out TRouteId, in out TFullPath, in out TParams, in out TSearchValidator, in out TLoaderFn, in out TLoaderDeps, in out TRouterContext, in out TRouteContextFn, in out TBeforeLoadFn> extends UpdatableStaticRouteOption {
63
69
  caseSensitive?: boolean;
64
70
  wrapInSuspense?: boolean;
@@ -92,16 +98,12 @@ export interface UpdatableRouteOptions<in out TParentRoute extends AnyRoute, in
92
98
  headers?: (ctx: {
93
99
  loaderData: ResolveLoaderData<TLoaderFn>;
94
100
  }) => Record<string, string>;
95
- head?: (ctx: {
96
- matches: Array<RouteMatch<TRouteId, TFullPath, ResolveAllParamsFromParent<TParentRoute, TParams>, ResolveFullSearchSchema<TParentRoute, TSearchValidator>, ResolveLoaderData<TLoaderFn>, ResolveAllContext<TParentRoute, TRouterContext, TRouteContextFn, TBeforeLoadFn>, TLoaderDeps>>;
97
- match: RouteMatch<TRouteId, TFullPath, ResolveAllParamsFromParent<TParentRoute, TParams>, ResolveFullSearchSchema<TParentRoute, TSearchValidator>, ResolveLoaderData<TLoaderFn>, ResolveAllContext<TParentRoute, TRouterContext, TRouteContextFn, TBeforeLoadFn>, TLoaderDeps>;
98
- params: ResolveAllParamsFromParent<TParentRoute, TParams>;
99
- loaderData: ResolveLoaderData<TLoaderFn>;
100
- }) => {
101
+ head?: (ctx: AssetFnContextOptions<TRouteId, TFullPath, TParentRoute, TParams, TSearchValidator, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps>) => {
101
102
  links?: AnyRouteMatch['links'];
102
- scripts?: AnyRouteMatch['scripts'];
103
+ scripts?: AnyRouteMatch['headScripts'];
103
104
  meta?: AnyRouteMatch['meta'];
104
105
  };
106
+ scripts?: (ctx: AssetFnContextOptions<TRouteId, TFullPath, TParentRoute, TParams, TSearchValidator, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps>) => AnyRouteMatch['scripts'];
105
107
  ssr?: boolean;
106
108
  codeSplitGroupings?: Array<Array<'loader' | 'component' | 'pendingComponent' | 'notFoundComponent' | 'errorComponent'>>;
107
109
  }
@@ -292,3 +294,4 @@ export type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>;
292
294
  export declare class NotFoundRoute<TParentRoute extends AnyRootRoute, TRouterContext = AnyContext, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TSearchValidator = undefined, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined, TChildren = unknown> extends Route<TParentRoute, '/404', '/404', '404', '404', TSearchValidator, {}, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren> {
293
295
  constructor(options: Omit<RouteOptions<TParentRoute, string, string, string, string, TSearchValidator, {}, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn>, 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id' | 'params'>);
294
296
  }
297
+ export {};
@@ -1064,7 +1064,7 @@ class Router {
1064
1064
  preload: !!preload && !this.state.matches.find((d) => d.id === matchId)
1065
1065
  }));
1066
1066
  const runLoader = async () => {
1067
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i;
1067
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k;
1068
1068
  try {
1069
1069
  const potentialPendingMinPromise = async () => {
1070
1070
  const latestMatch = this.getMatch(matchId);
@@ -1085,16 +1085,18 @@ class Router {
1085
1085
  );
1086
1086
  await route._lazyPromise;
1087
1087
  await potentialPendingMinPromise();
1088
- const headFnContent = (_d = (_c2 = route.options).head) == null ? void 0 : _d.call(_c2, {
1088
+ const assetContext = {
1089
1089
  matches,
1090
1090
  match: this.getMatch(matchId),
1091
1091
  params: this.getMatch(matchId).params,
1092
1092
  loaderData
1093
- });
1093
+ };
1094
+ const headFnContent = (_d = (_c2 = route.options).head) == null ? void 0 : _d.call(_c2, assetContext);
1094
1095
  const meta = headFnContent == null ? void 0 : headFnContent.meta;
1095
1096
  const links = headFnContent == null ? void 0 : headFnContent.links;
1096
- const scripts = headFnContent == null ? void 0 : headFnContent.scripts;
1097
- const headers = (_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, {
1097
+ const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
1098
+ const scripts = (_f = (_e = route.options).scripts) == null ? void 0 : _f.call(_e, assetContext);
1099
+ const headers = (_h = (_g = route.options).headers) == null ? void 0 : _h.call(_g, {
1098
1100
  loaderData
1099
1101
  });
1100
1102
  updateMatch(matchId, (prev) => ({
@@ -1106,15 +1108,16 @@ class Router {
1106
1108
  loaderData,
1107
1109
  meta,
1108
1110
  links,
1109
- scripts,
1110
- headers
1111
+ headScripts,
1112
+ headers,
1113
+ scripts
1111
1114
  }));
1112
1115
  } catch (e) {
1113
1116
  let error = e;
1114
1117
  await potentialPendingMinPromise();
1115
1118
  handleRedirectAndNotFound(this.getMatch(matchId), e);
1116
1119
  try {
1117
- (_h = (_g = route.options).onError) == null ? void 0 : _h.call(_g, e);
1120
+ (_j = (_i = route.options).onError) == null ? void 0 : _j.call(_i, e);
1118
1121
  } catch (onErrorError) {
1119
1122
  error = onErrorError;
1120
1123
  handleRedirectAndNotFound(
@@ -1129,7 +1132,7 @@ class Router {
1129
1132
  isFetching: false
1130
1133
  }));
1131
1134
  }
1132
- (_i = this.serverSsr) == null ? void 0 : _i.onMatchSettled({
1135
+ (_k = this.serverSsr) == null ? void 0 : _k.onMatchSettled({
1133
1136
  router: this,
1134
1137
  match: this.getMatch(matchId)
1135
1138
  });
@@ -1589,6 +1592,7 @@ class Router {
1589
1592
  preload: false,
1590
1593
  links: void 0,
1591
1594
  scripts: void 0,
1595
+ headScripts: void 0,
1592
1596
  meta: void 0,
1593
1597
  staticData: route.options.staticData || {},
1594
1598
  loadPromise: routerCore.createControlledPromise(),
@@ -1608,7 +1612,7 @@ class Router {
1608
1612
  matches.push(match);
1609
1613
  });
1610
1614
  matches.forEach((match, index) => {
1611
- var _a, _b, _c, _d, _e, _f;
1615
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1612
1616
  const route = this.looseRoutesById[match.routeId];
1613
1617
  const existingMatch = this.getMatch(match.id);
1614
1618
  if (!existingMatch && (opts == null ? void 0 : opts._buildLocation) !== true) {
@@ -1637,15 +1641,17 @@ class Router {
1637
1641
  match.headers = (_d = (_c = route.options).headers) == null ? void 0 : _d.call(_c, {
1638
1642
  loaderData: match.loaderData
1639
1643
  });
1640
- const headFnContent = (_f = (_e = route.options).head) == null ? void 0 : _f.call(_e, {
1644
+ const assetContext = {
1641
1645
  matches,
1642
1646
  match,
1643
1647
  params: match.params,
1644
1648
  loaderData: match.loaderData
1645
- });
1649
+ };
1650
+ const headFnContent = (_f = (_e = route.options).head) == null ? void 0 : _f.call(_e, assetContext);
1646
1651
  match.links = headFnContent == null ? void 0 : headFnContent.links;
1647
- match.scripts = headFnContent == null ? void 0 : headFnContent.scripts;
1652
+ match.headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
1648
1653
  match.meta = headFnContent == null ? void 0 : headFnContent.meta;
1654
+ match.scripts = (_h = (_g = route.options).scripts) == null ? void 0 : _h.call(_g, assetContext);
1649
1655
  }
1650
1656
  });
1651
1657
  return matches;