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