@tanstack/router-core 1.131.5 → 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;
@@ -234,7 +234,7 @@ class RouterCore {
234
234
  _buildLocation: true
235
235
  });
236
236
  const lastMatch = last(allCurrentLocationMatches);
237
- let fromPath = lastMatch.fullPath;
237
+ let fromPath = this.resolvePathWithBase(lastMatch.fullPath, ".");
238
238
  const toPath = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, ".");
239
239
  const routeIsChanging = !!dest.to && !comparePaths(dest.to.toString(), fromPath) && !comparePaths(toPath, fromPath);
240
240
  if (dest.unsafeRelative === "path") {
@@ -257,6 +257,7 @@ class RouterCore {
257
257
  }
258
258
  }
259
259
  }
260
+ fromPath = this.resolvePathWithBase(fromPath, ".");
260
261
  const fromSearch = lastMatch.search;
261
262
  const fromParams = { ...lastMatch.params };
262
263
  const nextTo = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, ".");
@@ -734,20 +735,22 @@ class RouterCore {
734
735
  }
735
736
  }
736
737
  }
737
- (_a = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a.resolve();
738
- (_b = match._nonReactive.loaderPromise) == null ? void 0 : _b.resolve();
739
- match._nonReactive.beforeLoadPromise = void 0;
740
- match._nonReactive.loaderPromise = void 0;
741
- updateMatch(match.id, (prev) => ({
742
- ...prev,
743
- status: isRedirect(err) ? "redirected" : isNotFound(err) ? "notFound" : "error",
744
- isFetching: false,
745
- error: err
746
- }));
747
- if (!err.routeId) {
748
- 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();
749
753
  }
750
- (_c = match._nonReactive.loadPromise) == null ? void 0 : _c.resolve();
751
754
  if (isRedirect(err)) {
752
755
  rendered = true;
753
756
  err.options._fromLocation = location;
@@ -978,33 +981,39 @@ class RouterCore {
978
981
  let loaderShouldRunAsync = false;
979
982
  let loaderIsRunningAsync = false;
980
983
  const route = this.looseRoutesById[routeId];
981
- const executeHead = async () => {
984
+ const executeHead = () => {
982
985
  var _a3, _b3, _c2, _d2, _e, _f;
983
986
  const match = this.getMatch(matchId);
984
987
  if (!match) {
985
988
  return;
986
989
  }
990
+ if (!route.options.head && !route.options.scripts && !route.options.headers) {
991
+ return;
992
+ }
987
993
  const assetContext = {
988
994
  matches,
989
995
  match,
990
996
  params: match.params,
991
997
  loaderData: match.loaderData
992
998
  };
993
- const headFnContent = await ((_b3 = (_a3 = route.options).head) == null ? void 0 : _b3.call(_a3, assetContext));
994
- const meta = headFnContent == null ? void 0 : headFnContent.meta;
995
- const links = headFnContent == null ? void 0 : headFnContent.links;
996
- const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
997
- const styles = headFnContent == null ? void 0 : headFnContent.styles;
998
- const scripts = await ((_d2 = (_c2 = route.options).scripts) == null ? void 0 : _d2.call(_c2, assetContext));
999
- const headers = await ((_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, assetContext));
1000
- return {
1001
- meta,
1002
- links,
1003
- headScripts,
1004
- headers,
1005
- scripts,
1006
- styles
1007
- };
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
+ });
1008
1017
  };
1009
1018
  const potentialPendingMinPromise = async () => {
1010
1019
  const latestMatch = this.getMatch(matchId);
@@ -1015,11 +1024,14 @@ class RouterCore {
1015
1024
  const prevMatch = this.getMatch(matchId);
1016
1025
  if (shouldSkipLoader(matchId)) {
1017
1026
  if (this.isServer) {
1018
- const head = await executeHead();
1019
- updateMatch(matchId, (prev) => ({
1020
- ...prev,
1021
- ...head
1022
- }));
1027
+ const headResult = executeHead();
1028
+ if (headResult) {
1029
+ const head = await headResult;
1030
+ updateMatch(matchId, (prev) => ({
1031
+ ...prev,
1032
+ ...head
1033
+ }));
1034
+ }
1023
1035
  return this.getMatch(matchId);
1024
1036
  }
1025
1037
  } else if (prevMatch._nonReactive.loaderPromise) {
@@ -1088,7 +1100,8 @@ class RouterCore {
1088
1100
  loaderData
1089
1101
  }));
1090
1102
  await route._lazyPromise;
1091
- const head = await executeHead();
1103
+ const headResult = executeHead();
1104
+ const head = headResult ? await headResult : void 0;
1092
1105
  await potentialPendingMinPromise();
1093
1106
  await route._componentsPromise;
1094
1107
  updateMatch(matchId, (prev) => ({
@@ -1112,7 +1125,8 @@ class RouterCore {
1112
1125
  onErrorError
1113
1126
  );
1114
1127
  }
1115
- const head = await executeHead();
1128
+ const headResult = executeHead();
1129
+ const head = headResult ? await headResult : void 0;
1116
1130
  updateMatch(matchId, (prev) => ({
1117
1131
  ...prev,
1118
1132
  error,
@@ -1122,15 +1136,19 @@ class RouterCore {
1122
1136
  }));
1123
1137
  }
1124
1138
  } catch (err) {
1125
- const head = await executeHead();
1126
- updateMatch(matchId, (prev) => {
1127
- prev._nonReactive.loaderPromise = void 0;
1128
- return {
1129
- ...prev,
1130
- ...head
1131
- };
1132
- });
1133
- 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);
1134
1152
  }
1135
1153
  };
1136
1154
  const { status, invalid } = this.getMatch(matchId);
@@ -1155,11 +1173,14 @@ class RouterCore {
1155
1173
  } else if (status !== "success" || loaderShouldRunAsync && sync) {
1156
1174
  await runLoader();
1157
1175
  } else {
1158
- const head = await executeHead();
1159
- updateMatch(matchId, (prev) => ({
1160
- ...prev,
1161
- ...head
1162
- }));
1176
+ const headResult = executeHead();
1177
+ if (headResult) {
1178
+ const head = await headResult;
1179
+ updateMatch(matchId, (prev) => ({
1180
+ ...prev,
1181
+ ...head
1182
+ }));
1183
+ }
1163
1184
  }
1164
1185
  }
1165
1186
  if (!loaderIsRunningAsync) {