@tanstack/router-core 1.131.7 → 1.131.12

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.
@@ -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;
@@ -735,20 +735,22 @@ class RouterCore {
735
735
  }
736
736
  }
737
737
  }
738
- (_a = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a.resolve();
739
- (_b = match._nonReactive.loaderPromise) == null ? void 0 : _b.resolve();
740
- match._nonReactive.beforeLoadPromise = void 0;
741
- match._nonReactive.loaderPromise = void 0;
742
- updateMatch(match.id, (prev) => ({
743
- ...prev,
744
- status: isRedirect(err) ? "redirected" : isNotFound(err) ? "notFound" : "error",
745
- isFetching: false,
746
- error: err
747
- }));
748
- if (!err.routeId) {
749
- err.routeId = match.routeId;
738
+ if (match) {
739
+ (_a = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a.resolve();
740
+ (_b = match._nonReactive.loaderPromise) == null ? void 0 : _b.resolve();
741
+ match._nonReactive.beforeLoadPromise = void 0;
742
+ match._nonReactive.loaderPromise = void 0;
743
+ updateMatch(match.id, (prev) => ({
744
+ ...prev,
745
+ status: isRedirect(err) ? "redirected" : isNotFound(err) ? "notFound" : "error",
746
+ isFetching: false,
747
+ error: err
748
+ }));
749
+ if (!err.routeId) {
750
+ err.routeId = match.routeId;
751
+ }
752
+ (_c = match._nonReactive.loadPromise) == null ? void 0 : _c.resolve();
750
753
  }
751
- (_c = match._nonReactive.loadPromise) == null ? void 0 : _c.resolve();
752
754
  if (isRedirect(err)) {
753
755
  rendered = true;
754
756
  err.options._fromLocation = location;
@@ -979,33 +981,39 @@ class RouterCore {
979
981
  let loaderShouldRunAsync = false;
980
982
  let loaderIsRunningAsync = false;
981
983
  const route = this.looseRoutesById[routeId];
982
- const executeHead = async () => {
984
+ const executeHead = () => {
983
985
  var _a3, _b3, _c2, _d2, _e, _f;
984
986
  const match = this.getMatch(matchId);
985
987
  if (!match) {
986
988
  return;
987
989
  }
990
+ if (!route.options.head && !route.options.scripts && !route.options.headers) {
991
+ return;
992
+ }
988
993
  const assetContext = {
989
994
  matches,
990
995
  match,
991
996
  params: match.params,
992
997
  loaderData: match.loaderData
993
998
  };
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
- };
999
+ return Promise.all([
1000
+ (_b3 = (_a3 = route.options).head) == null ? void 0 : _b3.call(_a3, assetContext),
1001
+ (_d2 = (_c2 = route.options).scripts) == null ? void 0 : _d2.call(_c2, assetContext),
1002
+ (_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, assetContext)
1003
+ ]).then(([headFnContent, scripts, headers]) => {
1004
+ const meta = headFnContent == null ? void 0 : headFnContent.meta;
1005
+ const links = headFnContent == null ? void 0 : headFnContent.links;
1006
+ const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
1007
+ const styles = headFnContent == null ? void 0 : headFnContent.styles;
1008
+ return {
1009
+ meta,
1010
+ links,
1011
+ headScripts,
1012
+ headers,
1013
+ scripts,
1014
+ styles
1015
+ };
1016
+ });
1009
1017
  };
1010
1018
  const potentialPendingMinPromise = async () => {
1011
1019
  const latestMatch = this.getMatch(matchId);
@@ -1016,11 +1024,14 @@ class RouterCore {
1016
1024
  const prevMatch = this.getMatch(matchId);
1017
1025
  if (shouldSkipLoader(matchId)) {
1018
1026
  if (this.isServer) {
1019
- const head = await executeHead();
1020
- updateMatch(matchId, (prev) => ({
1021
- ...prev,
1022
- ...head
1023
- }));
1027
+ const headResult = executeHead();
1028
+ if (headResult) {
1029
+ const head = await headResult;
1030
+ updateMatch(matchId, (prev) => ({
1031
+ ...prev,
1032
+ ...head
1033
+ }));
1034
+ }
1024
1035
  return this.getMatch(matchId);
1025
1036
  }
1026
1037
  } else if (prevMatch._nonReactive.loaderPromise) {
@@ -1089,7 +1100,8 @@ class RouterCore {
1089
1100
  loaderData
1090
1101
  }));
1091
1102
  await route._lazyPromise;
1092
- const head = await executeHead();
1103
+ const headResult = executeHead();
1104
+ const head = headResult ? await headResult : void 0;
1093
1105
  await potentialPendingMinPromise();
1094
1106
  await route._componentsPromise;
1095
1107
  updateMatch(matchId, (prev) => ({
@@ -1113,7 +1125,8 @@ class RouterCore {
1113
1125
  onErrorError
1114
1126
  );
1115
1127
  }
1116
- const head = await executeHead();
1128
+ const headResult = executeHead();
1129
+ const head = headResult ? await headResult : void 0;
1117
1130
  updateMatch(matchId, (prev) => ({
1118
1131
  ...prev,
1119
1132
  error,
@@ -1123,15 +1136,19 @@ class RouterCore {
1123
1136
  }));
1124
1137
  }
1125
1138
  } 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);
1139
+ const match = this.getMatch(matchId);
1140
+ if (match) {
1141
+ const headResult = executeHead();
1142
+ if (headResult) {
1143
+ const head = await headResult;
1144
+ updateMatch(matchId, (prev) => ({
1145
+ ...prev,
1146
+ ...head
1147
+ }));
1148
+ }
1149
+ match._nonReactive.loaderPromise = void 0;
1150
+ }
1151
+ handleRedirectAndNotFound(match, err);
1135
1152
  }
1136
1153
  };
1137
1154
  const { status, invalid } = this.getMatch(matchId);
@@ -1156,11 +1173,14 @@ class RouterCore {
1156
1173
  } else if (status !== "success" || loaderShouldRunAsync && sync) {
1157
1174
  await runLoader();
1158
1175
  } else {
1159
- const head = await executeHead();
1160
- updateMatch(matchId, (prev) => ({
1161
- ...prev,
1162
- ...head
1163
- }));
1176
+ const headResult = executeHead();
1177
+ if (headResult) {
1178
+ const head = await headResult;
1179
+ updateMatch(matchId, (prev) => ({
1180
+ ...prev,
1181
+ ...head
1182
+ }));
1183
+ }
1164
1184
  }
1165
1185
  }
1166
1186
  if (!loaderIsRunningAsync) {