@tanstack/router-core 1.131.7 → 1.131.13

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.
@@ -549,9 +549,7 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
549
549
  manifest: Manifest | undefined;
550
550
  };
551
551
  serverSsr?: ServerSsr;
552
- _handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError, { updateMatch, }?: {
553
- updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
554
- }) => void;
552
+ _handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError, updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void) => void;
555
553
  hasNotFoundMatch: () => boolean;
556
554
  }
557
555
  export declare class SearchParamError extends Error {
@@ -549,9 +549,7 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
549
549
  manifest: Manifest | undefined;
550
550
  };
551
551
  serverSsr?: ServerSsr;
552
- _handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError, { updateMatch, }?: {
553
- updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
554
- }) => void;
552
+ _handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError, updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void) => void;
555
553
  hasNotFoundMatch: () => boolean;
556
554
  }
557
555
  export declare class SearchParamError extends Error {
@@ -217,8 +217,8 @@ class RouterCore {
217
217
  const match = this.getMatch(id);
218
218
  if (!match) return;
219
219
  match.abortController.abort();
220
- match._nonReactive.pendingTimeout = void 0;
221
220
  clearTimeout(match._nonReactive.pendingTimeout);
221
+ match._nonReactive.pendingTimeout = void 0;
222
222
  };
223
223
  this.cancelMatches = () => {
224
224
  var _a;
@@ -727,40 +727,36 @@ class RouterCore {
727
727
  }
728
728
  const handleRedirectAndNotFound = (match, err) => {
729
729
  var _a, _b, _c;
730
- if (isRedirect(err) || isNotFound(err)) {
731
- if (isRedirect(err)) {
732
- if (err.redirectHandled) {
733
- if (!err.options.reloadDocument) {
734
- throw err;
735
- }
736
- }
737
- }
730
+ if (!isRedirect(err) && !isNotFound(err)) return;
731
+ if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {
732
+ throw err;
733
+ }
734
+ if (match) {
738
735
  (_a = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a.resolve();
739
736
  (_b = match._nonReactive.loaderPromise) == null ? void 0 : _b.resolve();
740
737
  match._nonReactive.beforeLoadPromise = void 0;
741
738
  match._nonReactive.loaderPromise = void 0;
739
+ const status = isRedirect(err) ? "redirected" : "notFound";
742
740
  updateMatch(match.id, (prev) => ({
743
741
  ...prev,
744
- status: isRedirect(err) ? "redirected" : isNotFound(err) ? "notFound" : "error",
742
+ status,
745
743
  isFetching: false,
746
744
  error: err
747
745
  }));
748
- if (!err.routeId) {
746
+ if (isNotFound(err) && !err.routeId) {
749
747
  err.routeId = match.routeId;
750
748
  }
751
749
  (_c = match._nonReactive.loadPromise) == null ? void 0 : _c.resolve();
752
- if (isRedirect(err)) {
753
- rendered = true;
754
- err.options._fromLocation = location;
755
- err.redirectHandled = true;
756
- err = this.resolveRedirect(err);
757
- throw err;
758
- } else if (isNotFound(err)) {
759
- this._handleNotFound(matches, err, {
760
- updateMatch
761
- });
762
- throw err;
763
- }
750
+ }
751
+ if (isRedirect(err)) {
752
+ rendered = true;
753
+ err.options._fromLocation = location;
754
+ err.redirectHandled = true;
755
+ err = this.resolveRedirect(err);
756
+ throw err;
757
+ } else {
758
+ this._handleNotFound(matches, err, updateMatch);
759
+ throw err;
764
760
  }
765
761
  };
766
762
  const shouldSkipLoader = (matchId) => {
@@ -979,33 +975,39 @@ class RouterCore {
979
975
  let loaderShouldRunAsync = false;
980
976
  let loaderIsRunningAsync = false;
981
977
  const route = this.looseRoutesById[routeId];
982
- const executeHead = async () => {
978
+ const executeHead = () => {
983
979
  var _a3, _b3, _c2, _d2, _e, _f;
984
980
  const match = this.getMatch(matchId);
985
981
  if (!match) {
986
982
  return;
987
983
  }
984
+ if (!route.options.head && !route.options.scripts && !route.options.headers) {
985
+ return;
986
+ }
988
987
  const assetContext = {
989
988
  matches,
990
989
  match,
991
990
  params: match.params,
992
991
  loaderData: match.loaderData
993
992
  };
994
- const headFnContent = await ((_b3 = (_a3 = route.options).head) == null ? void 0 : _b3.call(_a3, assetContext));
995
- const meta = headFnContent == null ? void 0 : headFnContent.meta;
996
- const links = headFnContent == null ? void 0 : headFnContent.links;
997
- const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
998
- const styles = headFnContent == null ? void 0 : headFnContent.styles;
999
- const scripts = await ((_d2 = (_c2 = route.options).scripts) == null ? void 0 : _d2.call(_c2, assetContext));
1000
- const headers = await ((_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, assetContext));
1001
- return {
1002
- meta,
1003
- links,
1004
- headScripts,
1005
- headers,
1006
- scripts,
1007
- styles
1008
- };
993
+ return Promise.all([
994
+ (_b3 = (_a3 = route.options).head) == null ? void 0 : _b3.call(_a3, assetContext),
995
+ (_d2 = (_c2 = route.options).scripts) == null ? void 0 : _d2.call(_c2, assetContext),
996
+ (_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, assetContext)
997
+ ]).then(([headFnContent, scripts, headers]) => {
998
+ const meta = headFnContent == null ? void 0 : headFnContent.meta;
999
+ const links = headFnContent == null ? void 0 : headFnContent.links;
1000
+ const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
1001
+ const styles = headFnContent == null ? void 0 : headFnContent.styles;
1002
+ return {
1003
+ meta,
1004
+ links,
1005
+ headScripts,
1006
+ headers,
1007
+ scripts,
1008
+ styles
1009
+ };
1010
+ });
1009
1011
  };
1010
1012
  const potentialPendingMinPromise = async () => {
1011
1013
  const latestMatch = this.getMatch(matchId);
@@ -1016,11 +1018,14 @@ class RouterCore {
1016
1018
  const prevMatch = this.getMatch(matchId);
1017
1019
  if (shouldSkipLoader(matchId)) {
1018
1020
  if (this.isServer) {
1019
- const head = await executeHead();
1020
- updateMatch(matchId, (prev) => ({
1021
- ...prev,
1022
- ...head
1023
- }));
1021
+ const headResult = executeHead();
1022
+ if (headResult) {
1023
+ const head = await headResult;
1024
+ updateMatch(matchId, (prev) => ({
1025
+ ...prev,
1026
+ ...head
1027
+ }));
1028
+ }
1024
1029
  return this.getMatch(matchId);
1025
1030
  }
1026
1031
  } else if (prevMatch._nonReactive.loaderPromise) {
@@ -1089,7 +1094,8 @@ class RouterCore {
1089
1094
  loaderData
1090
1095
  }));
1091
1096
  await route._lazyPromise;
1092
- const head = await executeHead();
1097
+ const headResult = executeHead();
1098
+ const head = headResult ? await headResult : void 0;
1093
1099
  await potentialPendingMinPromise();
1094
1100
  await route._componentsPromise;
1095
1101
  updateMatch(matchId, (prev) => ({
@@ -1113,7 +1119,8 @@ class RouterCore {
1113
1119
  onErrorError
1114
1120
  );
1115
1121
  }
1116
- const head = await executeHead();
1122
+ const headResult = executeHead();
1123
+ const head = headResult ? await headResult : void 0;
1117
1124
  updateMatch(matchId, (prev) => ({
1118
1125
  ...prev,
1119
1126
  error,
@@ -1123,15 +1130,19 @@ class RouterCore {
1123
1130
  }));
1124
1131
  }
1125
1132
  } catch (err) {
1126
- const head = await executeHead();
1127
- updateMatch(matchId, (prev) => {
1128
- prev._nonReactive.loaderPromise = void 0;
1129
- return {
1130
- ...prev,
1131
- ...head
1132
- };
1133
- });
1134
- handleRedirectAndNotFound(this.getMatch(matchId), err);
1133
+ const match = this.getMatch(matchId);
1134
+ if (match) {
1135
+ const headResult = executeHead();
1136
+ if (headResult) {
1137
+ const head = await headResult;
1138
+ updateMatch(matchId, (prev) => ({
1139
+ ...prev,
1140
+ ...head
1141
+ }));
1142
+ }
1143
+ match._nonReactive.loaderPromise = void 0;
1144
+ }
1145
+ handleRedirectAndNotFound(match, err);
1135
1146
  }
1136
1147
  };
1137
1148
  const { status, invalid } = this.getMatch(matchId);
@@ -1156,11 +1167,14 @@ class RouterCore {
1156
1167
  } else if (status !== "success" || loaderShouldRunAsync && sync) {
1157
1168
  await runLoader();
1158
1169
  } else {
1159
- const head = await executeHead();
1160
- updateMatch(matchId, (prev) => ({
1161
- ...prev,
1162
- ...head
1163
- }));
1170
+ const headResult = executeHead();
1171
+ if (headResult) {
1172
+ const head = await headResult;
1173
+ updateMatch(matchId, (prev) => ({
1174
+ ...prev,
1175
+ ...head
1176
+ }));
1177
+ }
1164
1178
  }
1165
1179
  }
1166
1180
  if (!loaderIsRunningAsync) {
@@ -1389,9 +1403,7 @@ class RouterCore {
1389
1403
  }
1390
1404
  return match;
1391
1405
  };
1392
- this._handleNotFound = (matches, err, {
1393
- updateMatch = this.updateMatch
1394
- } = {}) => {
1406
+ this._handleNotFound = (matches, err, updateMatch = this.updateMatch) => {
1395
1407
  var _a;
1396
1408
  const routeCursor = this.routesById[err.routeId ?? ""] ?? this.routeTree;
1397
1409
  const matchesByRouteId = {};
@@ -1418,9 +1430,7 @@ class RouterCore {
1418
1430
  }));
1419
1431
  if (err.routerCode === "BEFORE_LOAD" && routeCursor.parentRoute) {
1420
1432
  err.routeId = routeCursor.parentRoute.id;
1421
- this._handleNotFound(matches, err, {
1422
- updateMatch
1423
- });
1433
+ this._handleNotFound(matches, err, updateMatch);
1424
1434
  }
1425
1435
  };
1426
1436
  this.hasNotFoundMatch = () => {