@tanstack/router-core 1.171.24 → 1.171.25

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.
@@ -37,10 +37,17 @@ declare const ERROR = 1;
37
37
  declare const NOT_FOUND = 2;
38
38
  declare const REDIRECTED = 3;
39
39
  declare const CANCELED = 4;
40
- type LoaderOutcome = [kind: typeof SUCCESS, data: unknown] | [kind: typeof ERROR, error: unknown] | [kind: typeof NOT_FOUND, error: NotFoundError] | [kind: typeof REDIRECTED, redirect: AnyRedirect] | [kind: typeof CANCELED];
40
+ type RedirectOutcome = [
41
+ kind: typeof REDIRECTED,
42
+ redirect: AnyRedirect,
43
+ location?: ParsedLocation
44
+ ];
45
+ type NonRedirectOutcome = [kind: typeof SUCCESS, data: unknown] | [kind: typeof ERROR, error: unknown] | [kind: typeof NOT_FOUND, error: NotFoundError] | [kind: typeof CANCELED];
46
+ type RawLoaderOutcome = NonRedirectOutcome | [kind: typeof REDIRECTED, redirect: AnyRedirect];
47
+ type LoaderOutcome = NonRedirectOutcome | RedirectOutcome;
41
48
  type IndexedOutcome = [index: number, outcome: LoaderOutcome, boundary?: number];
42
49
  export type LoaderFlight = [
43
- outcome: Promise<LoaderOutcome>,
50
+ outcome: Promise<RawLoaderOutcome>,
44
51
  controller: AbortController,
45
52
  leases: number
46
53
  ];
@@ -66,31 +73,25 @@ export type LoadTransaction = [
66
73
  startedAt: number,
67
74
  done: Promise<void>,
68
75
  /**
69
- * Dev-only HMR refresh mode. Presence is the mode flag; a refresh always
70
- * carries the presentation it started from and its optional hydration
71
- * handoff. While a publication awaits acknowledgement, its rollback lives
72
- * with the transaction that owns the publication.
76
+ * Dev-only HMR refresh mode. Presence forces successor rematerialization
77
+ * until this publication is acknowledged. The optional hydration handoff is
78
+ * retired when the refresh publishes.
73
79
  */
74
- refresh?: [
75
- presentation: Array<AnyRouteMatch>,
76
- handoff: NonNullable<AnyRouter['_handoff']> | undefined,
77
- rollback?: () => boolean
78
- ]
80
+ refresh?: [handoff: NonNullable<AnyRouter['_handoff']> | undefined]
79
81
  ];
80
82
  export type PendingSession = [
81
- owner: LoadTransaction,
82
- boundary: number,
83
+ generation: LoadTransaction,
84
+ boundaryId: string,
83
85
  /** Pending reveal time until acknowledged, then minimum-visible-until time. */
84
86
  deadline: number,
85
- timer?: ReturnType<typeof setTimeout>,
86
- ack?: Promise<boolean>,
87
+ revealTimer?: ReturnType<typeof setTimeout>,
88
+ ack?: Promise<boolean> | true,
87
89
  component?: unknown
88
90
  ];
89
91
  type CoordinatorRouter = AnyRouter & {
90
92
  /** Active speculative lanes retained for cancellation, invalidation, and cache clearing. */
91
93
  _preloads?: Map<AbortController, Array<AnyRouteMatch>>;
92
94
  _refreshNextLoad?: boolean;
93
- _cancelTransition?: () => void;
94
95
  };
95
96
  type BackgroundLoaderTask = [
96
97
  index: number,
@@ -100,14 +101,13 @@ type BackgroundLoaderTask = [
100
101
  ];
101
102
  export declare function waitFor<T>(value: T | PromiseLike<T>, signal: AbortSignal): Promise<T>;
102
103
  export declare function getRoute(router: AnyRouter, match: WorkMatch): AnyRoute;
103
- export declare function navigateFrom(router: AnyRouter, location: ParsedLocation): (opts: any) => Promise<void>;
104
104
  export declare function cacheLoaderMatch(router: CoordinatorRouter, match: SettledMatch, planned: AnyRouteMatch | undefined): void;
105
105
  export declare function projectLane(router: AnyRouter, lane: ReducedLane, signal: AbortSignal, start?: number, end?: number): Promise<ProjectedLane>;
106
106
  export declare function loadClientRoute(router: CoordinatorRouter, opts?: {
107
107
  sync?: boolean;
108
108
  }): Promise<void>;
109
109
  export declare function refreshClientRoute(router: CoordinatorRouter): Promise<void>;
110
- export declare function preloadClientRoute(router: CoordinatorRouter, opts: any, redirects?: number): Promise<Array<AnyRouteMatch> | undefined>;
110
+ export declare function preloadClientRoute(router: CoordinatorRouter, opts: any, redirects?: number, builtLocation?: ParsedLocation): Promise<Array<AnyRouteMatch> | undefined>;
111
111
  declare global {
112
112
  interface Window {
113
113
  [GLOBAL_TSR]?: TsrSsrGlobal;
@@ -19,15 +19,30 @@ function normalize(value, rejected) {
19
19
  if (rejected && typeof value?.then === "function") value = new Error("A Promise was thrown", { cause: value });
20
20
  return rejected ? [ERROR, value] : [SUCCESS, value];
21
21
  }
22
- function normalizeError(route, cause) {
22
+ function normalizeError(router, lane, route, cause, signal, notify = true) {
23
+ signal?.throwIfAborted();
23
24
  let outcome = normalize(cause, true);
24
- if (outcome[0] !== ERROR) return outcome;
25
+ if (outcome[0] !== ERROR) return materializeRedirect(router, lane, route, outcome, signal, notify);
25
26
  try {
26
27
  route.options.onError?.(outcome[1]);
27
28
  } catch (onErrorCause) {
28
29
  outcome = normalize(onErrorCause, true);
29
30
  }
30
- return outcome;
31
+ signal?.throwIfAborted();
32
+ return materializeRedirect(router, lane, route, outcome, signal, notify);
33
+ }
34
+ function materializeRedirect(router, lane, route, outcome, signal, notify = true) {
35
+ if (outcome[0] !== REDIRECTED) return outcome;
36
+ signal?.throwIfAborted();
37
+ try {
38
+ outcome[1].options._fromLocation = lane.location;
39
+ router.resolveRedirect(outcome[1]);
40
+ signal?.throwIfAborted();
41
+ return outcome;
42
+ } catch (cause) {
43
+ signal?.throwIfAborted();
44
+ return notify ? normalizeError(router, lane, route, cause, signal, false) : [ERROR, cause];
45
+ }
31
46
  }
32
47
  function maybe(value, cause) {
33
48
  if (cause !== void 0) return {
@@ -96,7 +111,7 @@ async function contextualize(router, lane, signal) {
96
111
  match.ssr = await resolveSsr(router, lane, index);
97
112
  } catch (cause) {
98
113
  signal?.throwIfAborted();
99
- failure = [index, stampNotFound(match, normalizeError(route, cause))];
114
+ failure = [index, stampNotFound(match, normalizeError(router, lane, route, cause, signal))];
100
115
  end = index;
101
116
  }
102
117
  signal?.throwIfAborted();
@@ -128,7 +143,7 @@ async function contextualize(router, lane, signal) {
128
143
  match.context = context;
129
144
  } catch (cause) {
130
145
  signal?.throwIfAborted();
131
- if (!failure) failure = [index, stampNotFound(match, normalizeError(route, cause))];
146
+ if (!failure) failure = [index, stampNotFound(match, normalizeError(router, lane, route, cause, signal))];
132
147
  end = index;
133
148
  break;
134
149
  }
@@ -136,7 +151,7 @@ async function contextualize(router, lane, signal) {
136
151
  if (failure) break;
137
152
  const validationError = match.paramsError ?? match.searchError;
138
153
  if (validationError !== void 0) {
139
- failure = [index, stampNotFound(match, normalizeError(route, validationError))];
154
+ failure = [index, stampNotFound(match, normalizeError(router, lane, route, validationError, signal))];
140
155
  end = index;
141
156
  break;
142
157
  }
@@ -163,7 +178,7 @@ async function contextualize(router, lane, signal) {
163
178
  try {
164
179
  const beforeLoadContext = await route.options.beforeLoad(options);
165
180
  signal?.throwIfAborted();
166
- const outcome = stampNotFound(match, normalize(beforeLoadContext, false));
181
+ const outcome = stampNotFound(match, materializeRedirect(router, lane, route, normalize(beforeLoadContext, false), signal));
167
182
  if (outcome[0] !== SUCCESS) {
168
183
  failure = [index, outcome];
169
184
  end = index;
@@ -177,7 +192,7 @@ async function contextualize(router, lane, signal) {
177
192
  parentContext = match.context;
178
193
  } catch (cause) {
179
194
  signal?.throwIfAborted();
180
- failure = [index, stampNotFound(match, normalizeError(route, cause))];
195
+ failure = [index, stampNotFound(match, normalizeError(router, lane, route, cause, signal))];
181
196
  end = index;
182
197
  break;
183
198
  }
@@ -214,8 +229,9 @@ function createLoaderTask(router, lane, index, tasks, signal) {
214
229
  const loader = typeof routeLoader === "function" ? routeLoader : routeLoader?.handler;
215
230
  if (!loader) outcome = Promise.resolve([SUCCESS, void 0]);
216
231
  else outcome = Promise.resolve().then(() => loader(getLoaderContext(router, lane, match, route, index, tasks))).then((result) => normalize(result, false), (cause) => normalize(cause, true)).then((result) => {
217
- if (result[0] !== REDIRECTED && (signal?.aborted || match.abortController.signal.reason === lane)) return [SKIPPED];
218
- if (result[0] === ERROR) result = normalizeError(route, result[1]);
232
+ if (signal?.aborted || match.abortController.signal.reason === lane) return [SKIPPED];
233
+ if (result[0] === ERROR) result = normalizeError(router, lane, route, result[1], signal);
234
+ else result = materializeRedirect(router, lane, route, result, signal);
219
235
  return stampNotFound(match, result);
220
236
  });
221
237
  }
@@ -248,9 +264,9 @@ async function getNotFoundBoundary(router, matches, indexed, signal, fallback =
248
264
  if (index < 0) index = 0;
249
265
  for (let candidate = index; candidate >= 0; candidate--) {
250
266
  const route = getRoute(router, matches[candidate]);
251
- const loading = require_load_client.loadRouteChunk(route, false);
252
- if (loading) try {
253
- await loading;
267
+ try {
268
+ const loading = require_load_client.loadRouteChunk(route, false);
269
+ if (loading) await loading;
254
270
  } catch {
255
271
  signal?.throwIfAborted();
256
272
  }
@@ -262,13 +278,6 @@ async function getNotFoundBoundary(router, matches, indexed, signal, fallback =
262
278
  function abortMatches(matches, start = 0, reason) {
263
279
  for (let index = start; index < matches.length; index++) matches[index].abortController.abort(reason);
264
280
  }
265
- function resolveServerRedirect(router, location, value) {
266
- value.options._fromLocation = location;
267
- return {
268
- type: "redirect",
269
- redirect: router.resolveRedirect(value)
270
- };
271
- }
272
281
  async function applyFailure(router, lane, indexed, signal) {
273
282
  if (!indexed) {
274
283
  const boundary = lane.matches.findIndex((match) => match._notFound);
@@ -330,14 +339,14 @@ async function loadNormalChunks(router, lane, end, signal) {
330
339
  signal?.throwIfAborted();
331
340
  }, (cause) => {
332
341
  signal?.throwIfAborted();
333
- return [index, stampNotFound(match, normalizeError(route, cause))];
342
+ return [index, stampNotFound(match, normalizeError(router, lane, route, cause, signal))];
334
343
  });
335
344
  chunk.catch(() => {});
336
345
  chunks.push(chunk);
337
346
  }
338
347
  } catch (cause) {
339
348
  signal?.throwIfAborted();
340
- chunks.push([index, stampNotFound(match, normalizeError(route, cause))]);
349
+ chunks.push([index, stampNotFound(match, normalizeError(router, lane, route, cause, signal))]);
341
350
  }
342
351
  }
343
352
  for (const chunk of chunks) {
@@ -449,7 +458,10 @@ async function executeServerLane(router, location, matchedMatches, signal) {
449
458
  signal?.throwIfAborted();
450
459
  if (control?.[1][0] === REDIRECTED) {
451
460
  abortMatches(lane.matches, 0, lane);
452
- return resolveServerRedirect(router, location, control[1][1]);
461
+ return {
462
+ type: "redirect",
463
+ redirect: control[1][1]
464
+ };
453
465
  }
454
466
  let failure = lane.failure ?? loaderFailure;
455
467
  const plannedBoundary = lane.matches.findIndex((match) => match._notFound);
@@ -472,7 +484,10 @@ async function executeServerLane(router, location, matchedMatches, signal) {
472
484
  if (requiredFailure) {
473
485
  if (requiredFailure[1][0] === REDIRECTED) {
474
486
  abortMatches(lane.matches);
475
- return resolveServerRedirect(router, location, requiredFailure[1][1]);
487
+ return {
488
+ type: "redirect",
489
+ redirect: requiredFailure[1][1]
490
+ };
476
491
  }
477
492
  failure = requiredFailure;
478
493
  }
@@ -519,13 +534,7 @@ async function loadServerRoute(router, opts) {
519
534
  state: true,
520
535
  _includeValidateSearch: true
521
536
  });
522
- if (next.publicHref !== canonical.publicHref) {
523
- const href = canonical.publicHref || "/";
524
- throw canonical.external ? require_redirect.redirect({ href }) : require_redirect.redirect({
525
- href,
526
- _builtLocation: canonical
527
- });
528
- }
537
+ if (next.publicHref !== canonical.publicHref) throw require_redirect.redirect({ href: canonical.publicHref || "/" });
529
538
  const changeInfo = require_router.getLocationChangeInfo(next, router.stores.resolvedLocation.get());
530
539
  router.emit({
531
540
  type: "onBeforeNavigate",
@@ -541,7 +550,11 @@ async function loadServerRoute(router, opts) {
541
550
  } catch (cause) {
542
551
  opts?._signal?.throwIfAborted();
543
552
  if (!require_redirect.isRedirect(cause)) throw cause;
544
- result = resolveServerRedirect(router, next, cause);
553
+ cause.options._fromLocation = next;
554
+ result = {
555
+ type: "redirect",
556
+ redirect: router.resolveRedirect(cause)
557
+ };
545
558
  }
546
559
  router._serverResult = result;
547
560
  router.batch(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"load-server.cjs","names":[],"sources":["../../src/load-server.ts"],"sourcesContent":["// Keep this filename free of a secondary extension so declaration generation\n// can rewrite relative imports for both ESM and CJS.\nimport { isNotFound } from './not-found'\nimport { isRedirect, redirect } from './redirect'\nimport { rootRouteId } from './root'\nimport { loadRouteChunk } from './load-client'\nimport { waitForReason } from './await-signal'\nimport { getLocationChangeInfo, runRouteLifecycle } from './router'\nimport type { ParsedLocation } from './location'\nimport type { AnyRouteMatch } from './Matches'\nimport type { NotFoundError } from './not-found'\nimport type {\n AnyRoute,\n BeforeLoadContextOptions,\n LoaderFnContext,\n RouteContextOptions,\n SsrContextOptions,\n} from './route'\nimport type { AnyRedirect } from './redirect'\nimport type { AnyRouter, SSROption } from './router'\n\ndeclare const serverLanePhase: unique symbol\n\ntype ServerLane<TPhase extends 'matched' | 'contextualized' | 'reduced'> = {\n readonly [serverLanePhase]: TPhase\n location: ParsedLocation\n matches: Array<AnyRouteMatch>\n}\n\ntype MatchedLane = ServerLane<'matched'>\n\ntype IndexedOutcome = [index: number, outcome: LoaderOutcome, boundary?: number]\n\ntype ContextualizedLane = ServerLane<'contextualized'> & {\n end: number\n failure?: IndexedOutcome\n}\n\ntype ReducedLane = ServerLane<'reduced'>\n\nconst SUCCESS = 0\nconst ERROR = 1\nconst NOT_FOUND = 2\nconst REDIRECTED = 3\nconst SKIPPED = 4\n\ntype LoaderOutcome =\n | [typeof SUCCESS, data: unknown]\n | [typeof ERROR, error: unknown]\n | [typeof NOT_FOUND, error: NotFoundError]\n | [typeof REDIRECTED, redirect: AnyRedirect]\n | [typeof SKIPPED]\n\ntype LoaderTask = {\n index: number\n outcome: Promise<LoaderOutcome>\n match: Promise<AnyRouteMatch>\n}\n\nexport type ServerLoadResult =\n | {\n type: 'render'\n status: 200 | 404 | 500\n matches: Array<AnyRouteMatch>\n }\n | { type: 'redirect'; redirect: AnyRedirect }\n\nfunction getRoute(router: AnyRouter, match: AnyRouteMatch): AnyRoute {\n return router.routesById[match.routeId]\n}\n\nfunction normalize(value: unknown, rejected: boolean): LoaderOutcome {\n if (isRedirect(value)) {\n return [REDIRECTED, value]\n }\n if (isNotFound(value)) {\n return [NOT_FOUND, value]\n }\n if (rejected && typeof (value as any)?.then === 'function') {\n value = new Error('A Promise was thrown', { cause: value })\n }\n return rejected ? [ERROR, value] : [SUCCESS, value]\n}\n\nfunction normalizeError(route: AnyRoute, cause: unknown): LoaderOutcome {\n let outcome = normalize(cause, true)\n if (outcome[0] !== ERROR) {\n return outcome\n }\n try {\n route.options.onError?.(outcome[1])\n } catch (onErrorCause) {\n outcome = normalize(onErrorCause, true)\n }\n return outcome\n}\n\nfunction maybe<TValue>(\n value: TValue,\n cause: unknown,\n): { status: 'success'; value: TValue } | { status: 'error'; error: unknown } {\n if (cause !== undefined) {\n return { status: 'error', error: cause }\n }\n return { status: 'success', value }\n}\n\nfunction navigateFrom(router: AnyRouter, location: ParsedLocation) {\n return (options: any) =>\n router.navigate({\n ...options,\n _fromLocation: location,\n })\n}\n\nfunction waitFor<T>(value: Promise<T>, signal?: AbortSignal): Promise<T> {\n return signal ? waitForReason(value, signal) : value\n}\n\nasync function resolveSsr(\n router: AnyRouter,\n lane: MatchedLane,\n index: number,\n): Promise<SSROption> {\n const match = lane.matches[index]!\n const route = getRoute(router, match)\n const parentSsr = lane.matches[index - 1]?.ssr\n\n if (router.isShell()) {\n return route.id === rootRouteId\n }\n if (parentSsr === false) {\n return false\n }\n\n const inherit = (value: SSROption): SSROption => {\n return value === true && parentSsr === 'data-only' ? 'data-only' : value\n }\n const defaultSsr = router.options.defaultSsr ?? true\n const inheritedDefault = inherit(defaultSsr)\n // A functional override can fail. Establish the inherited policy first so\n // the selected error boundary retains the route's actual renderability.\n match.ssr = inheritedDefault\n const option = route.options.ssr\n if (option === undefined) {\n return inheritedDefault\n }\n if (typeof option !== 'function') {\n return inherit(option)\n }\n\n const context: SsrContextOptions<any, any, any> = {\n search: maybe(match.search, match.searchError),\n params: maybe(match.params, match.paramsError),\n location: lane.location,\n matches: lane.matches.map((candidate) => ({\n index: candidate.index,\n pathname: candidate.pathname,\n fullPath: candidate.fullPath,\n staticData: candidate.staticData,\n id: candidate.id,\n routeId: candidate.routeId,\n search: maybe(candidate.search, candidate.searchError),\n params: maybe(candidate.params, candidate.paramsError),\n ssr: candidate.ssr,\n })),\n }\n return inherit((await option(context)) ?? defaultSsr)\n}\n\nfunction stampNotFound(\n match: AnyRouteMatch,\n outcome: LoaderOutcome,\n): LoaderOutcome {\n if (outcome[0] === NOT_FOUND && !outcome[1].routeId) {\n outcome[1].routeId = match.routeId\n }\n return outcome\n}\n\nasync function contextualize(\n router: AnyRouter,\n lane: MatchedLane,\n signal?: AbortSignal,\n): Promise<ContextualizedLane> {\n const globalBoundary = lane.matches.findIndex((match) => match._notFound)\n let end = globalBoundary < 0 ? lane.matches.length : globalBoundary + 1\n let failure: IndexedOutcome | undefined\n let parentContext: Record<string, unknown> = {\n ...(router.options.context ?? {}),\n }\n\n for (let index = 0; index < end; index++) {\n const match = lane.matches[index]!\n const route = getRoute(router, match)\n try {\n match.ssr = await resolveSsr(router, lane, index)\n } catch (cause) {\n signal?.throwIfAborted()\n failure = [index, stampNotFound(match, normalizeError(route, cause))]\n end = index\n }\n signal?.throwIfAborted()\n if (failure?.[1][0] === REDIRECTED) {\n break\n }\n\n match.__beforeLoadContext = undefined\n let context = parentContext\n try {\n let routeContext\n if (route.options.context) {\n const routeContextOptions: RouteContextOptions<\n any,\n any,\n any,\n any,\n any\n > = {\n deps: match.loaderDeps,\n params: match.params,\n context: parentContext,\n location: lane.location,\n navigate: navigateFrom(router, lane.location),\n buildLocation: router.buildLocation,\n cause: match.cause,\n abortController: match.abortController,\n preload: false,\n matches: lane.matches,\n routeId: route.id,\n }\n routeContext = route.options.context(routeContextOptions) ?? undefined\n }\n context = {\n ...parentContext,\n ...routeContext,\n }\n match.context = context\n } catch (cause) {\n signal?.throwIfAborted()\n if (!failure) {\n failure = [index, stampNotFound(match, normalizeError(route, cause))]\n }\n end = index\n break\n }\n signal?.throwIfAborted()\n if (failure) {\n break\n }\n const validationError = match.paramsError ?? match.searchError\n if (validationError !== undefined) {\n failure = [\n index,\n stampNotFound(match, normalizeError(route, validationError)),\n ]\n end = index\n break\n }\n signal?.throwIfAborted()\n\n if (match.ssr === false || !route.options.beforeLoad) {\n parentContext = context\n continue\n }\n\n const abortController = match.abortController\n const options: BeforeLoadContextOptions<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = {\n search: match.search,\n abortController,\n params: match.params,\n preload: false,\n context,\n location: lane.location,\n navigate: navigateFrom(router, lane.location),\n buildLocation: router.buildLocation,\n cause: match.cause,\n matches: lane.matches,\n routeId: route.id,\n ...router.options.additionalContext,\n }\n\n try {\n const beforeLoadContext = await route.options.beforeLoad(options)\n signal?.throwIfAborted()\n const outcome = stampNotFound(match, normalize(beforeLoadContext, false))\n if (outcome[0] !== SUCCESS) {\n failure = [index, outcome]\n end = index\n break\n }\n match.__beforeLoadContext = beforeLoadContext\n match.context = {\n ...context,\n ...beforeLoadContext,\n }\n parentContext = match.context\n } catch (cause) {\n signal?.throwIfAborted()\n failure = [index, stampNotFound(match, normalizeError(route, cause))]\n end = index\n break\n }\n }\n\n return {\n location: lane.location,\n matches: lane.matches,\n end,\n failure,\n } as ContextualizedLane\n}\n\nfunction getLoaderContext(\n router: AnyRouter,\n lane: ContextualizedLane,\n match: AnyRouteMatch,\n route: AnyRoute,\n index: number,\n tasks: Array<LoaderTask>,\n): LoaderFnContext {\n return {\n params: match.params,\n deps: match.loaderDeps,\n preload: false,\n parentMatchPromise: tasks[index - 1]?.match,\n abortController: match.abortController,\n context: match.context,\n location: lane.location,\n navigate: navigateFrom(router, lane.location),\n cause: match.cause,\n route,\n ...router.options.additionalContext,\n }\n}\n\nfunction createLoaderTask(\n router: AnyRouter,\n lane: ContextualizedLane,\n index: number,\n tasks: Array<LoaderTask>,\n signal?: AbortSignal,\n): LoaderTask {\n const match = lane.matches[index]!\n const route = getRoute(router, match)\n let outcome: Promise<LoaderOutcome>\n\n if (match.ssr === false) {\n outcome = Promise.resolve<LoaderOutcome>([SKIPPED])\n } else {\n const routeLoader = route.options.loader\n const loader =\n typeof routeLoader === 'function' ? routeLoader : routeLoader?.handler\n if (!loader) {\n outcome = Promise.resolve<LoaderOutcome>([SUCCESS, undefined])\n } else {\n outcome = Promise.resolve()\n .then(() =>\n loader(getLoaderContext(router, lane, match, route, index, tasks)),\n )\n .then(\n (result) => normalize(result, false),\n (cause) => normalize(cause, true),\n )\n .then((result): LoaderOutcome => {\n if (\n result[0] !== REDIRECTED &&\n (signal?.aborted || match.abortController.signal.reason === lane)\n ) {\n return [SKIPPED]\n }\n if (result[0] === ERROR) {\n result = normalizeError(route, result[1])\n }\n return stampNotFound(match, result)\n })\n }\n }\n\n const parentMatch = outcome.then((result) => {\n const snapshot = { ...match }\n if (result[0] === SUCCESS) {\n snapshot.loaderData = result[1]\n snapshot.status = 'success'\n snapshot.error = undefined\n snapshot.invalid = false\n snapshot.isFetching = false\n } else if (result[0] === ERROR) {\n snapshot.status = 'error'\n snapshot.error = result[1]\n } else if (result[0] === NOT_FOUND) {\n snapshot.status = 'notFound'\n snapshot.error = result[1]\n }\n return snapshot\n })\n\n return { index, outcome, match: parentMatch }\n}\n\nasync function getNotFoundBoundary(\n router: AnyRouter,\n matches: Array<AnyRouteMatch>,\n indexed: IndexedOutcome | undefined,\n signal?: AbortSignal,\n fallback = 0,\n): Promise<number> {\n const cause = indexed?.[1][1] as NotFoundError | undefined\n let index = cause?.routeId\n ? matches.findIndex((match) => match.routeId === cause.routeId)\n : (indexed?.[0] ?? matches.length - 1)\n if (index < 0) {\n index = 0\n }\n for (let candidate = index; candidate >= 0; candidate--) {\n const route = getRoute(router, matches[candidate]!)\n const loading = loadRouteChunk(route, false)\n if (loading) {\n try {\n await loading\n } catch {\n signal?.throwIfAborted()\n }\n }\n signal?.throwIfAborted()\n if (route.options.notFoundComponent) {\n return candidate\n }\n }\n return cause?.routeId ? index : fallback\n}\n\nfunction abortMatches(\n matches: Array<AnyRouteMatch>,\n start = 0,\n reason?: unknown,\n): void {\n for (let index = start; index < matches.length; index++) {\n matches[index]!.abortController.abort(reason)\n }\n}\n\nfunction resolveServerRedirect(\n router: AnyRouter,\n location: ParsedLocation,\n value: AnyRedirect,\n): ServerLoadResult {\n value.options._fromLocation = location\n return { type: 'redirect', redirect: router.resolveRedirect(value) }\n}\n\nasync function applyFailure(\n router: AnyRouter,\n lane: ContextualizedLane,\n indexed: IndexedOutcome | undefined,\n signal?: AbortSignal,\n): Promise<{ status: 200 | 404 | 500; boundary?: number; kind?: number }> {\n if (!indexed) {\n const boundary = lane.matches.findIndex((match) => match._notFound)\n if (boundary >= 0) {\n abortMatches(lane.matches, boundary + 1)\n return { status: 404, boundary, kind: NOT_FOUND }\n }\n return { status: 200 }\n }\n\n const [index, outcome] = indexed\n if (outcome[0] === ERROR) {\n const match = lane.matches[index]!\n match._notFound = undefined\n match.status = 'error'\n match.error = outcome[1]\n match.isFetching = false\n abortMatches(lane.matches, index + 1)\n return { status: 500, boundary: index, kind: ERROR }\n }\n\n const boundary =\n indexed[2] ??\n (await getNotFoundBoundary(router, lane.matches, indexed, signal))\n const match = lane.matches[boundary]!\n const cause = outcome[1] as NotFoundError\n cause.routeId = match.routeId\n match._notFound = undefined\n if (match.routeId === router.routeTree.id) {\n match.status = 'success'\n match._notFound = true\n match.error = cause\n } else {\n match.status = 'notFound'\n match.error = cause\n }\n match.isFetching = false\n abortMatches(lane.matches, boundary + 1)\n return { status: 404, boundary, kind: NOT_FOUND }\n}\n\nasync function loadNormalChunks(\n router: AnyRouter,\n lane: ContextualizedLane,\n end: number,\n signal?: AbortSignal,\n): Promise<IndexedOutcome | undefined> {\n const chunks: Array<IndexedOutcome | Promise<IndexedOutcome | undefined>> = []\n for (let index = 0; index < lane.matches.length; index++) {\n const match = lane.matches[index]!\n if (index >= end || match.ssr !== true || match.status !== 'success') {\n continue\n }\n const route = getRoute(router, match)\n try {\n const loading = loadRouteChunk(route)\n if (loading) {\n const chunk = loading.then(\n () => {\n signal?.throwIfAborted()\n return undefined\n },\n (cause) => {\n signal?.throwIfAborted()\n return [\n index,\n stampNotFound(match, normalizeError(route, cause)),\n ] as IndexedOutcome\n },\n )\n // Route-order reduction can return before later chunks settle.\n void chunk.catch(() => {})\n chunks.push(chunk)\n }\n } catch (cause) {\n signal?.throwIfAborted()\n chunks.push([index, stampNotFound(match, normalizeError(route, cause))])\n }\n }\n for (const chunk of chunks) {\n const indexed = Array.isArray(chunk) ? chunk : await chunk\n if (indexed) {\n return indexed\n }\n }\n return undefined\n}\n\nasync function projectLane(\n router: AnyRouter,\n lane: ReducedLane,\n signal?: AbortSignal,\n): Promise<void> {\n for (const match of lane.matches) {\n const routeOptions = getRoute(router, match).options\n if (routeOptions.head || routeOptions.scripts || routeOptions.headers) {\n const context = {\n ssr: router.options.ssr,\n matches: lane.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n try {\n const [head, scripts, headers] = await Promise.all([\n routeOptions.head?.(context),\n routeOptions.scripts?.(context),\n routeOptions.headers?.(context),\n ])\n signal?.throwIfAborted()\n match.meta = head?.meta\n match.links = head?.links\n match.headScripts = head?.scripts\n match.styles = head?.styles\n match.scripts = scripts\n match.headers = headers\n } catch (cause) {\n signal?.throwIfAborted()\n console.error(cause)\n }\n }\n if (match.ssr === false || match.status !== 'success' || match._notFound) {\n break\n }\n }\n}\n\nasync function executeServerLane(\n router: AnyRouter,\n location: ParsedLocation,\n matchedMatches: Array<AnyRouteMatch>,\n signal?: AbortSignal,\n): Promise<ServerLoadResult> {\n const matched = {\n location,\n matches: matchedMatches.map((match) => ({\n ...match,\n __beforeLoadContext: undefined,\n context: {},\n isFetching: false,\n abortController: new AbortController(),\n })),\n } as MatchedLane\n const abortLane = () => abortMatches(matched.matches, 0, signal?.reason)\n if (signal?.aborted) {\n abortLane()\n signal.throwIfAborted()\n }\n signal?.addEventListener('abort', abortLane, { once: true })\n\n try {\n const plannedGlobalBoundary = matched.matches.findIndex(\n (match) => match._notFound,\n )\n if (router.options.notFoundMode !== 'root' && plannedGlobalBoundary >= 0) {\n const boundary = await getNotFoundBoundary(\n router,\n matched.matches,\n undefined,\n signal,\n plannedGlobalBoundary,\n )\n if (boundary !== plannedGlobalBoundary) {\n matched.matches[plannedGlobalBoundary]!._notFound = undefined\n matched.matches[boundary]!._notFound = true\n }\n }\n const lane = await contextualize(router, matched, signal)\n signal?.throwIfAborted()\n\n let loaderEnd = lane.end\n if (lane.failure?.[1][0] === REDIRECTED) {\n loaderEnd = 0\n } else if (lane.failure?.[1][0] === NOT_FOUND) {\n lane.failure[2] = await getNotFoundBoundary(\n router,\n lane.matches,\n lane.failure,\n signal,\n )\n loaderEnd = Math.min(loaderEnd, lane.failure[2] + 1)\n }\n\n const tasks: Array<LoaderTask> = []\n for (let index = 0; index < loaderEnd; index++) {\n const task = createLoaderTask(router, lane, index, tasks, signal)\n tasks.push(task)\n }\n\n let loaderFailure: IndexedOutcome | undefined\n let control = lane.failure?.[1][0] === REDIRECTED ? lane.failure : undefined\n try {\n await Promise.all(\n tasks.map((task) =>\n task.outcome.then((loadedOutcome) => {\n const match = lane.matches[task.index]!\n const outcome = loadedOutcome\n if (outcome[0] === SUCCESS) {\n match.loaderData = outcome[1]\n match.status = 'success'\n match.error = undefined\n match.invalid = false\n match.isFetching = false\n match.updatedAt = Date.now()\n } else if (outcome[0] === REDIRECTED) {\n control = [task.index, outcome]\n throw control\n } else {\n // A selective-SSR skip must stay pending for hydration. Every\n // settled server attempt is otherwise renderable unless\n // reduction selects it as the lane's terminal failure.\n if (match.ssr !== false) {\n match.status = 'success'\n match.error = undefined\n match.invalid = true\n match.isFetching = false\n }\n if (!loaderFailure && outcome[0] !== SKIPPED) {\n loaderFailure = [task.index, outcome]\n }\n }\n }),\n ),\n )\n } catch (cause) {\n if (!Array.isArray(cause)) {\n throw cause\n }\n control = cause as IndexedOutcome\n }\n signal?.throwIfAborted()\n\n if (control?.[1][0] === REDIRECTED) {\n abortMatches(lane.matches, 0, lane)\n return resolveServerRedirect(router, location, control[1][1])\n }\n\n let failure = lane.failure ?? loaderFailure\n const plannedBoundary = lane.matches.findIndex((match) => match._notFound)\n let readinessEnd: number\n if (failure) {\n const outcomeEnd = (failure[2] ??=\n failure[1][0] === NOT_FOUND\n ? await getNotFoundBoundary(router, lane.matches, failure, signal)\n : failure[0])\n for (const task of tasks) {\n if (task.index >= outcomeEnd) {\n break\n }\n const outcome = await task.outcome\n // Presence means a loader previously succeeded, even with `undefined`.\n if (\n outcome[0] !== SUCCESS &&\n outcome[0] < REDIRECTED &&\n !('loaderData' in lane.matches[task.index]!)\n ) {\n failure = [task.index, outcome]\n failure[2] =\n outcome[0] === NOT_FOUND\n ? await getNotFoundBoundary(router, lane.matches, failure, signal)\n : task.index\n break\n }\n }\n readinessEnd = failure[2]\n } else {\n readinessEnd = plannedBoundary < 0 ? lane.matches.length : plannedBoundary\n }\n const requiredFailure = await loadNormalChunks(\n router,\n lane,\n readinessEnd,\n signal,\n )\n signal?.throwIfAborted()\n if (requiredFailure) {\n if (requiredFailure[1][0] === REDIRECTED) {\n abortMatches(lane.matches)\n return resolveServerRedirect(router, location, requiredFailure[1][1])\n }\n failure = requiredFailure\n }\n\n const terminal = await applyFailure(router, lane, failure, signal)\n if (terminal.boundary !== undefined) {\n const match = lane.matches[terminal.boundary]!\n if (match.ssr === true) {\n const route = getRoute(router, match)\n try {\n if (terminal.kind === ERROR) {\n await loadRouteChunk(route, 'errorComponent')\n } else if (match._notFound) {\n await Promise.all([\n loadRouteChunk(route),\n loadRouteChunk(route, 'notFoundComponent'),\n ])\n } else {\n await loadRouteChunk(route, 'notFoundComponent')\n }\n } catch {}\n signal?.throwIfAborted()\n }\n }\n\n signal?.throwIfAborted()\n await projectLane(\n router,\n {\n location: lane.location,\n matches: lane.matches,\n } as ReducedLane,\n signal,\n )\n signal?.throwIfAborted()\n router.serverSsr?.onCleanup(abortLane)\n return { type: 'render', status: terminal.status, matches: lane.matches }\n } finally {\n signal?.removeEventListener('abort', abortLane)\n }\n}\n\ntype ServerLoadOptions = NonNullable<Parameters<AnyRouter['load']>[0]> & {\n _signal?: AbortSignal\n}\n\nexport async function loadServerRoute(\n router: AnyRouter,\n opts?: ServerLoadOptions,\n): Promise<void> {\n router.updateLatestLocation()\n const next = router.latestLocation\n const previous = router._committed\n let result: ServerLoadResult\n try {\n const canonical = router.buildLocation({\n to: next.pathname,\n search: true,\n params: true,\n hash: true,\n state: true,\n _includeValidateSearch: true,\n })\n if (next.publicHref !== canonical.publicHref) {\n const href = canonical.publicHref || '/'\n throw canonical.external\n ? redirect({ href })\n : redirect({ href, _builtLocation: canonical })\n }\n\n const fromLocation = router.stores.resolvedLocation.get()\n const changeInfo = getLocationChangeInfo(next, fromLocation)\n router.emit({ type: 'onBeforeNavigate', ...changeInfo })\n router.emit({ type: 'onBeforeLoad', ...changeInfo })\n opts?._signal?.throwIfAborted()\n result = await waitFor(\n executeServerLane(router, next, router.matchRoutes(next), opts?._signal),\n opts?._signal,\n )\n opts?._signal?.throwIfAborted()\n } catch (cause) {\n opts?._signal?.throwIfAborted()\n if (!isRedirect(cause)) {\n throw cause\n }\n result = resolveServerRedirect(router, next, cause)\n }\n\n router._serverResult = result\n router.batch(() => {\n router.stores.location.set(next)\n router.stores.status.set('idle')\n if (result.type === 'render') {\n router.stores.setMatches(result.matches)\n router.stores.resolvedLocation.set(next)\n }\n })\n if (result.type === 'render') {\n router._committed = result.matches\n runRouteLifecycle(router, previous, result.matches)\n }\n router._commitPromise?.resolve()\n router._commitPromise = undefined\n}\n"],"mappings":";;;;;;;AAwCA,MAAM,UAAU;AAChB,MAAM,QAAQ;AACd,MAAM,YAAY;AAClB,MAAM,aAAa;AACnB,MAAM,UAAU;AAuBhB,SAAS,SAAS,QAAmB,OAAgC;CACnE,OAAO,OAAO,WAAW,MAAM;AACjC;AAEA,SAAS,UAAU,OAAgB,UAAkC;CACnE,IAAI,iBAAA,WAAW,KAAK,GAClB,OAAO,CAAC,YAAY,KAAK;CAE3B,IAAI,kBAAA,WAAW,KAAK,GAClB,OAAO,CAAC,WAAW,KAAK;CAE1B,IAAI,YAAY,OAAQ,OAAe,SAAS,YAC9C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AI,IAAI;EACzC;CACF,CAAC;CACD,IAAI,OAAO,SAAS,UAAU;EAC5B,OAAO,aAAa,OAAO;EAC3B,eAAA,kBAAkB,QAAQ,UAAU,OAAO,OAAO;CACpD;CACA,OAAO,gBAAgB,QAAQ;CAC/B,OAAO,iBAAiB,KAAA;AAC1B"}
1
+ {"version":3,"file":"load-server.cjs","names":[],"sources":["../../src/load-server.ts"],"sourcesContent":["// Keep this filename free of a secondary extension so declaration generation\n// can rewrite relative imports for both ESM and CJS.\nimport { isNotFound } from './not-found'\nimport { isRedirect, redirect } from './redirect'\nimport { rootRouteId } from './root'\nimport { loadRouteChunk } from './load-client'\nimport { waitForReason } from './await-signal'\nimport { getLocationChangeInfo, runRouteLifecycle } from './router'\nimport type { ParsedLocation } from './location'\nimport type { AnyRouteMatch } from './Matches'\nimport type { NotFoundError } from './not-found'\nimport type {\n AnyRoute,\n BeforeLoadContextOptions,\n LoaderFnContext,\n RouteContextOptions,\n SsrContextOptions,\n} from './route'\nimport type { AnyRedirect } from './redirect'\nimport type { AnyRouter, SSROption } from './router'\n\ndeclare const serverLanePhase: unique symbol\n\ntype ServerLane<TPhase extends 'matched' | 'contextualized' | 'reduced'> = {\n readonly [serverLanePhase]: TPhase\n location: ParsedLocation\n matches: Array<AnyRouteMatch>\n}\n\ntype MatchedLane = ServerLane<'matched'>\n\ntype IndexedOutcome = [index: number, outcome: LoaderOutcome, boundary?: number]\n\ntype ContextualizedLane = ServerLane<'contextualized'> & {\n end: number\n failure?: IndexedOutcome\n}\n\ntype ReducedLane = ServerLane<'reduced'>\n\nconst SUCCESS = 0\nconst ERROR = 1\nconst NOT_FOUND = 2\nconst REDIRECTED = 3\nconst SKIPPED = 4\n\ntype LoaderOutcome =\n | [typeof SUCCESS, data: unknown]\n | [typeof ERROR, error: unknown]\n | [typeof NOT_FOUND, error: NotFoundError]\n | [typeof REDIRECTED, redirect: AnyRedirect]\n | [typeof SKIPPED]\n\ntype LoaderTask = {\n index: number\n outcome: Promise<LoaderOutcome>\n match: Promise<AnyRouteMatch>\n}\n\nexport type ServerLoadResult =\n | {\n type: 'render'\n status: 200 | 404 | 500\n matches: Array<AnyRouteMatch>\n }\n | { type: 'redirect'; redirect: AnyRedirect }\n\nfunction getRoute(router: AnyRouter, match: AnyRouteMatch): AnyRoute {\n return router.routesById[match.routeId]\n}\n\nfunction normalize(value: unknown, rejected: boolean): LoaderOutcome {\n if (isRedirect(value)) {\n return [REDIRECTED, value]\n }\n if (isNotFound(value)) {\n return [NOT_FOUND, value]\n }\n if (rejected && typeof (value as any)?.then === 'function') {\n value = new Error('A Promise was thrown', { cause: value })\n }\n return rejected ? [ERROR, value] : [SUCCESS, value]\n}\n\nfunction normalizeError(\n router: AnyRouter,\n lane: { location: ParsedLocation },\n route: AnyRoute,\n cause: unknown,\n signal?: AbortSignal,\n notify = true,\n): LoaderOutcome {\n signal?.throwIfAborted()\n let outcome = normalize(cause, true)\n if (outcome[0] !== ERROR) {\n return materializeRedirect(router, lane, route, outcome, signal, notify)\n }\n try {\n route.options.onError?.(outcome[1])\n } catch (onErrorCause) {\n outcome = normalize(onErrorCause, true)\n }\n signal?.throwIfAborted()\n return materializeRedirect(router, lane, route, outcome, signal, notify)\n}\n\nfunction materializeRedirect(\n router: AnyRouter,\n lane: { location: ParsedLocation },\n route: AnyRoute,\n outcome: LoaderOutcome,\n signal?: AbortSignal,\n notify = true,\n): LoaderOutcome {\n if (outcome[0] !== REDIRECTED) {\n return outcome\n }\n signal?.throwIfAborted()\n try {\n outcome[1].options._fromLocation = lane.location\n router.resolveRedirect(outcome[1])\n signal?.throwIfAborted()\n return outcome\n } catch (cause) {\n signal?.throwIfAborted()\n return notify\n ? normalizeError(router, lane, route, cause, signal, false)\n : [ERROR, cause]\n }\n}\n\nfunction maybe<TValue>(\n value: TValue,\n cause: unknown,\n): { status: 'success'; value: TValue } | { status: 'error'; error: unknown } {\n if (cause !== undefined) {\n return { status: 'error', error: cause }\n }\n return { status: 'success', value }\n}\n\nfunction navigateFrom(router: AnyRouter, location: ParsedLocation) {\n return (options: any) =>\n router.navigate({\n ...options,\n _fromLocation: location,\n })\n}\n\nfunction waitFor<T>(value: Promise<T>, signal?: AbortSignal): Promise<T> {\n return signal ? waitForReason(value, signal) : value\n}\n\nasync function resolveSsr(\n router: AnyRouter,\n lane: MatchedLane,\n index: number,\n): Promise<SSROption> {\n const match = lane.matches[index]!\n const route = getRoute(router, match)\n const parentSsr = lane.matches[index - 1]?.ssr\n\n if (router.isShell()) {\n return route.id === rootRouteId\n }\n if (parentSsr === false) {\n return false\n }\n\n const inherit = (value: SSROption): SSROption => {\n return value === true && parentSsr === 'data-only' ? 'data-only' : value\n }\n const defaultSsr = router.options.defaultSsr ?? true\n const inheritedDefault = inherit(defaultSsr)\n // A functional override can fail. Establish the inherited policy first so\n // the selected error boundary retains the route's actual renderability.\n match.ssr = inheritedDefault\n const option = route.options.ssr\n if (option === undefined) {\n return inheritedDefault\n }\n if (typeof option !== 'function') {\n return inherit(option)\n }\n\n const context: SsrContextOptions<any, any, any> = {\n search: maybe(match.search, match.searchError),\n params: maybe(match.params, match.paramsError),\n location: lane.location,\n matches: lane.matches.map((candidate) => ({\n index: candidate.index,\n pathname: candidate.pathname,\n fullPath: candidate.fullPath,\n staticData: candidate.staticData,\n id: candidate.id,\n routeId: candidate.routeId,\n search: maybe(candidate.search, candidate.searchError),\n params: maybe(candidate.params, candidate.paramsError),\n ssr: candidate.ssr,\n })),\n }\n return inherit((await option(context)) ?? defaultSsr)\n}\n\nfunction stampNotFound(\n match: AnyRouteMatch,\n outcome: LoaderOutcome,\n): LoaderOutcome {\n if (outcome[0] === NOT_FOUND && !outcome[1].routeId) {\n outcome[1].routeId = match.routeId\n }\n return outcome\n}\n\nasync function contextualize(\n router: AnyRouter,\n lane: MatchedLane,\n signal?: AbortSignal,\n): Promise<ContextualizedLane> {\n const globalBoundary = lane.matches.findIndex((match) => match._notFound)\n let end = globalBoundary < 0 ? lane.matches.length : globalBoundary + 1\n let failure: IndexedOutcome | undefined\n let parentContext: Record<string, unknown> = {\n ...(router.options.context ?? {}),\n }\n\n for (let index = 0; index < end; index++) {\n const match = lane.matches[index]!\n const route = getRoute(router, match)\n try {\n match.ssr = await resolveSsr(router, lane, index)\n } catch (cause) {\n signal?.throwIfAborted()\n failure = [\n index,\n stampNotFound(\n match,\n normalizeError(router, lane, route, cause, signal),\n ),\n ]\n end = index\n }\n signal?.throwIfAborted()\n if (failure?.[1][0] === REDIRECTED) {\n break\n }\n\n match.__beforeLoadContext = undefined\n let context = parentContext\n try {\n let routeContext\n if (route.options.context) {\n const routeContextOptions: RouteContextOptions<\n any,\n any,\n any,\n any,\n any\n > = {\n deps: match.loaderDeps,\n params: match.params,\n context: parentContext,\n location: lane.location,\n navigate: navigateFrom(router, lane.location),\n buildLocation: router.buildLocation,\n cause: match.cause,\n abortController: match.abortController,\n preload: false,\n matches: lane.matches,\n routeId: route.id,\n }\n routeContext = route.options.context(routeContextOptions) ?? undefined\n }\n context = {\n ...parentContext,\n ...routeContext,\n }\n match.context = context\n } catch (cause) {\n signal?.throwIfAborted()\n if (!failure) {\n failure = [\n index,\n stampNotFound(\n match,\n normalizeError(router, lane, route, cause, signal),\n ),\n ]\n }\n end = index\n break\n }\n signal?.throwIfAborted()\n if (failure) {\n break\n }\n const validationError = match.paramsError ?? match.searchError\n if (validationError !== undefined) {\n failure = [\n index,\n stampNotFound(\n match,\n normalizeError(router, lane, route, validationError, signal),\n ),\n ]\n end = index\n break\n }\n signal?.throwIfAborted()\n\n if (match.ssr === false || !route.options.beforeLoad) {\n parentContext = context\n continue\n }\n\n const abortController = match.abortController\n const options: BeforeLoadContextOptions<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = {\n search: match.search,\n abortController,\n params: match.params,\n preload: false,\n context,\n location: lane.location,\n navigate: navigateFrom(router, lane.location),\n buildLocation: router.buildLocation,\n cause: match.cause,\n matches: lane.matches,\n routeId: route.id,\n ...router.options.additionalContext,\n }\n\n try {\n const beforeLoadContext = await route.options.beforeLoad(options)\n signal?.throwIfAborted()\n const outcome = stampNotFound(\n match,\n materializeRedirect(\n router,\n lane,\n route,\n normalize(beforeLoadContext, false),\n signal,\n ),\n )\n if (outcome[0] !== SUCCESS) {\n failure = [index, outcome]\n end = index\n break\n }\n match.__beforeLoadContext = beforeLoadContext\n match.context = {\n ...context,\n ...beforeLoadContext,\n }\n parentContext = match.context\n } catch (cause) {\n signal?.throwIfAborted()\n failure = [\n index,\n stampNotFound(\n match,\n normalizeError(router, lane, route, cause, signal),\n ),\n ]\n end = index\n break\n }\n }\n\n return {\n location: lane.location,\n matches: lane.matches,\n end,\n failure,\n } as ContextualizedLane\n}\n\nfunction getLoaderContext(\n router: AnyRouter,\n lane: ContextualizedLane,\n match: AnyRouteMatch,\n route: AnyRoute,\n index: number,\n tasks: Array<LoaderTask>,\n): LoaderFnContext {\n return {\n params: match.params,\n deps: match.loaderDeps,\n preload: false,\n parentMatchPromise: tasks[index - 1]?.match,\n abortController: match.abortController,\n context: match.context,\n location: lane.location,\n navigate: navigateFrom(router, lane.location),\n cause: match.cause,\n route,\n ...router.options.additionalContext,\n }\n}\n\nfunction createLoaderTask(\n router: AnyRouter,\n lane: ContextualizedLane,\n index: number,\n tasks: Array<LoaderTask>,\n signal?: AbortSignal,\n): LoaderTask {\n const match = lane.matches[index]!\n const route = getRoute(router, match)\n let outcome: Promise<LoaderOutcome>\n\n if (match.ssr === false) {\n outcome = Promise.resolve<LoaderOutcome>([SKIPPED])\n } else {\n const routeLoader = route.options.loader\n const loader =\n typeof routeLoader === 'function' ? routeLoader : routeLoader?.handler\n if (!loader) {\n outcome = Promise.resolve<LoaderOutcome>([SUCCESS, undefined])\n } else {\n outcome = Promise.resolve()\n .then(() =>\n loader(getLoaderContext(router, lane, match, route, index, tasks)),\n )\n .then(\n (result) => normalize(result, false),\n (cause) => normalize(cause, true),\n )\n .then((result): LoaderOutcome => {\n if (signal?.aborted || match.abortController.signal.reason === lane) {\n return [SKIPPED]\n }\n if (result[0] === ERROR) {\n result = normalizeError(router, lane, route, result[1], signal)\n } else {\n result = materializeRedirect(router, lane, route, result, signal)\n }\n return stampNotFound(match, result)\n })\n }\n }\n\n const parentMatch = outcome.then((result) => {\n const snapshot = { ...match }\n if (result[0] === SUCCESS) {\n snapshot.loaderData = result[1]\n snapshot.status = 'success'\n snapshot.error = undefined\n snapshot.invalid = false\n snapshot.isFetching = false\n } else if (result[0] === ERROR) {\n snapshot.status = 'error'\n snapshot.error = result[1]\n } else if (result[0] === NOT_FOUND) {\n snapshot.status = 'notFound'\n snapshot.error = result[1]\n }\n return snapshot\n })\n\n return { index, outcome, match: parentMatch }\n}\n\nasync function getNotFoundBoundary(\n router: AnyRouter,\n matches: Array<AnyRouteMatch>,\n indexed: IndexedOutcome | undefined,\n signal?: AbortSignal,\n fallback = 0,\n): Promise<number> {\n const cause = indexed?.[1][1] as NotFoundError | undefined\n let index = cause?.routeId\n ? matches.findIndex((match) => match.routeId === cause.routeId)\n : (indexed?.[0] ?? matches.length - 1)\n if (index < 0) {\n index = 0\n }\n for (let candidate = index; candidate >= 0; candidate--) {\n const route = getRoute(router, matches[candidate]!)\n try {\n const loading = loadRouteChunk(route, false)\n if (loading) {\n await loading\n }\n } catch {\n signal?.throwIfAborted()\n }\n signal?.throwIfAborted()\n if (route.options.notFoundComponent) {\n return candidate\n }\n }\n return cause?.routeId ? index : fallback\n}\n\nfunction abortMatches(\n matches: Array<AnyRouteMatch>,\n start = 0,\n reason?: unknown,\n): void {\n for (let index = start; index < matches.length; index++) {\n matches[index]!.abortController.abort(reason)\n }\n}\n\nasync function applyFailure(\n router: AnyRouter,\n lane: ContextualizedLane,\n indexed: IndexedOutcome | undefined,\n signal?: AbortSignal,\n): Promise<{ status: 200 | 404 | 500; boundary?: number; kind?: number }> {\n if (!indexed) {\n const boundary = lane.matches.findIndex((match) => match._notFound)\n if (boundary >= 0) {\n abortMatches(lane.matches, boundary + 1)\n return { status: 404, boundary, kind: NOT_FOUND }\n }\n return { status: 200 }\n }\n\n const [index, outcome] = indexed\n if (outcome[0] === ERROR) {\n const match = lane.matches[index]!\n match._notFound = undefined\n match.status = 'error'\n match.error = outcome[1]\n match.isFetching = false\n abortMatches(lane.matches, index + 1)\n return { status: 500, boundary: index, kind: ERROR }\n }\n\n const boundary =\n indexed[2] ??\n (await getNotFoundBoundary(router, lane.matches, indexed, signal))\n const match = lane.matches[boundary]!\n const cause = outcome[1] as NotFoundError\n cause.routeId = match.routeId\n match._notFound = undefined\n if (match.routeId === router.routeTree.id) {\n match.status = 'success'\n match._notFound = true\n match.error = cause\n } else {\n match.status = 'notFound'\n match.error = cause\n }\n match.isFetching = false\n abortMatches(lane.matches, boundary + 1)\n return { status: 404, boundary, kind: NOT_FOUND }\n}\n\nasync function loadNormalChunks(\n router: AnyRouter,\n lane: ContextualizedLane,\n end: number,\n signal?: AbortSignal,\n): Promise<IndexedOutcome | undefined> {\n const chunks: Array<IndexedOutcome | Promise<IndexedOutcome | undefined>> = []\n for (let index = 0; index < lane.matches.length; index++) {\n const match = lane.matches[index]!\n if (index >= end || match.ssr !== true || match.status !== 'success') {\n continue\n }\n const route = getRoute(router, match)\n try {\n const loading = loadRouteChunk(route)\n if (loading) {\n const chunk = loading.then(\n () => {\n signal?.throwIfAborted()\n return undefined\n },\n (cause) => {\n signal?.throwIfAborted()\n return [\n index,\n stampNotFound(\n match,\n normalizeError(router, lane, route, cause, signal),\n ),\n ] as IndexedOutcome\n },\n )\n // Route-order reduction can return before later chunks settle.\n void chunk.catch(() => {})\n chunks.push(chunk)\n }\n } catch (cause) {\n signal?.throwIfAborted()\n chunks.push([\n index,\n stampNotFound(\n match,\n normalizeError(router, lane, route, cause, signal),\n ),\n ])\n }\n }\n for (const chunk of chunks) {\n const indexed = Array.isArray(chunk) ? chunk : await chunk\n if (indexed) {\n return indexed\n }\n }\n return undefined\n}\n\nasync function projectLane(\n router: AnyRouter,\n lane: ReducedLane,\n signal?: AbortSignal,\n): Promise<void> {\n for (const match of lane.matches) {\n const routeOptions = getRoute(router, match).options\n if (routeOptions.head || routeOptions.scripts || routeOptions.headers) {\n const context = {\n ssr: router.options.ssr,\n matches: lane.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n try {\n const [head, scripts, headers] = await Promise.all([\n routeOptions.head?.(context),\n routeOptions.scripts?.(context),\n routeOptions.headers?.(context),\n ])\n signal?.throwIfAborted()\n match.meta = head?.meta\n match.links = head?.links\n match.headScripts = head?.scripts\n match.styles = head?.styles\n match.scripts = scripts\n match.headers = headers\n } catch (cause) {\n signal?.throwIfAborted()\n console.error(cause)\n }\n }\n if (match.ssr === false || match.status !== 'success' || match._notFound) {\n break\n }\n }\n}\n\nasync function executeServerLane(\n router: AnyRouter,\n location: ParsedLocation,\n matchedMatches: Array<AnyRouteMatch>,\n signal?: AbortSignal,\n): Promise<ServerLoadResult> {\n const matched = {\n location,\n matches: matchedMatches.map((match) => ({\n ...match,\n __beforeLoadContext: undefined,\n context: {},\n isFetching: false,\n abortController: new AbortController(),\n })),\n } as MatchedLane\n const abortLane = () => abortMatches(matched.matches, 0, signal?.reason)\n if (signal?.aborted) {\n abortLane()\n signal.throwIfAborted()\n }\n signal?.addEventListener('abort', abortLane, { once: true })\n\n try {\n const plannedGlobalBoundary = matched.matches.findIndex(\n (match) => match._notFound,\n )\n if (router.options.notFoundMode !== 'root' && plannedGlobalBoundary >= 0) {\n const boundary = await getNotFoundBoundary(\n router,\n matched.matches,\n undefined,\n signal,\n plannedGlobalBoundary,\n )\n if (boundary !== plannedGlobalBoundary) {\n matched.matches[plannedGlobalBoundary]!._notFound = undefined\n matched.matches[boundary]!._notFound = true\n }\n }\n const lane = await contextualize(router, matched, signal)\n signal?.throwIfAborted()\n\n let loaderEnd = lane.end\n if (lane.failure?.[1][0] === REDIRECTED) {\n loaderEnd = 0\n } else if (lane.failure?.[1][0] === NOT_FOUND) {\n lane.failure[2] = await getNotFoundBoundary(\n router,\n lane.matches,\n lane.failure,\n signal,\n )\n loaderEnd = Math.min(loaderEnd, lane.failure[2] + 1)\n }\n\n const tasks: Array<LoaderTask> = []\n for (let index = 0; index < loaderEnd; index++) {\n const task = createLoaderTask(router, lane, index, tasks, signal)\n tasks.push(task)\n }\n\n let loaderFailure: IndexedOutcome | undefined\n let control = lane.failure?.[1][0] === REDIRECTED ? lane.failure : undefined\n try {\n await Promise.all(\n tasks.map((task) =>\n task.outcome.then((loadedOutcome) => {\n const match = lane.matches[task.index]!\n const outcome = loadedOutcome\n if (outcome[0] === SUCCESS) {\n match.loaderData = outcome[1]\n match.status = 'success'\n match.error = undefined\n match.invalid = false\n match.isFetching = false\n match.updatedAt = Date.now()\n } else if (outcome[0] === REDIRECTED) {\n control = [task.index, outcome]\n throw control\n } else {\n // A selective-SSR skip must stay pending for hydration. Every\n // settled server attempt is otherwise renderable unless\n // reduction selects it as the lane's terminal failure.\n if (match.ssr !== false) {\n match.status = 'success'\n match.error = undefined\n match.invalid = true\n match.isFetching = false\n }\n if (!loaderFailure && outcome[0] !== SKIPPED) {\n loaderFailure = [task.index, outcome]\n }\n }\n }),\n ),\n )\n } catch (cause) {\n if (!Array.isArray(cause)) {\n throw cause\n }\n control = cause as IndexedOutcome\n }\n signal?.throwIfAborted()\n\n if (control?.[1][0] === REDIRECTED) {\n abortMatches(lane.matches, 0, lane)\n return { type: 'redirect', redirect: control[1][1] }\n }\n\n let failure = lane.failure ?? loaderFailure\n const plannedBoundary = lane.matches.findIndex((match) => match._notFound)\n let readinessEnd: number\n if (failure) {\n const outcomeEnd = (failure[2] ??=\n failure[1][0] === NOT_FOUND\n ? await getNotFoundBoundary(router, lane.matches, failure, signal)\n : failure[0])\n for (const task of tasks) {\n if (task.index >= outcomeEnd) {\n break\n }\n const outcome = await task.outcome\n // Presence means a loader previously succeeded, even with `undefined`.\n if (\n outcome[0] !== SUCCESS &&\n outcome[0] < REDIRECTED &&\n !('loaderData' in lane.matches[task.index]!)\n ) {\n failure = [task.index, outcome]\n failure[2] =\n outcome[0] === NOT_FOUND\n ? await getNotFoundBoundary(router, lane.matches, failure, signal)\n : task.index\n break\n }\n }\n readinessEnd = failure[2]\n } else {\n readinessEnd = plannedBoundary < 0 ? lane.matches.length : plannedBoundary\n }\n const requiredFailure = await loadNormalChunks(\n router,\n lane,\n readinessEnd,\n signal,\n )\n signal?.throwIfAborted()\n if (requiredFailure) {\n if (requiredFailure[1][0] === REDIRECTED) {\n abortMatches(lane.matches)\n return { type: 'redirect', redirect: requiredFailure[1][1] }\n }\n failure = requiredFailure\n }\n\n const terminal = await applyFailure(router, lane, failure, signal)\n if (terminal.boundary !== undefined) {\n const match = lane.matches[terminal.boundary]!\n if (match.ssr === true) {\n const route = getRoute(router, match)\n try {\n if (terminal.kind === ERROR) {\n await loadRouteChunk(route, 'errorComponent')\n } else if (match._notFound) {\n await Promise.all([\n loadRouteChunk(route),\n loadRouteChunk(route, 'notFoundComponent'),\n ])\n } else {\n await loadRouteChunk(route, 'notFoundComponent')\n }\n } catch {}\n signal?.throwIfAborted()\n }\n }\n\n signal?.throwIfAborted()\n await projectLane(\n router,\n {\n location: lane.location,\n matches: lane.matches,\n } as ReducedLane,\n signal,\n )\n signal?.throwIfAborted()\n router.serverSsr?.onCleanup(abortLane)\n return { type: 'render', status: terminal.status, matches: lane.matches }\n } finally {\n signal?.removeEventListener('abort', abortLane)\n }\n}\n\ntype ServerLoadOptions = NonNullable<Parameters<AnyRouter['load']>[0]> & {\n _signal?: AbortSignal\n}\n\nexport async function loadServerRoute(\n router: AnyRouter,\n opts?: ServerLoadOptions,\n): Promise<void> {\n router.updateLatestLocation()\n const next = router.latestLocation\n const previous = router._committed\n let result: ServerLoadResult\n try {\n const canonical = router.buildLocation({\n to: next.pathname,\n search: true,\n params: true,\n hash: true,\n state: true,\n _includeValidateSearch: true,\n })\n if (next.publicHref !== canonical.publicHref) {\n const href = canonical.publicHref || '/'\n throw redirect({ href })\n }\n\n const fromLocation = router.stores.resolvedLocation.get()\n const changeInfo = getLocationChangeInfo(next, fromLocation)\n router.emit({ type: 'onBeforeNavigate', ...changeInfo })\n router.emit({ type: 'onBeforeLoad', ...changeInfo })\n opts?._signal?.throwIfAborted()\n result = await waitFor(\n executeServerLane(router, next, router.matchRoutes(next), opts?._signal),\n opts?._signal,\n )\n opts?._signal?.throwIfAborted()\n } catch (cause) {\n opts?._signal?.throwIfAborted()\n if (!isRedirect(cause)) {\n throw cause\n }\n cause.options._fromLocation = next\n result = { type: 'redirect', redirect: router.resolveRedirect(cause) }\n }\n\n router._serverResult = result\n router.batch(() => {\n router.stores.location.set(next)\n router.stores.status.set('idle')\n if (result.type === 'render') {\n router.stores.setMatches(result.matches)\n router.stores.resolvedLocation.set(next)\n }\n })\n if (result.type === 'render') {\n router._committed = result.matches\n runRouteLifecycle(router, previous, result.matches)\n }\n router._commitPromise?.resolve()\n router._commitPromise = undefined\n}\n"],"mappings":";;;;;;;AAwCA,MAAM,UAAU;AAChB,MAAM,QAAQ;AACd,MAAM,YAAY;AAClB,MAAM,aAAa;AACnB,MAAM,UAAU;AAuBhB,SAAS,SAAS,QAAmB,OAAgC;CACnE,OAAO,OAAO,WAAW,MAAM;AACjC;AAEA,SAAS,UAAU,OAAgB,UAAkC;CACnE,IAAI,iBAAA,WAAW,KAAK,GAClB,OAAO,CAAC,YAAY,KAAK;CAE3B,IAAI,kBAAA,WAAW,KAAK,GAClB,OAAO,CAAC,WAAW,KAAK;CAE1B,IAAI,YAAY,OAAQ,OAAe,SAAS,YAC9C,QAAQ,IAAI,MAAM,wBAAwB,EAAE,OAAO,MAAM,CAAC;CAE5D,OAAO,WAAW,CAAC,OAAO,KAAK,IAAI,CAAC,SAAS,KAAK;AACpD;AAEA,SAAS,eACP,QACA,MACA,OACA,OACA,QACA,SAAS,MACM;CACf,QAAQ,eAAe;CACvB,IAAI,UAAU,UAAU,OAAO,IAAI;CACnC,IAAI,QAAQ,OAAO,OACjB,OAAO,oBAAoB,QAAQ,MAAM,OAAO,SAAS,QAAQ,MAAM;CAEzE,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AgB;CACvB,OAAO,YAAY;EACjB,OAAO,OAAO,SAAS,IAAI,IAAI;EAC/B,OAAO,OAAO,OAAO,IAAI,MAAM;EAC/B,IAAI,OAAO,SAAS,UAAU;GAC5B,OAAO,OAAO,WAAW,OAAO,OAAO;GACvC,OAAO,OAAO,iBAAiB,IAAI,IAAI;EACzC;CACF,CAAC;CACD,IAAI,OAAO,SAAS,UAAU;EAC5B,OAAO,aAAa,OAAO;EAC3B,eAAA,kBAAkB,QAAQ,UAAU,OAAO,OAAO;CACpD;CACA,OAAO,gBAAgB,QAAQ;CAC/B,OAAO,iBAAiB,KAAA;AAC1B"}
@@ -18,7 +18,7 @@
18
18
  */
19
19
  function redirect(opts) {
20
20
  opts.statusCode = opts.statusCode || opts.code || 307;
21
- if (!opts._builtLocation && !opts.reloadDocument && typeof opts.href === "string") try {
21
+ if (!opts.reloadDocument && typeof opts.href === "string") try {
22
22
  new URL(opts.href);
23
23
  opts.reloadDocument = true;
24
24
  } catch {}
@@ -1 +1 @@
1
- {"version":3,"file":"redirect.cjs","names":[],"sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { ParsedLocation } from './location'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = Response & {\n options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n }\n}\n\nexport type RedirectOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string = '',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\n/**\n * Options for route-bound redirect, where 'from' is automatically set.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type RedirectOptionsRoute<\n TDefaultFrom extends string = string,\n TRouter extends AnyRouter = RegisteredRouter,\n TTo extends string | undefined = undefined,\n TMaskTo extends string = '',\n> = Omit<\n RedirectOptions<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>,\n 'from'\n>\n\n/**\n * A redirect function bound to a specific route, with 'from' pre-set to the route's fullPath.\n * This enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport interface RedirectFnRoute<in out TDefaultFrom extends string = string> {\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n opts: RedirectOptionsRoute<TDefaultFrom, TRouter, TTo, TMaskTo>,\n ): Redirect<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>\n}\n\n/**\n * Create a redirect Response understood by TanStack Router.\n *\n * Use from route `loader`/`beforeLoad` or server functions to trigger a\n * navigation. If `throw: true` is set, the redirect is thrown instead of\n * returned. When an absolute `href` is supplied and `reloadDocument` is not\n * set, a full-document navigation is inferred.\n *\n * @param opts Options for the redirect. Common fields:\n * - `href`: absolute URL for external redirects; infers `reloadDocument`.\n * - `statusCode`: HTTP status code to use (defaults to 307).\n * - `headers`: additional headers to include on the Response.\n * - Standard navigation options like `to`, `params`, `search`, `replace`,\n * and `reloadDocument` for internal redirects.\n * @returns A Response augmented with router navigation options.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\nexport function redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = '.',\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: RedirectOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n opts.statusCode = opts.statusCode || opts.code || 307\n\n if (\n !opts._builtLocation &&\n !opts.reloadDocument &&\n typeof opts.href === 'string'\n ) {\n try {\n new URL(opts.href)\n opts.reloadDocument = true\n } catch {}\n }\n\n const headers = new Headers(opts.headers)\n if (opts.href && headers.get('Location') === null) {\n headers.set('Location', opts.href)\n }\n\n const response = new Response(null, {\n status: opts.statusCode,\n headers,\n })\n\n ;(response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>).options =\n opts\n\n if (opts.throw) {\n throw response\n }\n\n return response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n}\n\n/** Check whether a value is a TanStack Router redirect Response. */\n/** Check whether a value is a TanStack Router redirect Response. */\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return obj instanceof Response && !!(obj as any).options\n}\n\n/** True if value is a redirect with a resolved `href` location. */\n/** True if value is a redirect with a resolved `href` location. */\nexport function isResolvedRedirect(\n obj: any,\n): obj is AnyRedirect & { options: { href: string } } {\n return isRedirect(obj) && !!obj.options.href\n}\n\n/** Parse a serialized redirect object back into a redirect Response. */\n/** Parse a serialized redirect object back into a redirect Response. */\nexport function parseRedirect(obj: any) {\n if (obj !== null && typeof obj === 'object' && obj.isSerializedRedirect) {\n return redirect(obj)\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiHA,SAAgB,SAOd,MACmD;CACnD,KAAK,aAAa,KAAK,cAAc,KAAK,QAAQ;CAElD,IACE,CAAC,KAAK,kBACN,CAAC,KAAK,kBACN,OAAO,KAAK,SAAS,UAErB,IAAI;EACF,IAAI,IAAI,KAAK,IAAI;EACjB,KAAK,iBAAiB;CACxB,QAAQ,CAAC;CAGX,MAAM,UAAU,IAAI,QAAQ,KAAK,OAAO;CACxC,IAAI,KAAK,QAAQ,QAAQ,IAAI,UAAU,MAAM,MAC3C,QAAQ,IAAI,YAAY,KAAK,IAAI;CAGnC,MAAM,WAAW,IAAI,SAAS,MAAM;EAClC,QAAQ,KAAK;EACb;CACF,CAAC;CAEA,SAAgE,UAC/D;CAEF,IAAI,KAAK,OACP,MAAM;CAGR,OAAO;AACT;;;AAIA,SAAgB,WAAW,KAA8B;CACvD,OAAO,eAAe,YAAY,CAAC,CAAE,IAAY;AACnD;;;AAIA,SAAgB,mBACd,KACoD;CACpD,OAAO,WAAW,GAAG,KAAK,CAAC,CAAC,IAAI,QAAQ;AAC1C;;;AAIA,SAAgB,cAAc,KAAU;CACtC,IAAI,QAAQ,QAAQ,OAAO,QAAQ,YAAY,IAAI,sBACjD,OAAO,SAAS,GAAG;AAIvB"}
1
+ {"version":3,"file":"redirect.cjs","names":[],"sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { AnyRouter, RegisteredRouter } from './router'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = Response & {\n options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n}\n\nexport type RedirectOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string = '',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\n/**\n * Options for route-bound redirect, where 'from' is automatically set.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type RedirectOptionsRoute<\n TDefaultFrom extends string = string,\n TRouter extends AnyRouter = RegisteredRouter,\n TTo extends string | undefined = undefined,\n TMaskTo extends string = '',\n> = Omit<\n RedirectOptions<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>,\n 'from'\n>\n\n/**\n * A redirect function bound to a specific route, with 'from' pre-set to the route's fullPath.\n * This enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport interface RedirectFnRoute<in out TDefaultFrom extends string = string> {\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n opts: RedirectOptionsRoute<TDefaultFrom, TRouter, TTo, TMaskTo>,\n ): Redirect<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>\n}\n\n/**\n * Create a redirect Response understood by TanStack Router.\n *\n * Use from route `loader`/`beforeLoad` or server functions to trigger a\n * navigation. If `throw: true` is set, the redirect is thrown instead of\n * returned. When an absolute `href` is supplied and `reloadDocument` is not\n * set, a full-document navigation is inferred.\n *\n * @param opts Options for the redirect. Common fields:\n * - `href`: absolute URL for external redirects; infers `reloadDocument`.\n * - `statusCode`: HTTP status code to use (defaults to 307).\n * - `headers`: additional headers to include on the Response.\n * - Standard navigation options like `to`, `params`, `search`, `replace`,\n * and `reloadDocument` for internal redirects.\n * @returns A Response augmented with router navigation options.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\nexport function redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = '.',\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: RedirectOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n opts.statusCode = opts.statusCode || opts.code || 307\n\n if (!opts.reloadDocument && typeof opts.href === 'string') {\n try {\n new URL(opts.href)\n opts.reloadDocument = true\n } catch {}\n }\n\n const headers = new Headers(opts.headers)\n if (opts.href && headers.get('Location') === null) {\n headers.set('Location', opts.href)\n }\n\n const response = new Response(null, {\n status: opts.statusCode,\n headers,\n })\n\n ;(response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>).options =\n opts\n\n if (opts.throw) {\n throw response\n }\n\n return response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n}\n\n/** Check whether a value is a TanStack Router redirect Response. */\n/** Check whether a value is a TanStack Router redirect Response. */\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return obj instanceof Response && !!(obj as any).options\n}\n\n/** True if value is a redirect with a resolved `href` location. */\n/** True if value is a redirect with a resolved `href` location. */\nexport function isResolvedRedirect(\n obj: any,\n): obj is AnyRedirect & { options: { href: string } } {\n return isRedirect(obj) && !!obj.options.href\n}\n\n/** Parse a serialized redirect object back into a redirect Response. */\n/** Parse a serialized redirect object back into a redirect Response. */\nexport function parseRedirect(obj: any) {\n if (obj !== null && typeof obj === 'object' && obj.isSerializedRedirect) {\n return redirect(obj)\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqGA,SAAgB,SAOd,MACmD;CACnD,KAAK,aAAa,KAAK,cAAc,KAAK,QAAQ;CAElD,IAAI,CAAC,KAAK,kBAAkB,OAAO,KAAK,SAAS,UAC/C,IAAI;EACF,IAAI,IAAI,KAAK,IAAI;EACjB,KAAK,iBAAiB;CACxB,QAAQ,CAAC;CAGX,MAAM,UAAU,IAAI,QAAQ,KAAK,OAAO;CACxC,IAAI,KAAK,QAAQ,QAAQ,IAAI,UAAU,MAAM,MAC3C,QAAQ,IAAI,YAAY,KAAK,IAAI;CAGnC,MAAM,WAAW,IAAI,SAAS,MAAM;EAClC,QAAQ,KAAK;EACb;CACF,CAAC;CAEA,SAAgE,UAC/D;CAEF,IAAI,KAAK,OACP,MAAM;CAGR,OAAO;AACT;;;AAIA,SAAgB,WAAW,KAA8B;CACvD,OAAO,eAAe,YAAY,CAAC,CAAE,IAAY;AACnD;;;AAIA,SAAgB,mBACd,KACoD;CACpD,OAAO,WAAW,GAAG,KAAK,CAAC,CAAC,IAAI,QAAQ;AAC1C;;;AAIA,SAAgB,cAAc,KAAU;CACtC,IAAI,QAAQ,QAAQ,OAAO,QAAQ,YAAY,IAAI,sBACjD,OAAO,SAAS,GAAG;AAIvB"}
@@ -5,7 +5,7 @@ export type AnyRedirect = Redirect<any, any, any, any, any>;
5
5
  * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)
6
6
  */
7
7
  export type Redirect<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = undefined, TMaskFrom extends string = TFrom, TMaskTo extends string = '.'> = Response & {
8
- options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {};
8
+ options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>;
9
9
  };
10
10
  export type RedirectOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = undefined, TMaskFrom extends string = TFrom, TMaskTo extends string = '.'> = {
11
11
  href?: string;
@@ -59,13 +59,13 @@ function _getUserHistoryState({ key: _key, __TSR_key: _tsrKey, __TSR_index: _tsr
59
59
  return state;
60
60
  }
61
61
  /** Run route lifecycle callbacks in leave/enter/stay phases. */
62
- function runRouteLifecycle(router, previous, matches, isCurrent) {
62
+ function runRouteLifecycle(router, previous, matches, owner) {
63
63
  for (const match of previous) {
64
- if (isCurrent?.() === false) return;
64
+ if (owner && router._tx !== owner) return;
65
65
  if (!matches.some((candidate) => candidate.routeId === match.routeId)) router.routesById[match.routeId].options.onLeave?.(match);
66
66
  }
67
67
  for (const match of matches) {
68
- if (isCurrent?.() === false) return;
68
+ if (owner && router._tx !== owner) return;
69
69
  router.routesById[match.routeId].options[previous.some((candidate) => candidate.routeId === match.routeId) ? "onStay" : "onEnter"]?.(match);
70
70
  }
71
71
  }
@@ -253,6 +253,15 @@ var RouterCore = class {
253
253
  };
254
254
  this.buildLocation = (opts) => {
255
255
  const build = (dest = {}) => {
256
+ if (dest.href) {
257
+ const parsed = (0, _tanstack_history.parseHref)(dest.href, {});
258
+ dest = {
259
+ ...dest,
260
+ to: require_rewrite.executeRewriteInput(this.rewrite, new URL(parsed.pathname, this.origin)).pathname,
261
+ search: this.options.parseSearch(parsed.search),
262
+ hash: parsed.hash.slice(1)
263
+ };
264
+ }
256
265
  const currentLocation = dest._fromLocation || this._pendingLocation || this.latestLocation;
257
266
  const lightweightResult = this.matchRoutesLightweight(currentLocation);
258
267
  if (dest.from && process.env.NODE_ENV !== "production" && dest._isNavigate) {
@@ -411,20 +420,11 @@ var RouterCore = class {
411
420
  this._scroll.next = next.resetScroll ?? true;
412
421
  return this._commitPromise;
413
422
  };
414
- this.buildAndCommitLocation = ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, _redirects, href, ...rest } = {}) => {
415
- if (href) {
416
- const currentIndex = this.history.location.state.__TSR_index;
417
- const parsed = (0, _tanstack_history.parseHref)(href, { __TSR_index: replace ? currentIndex : currentIndex + 1 });
418
- const hrefUrl = new URL(parsed.pathname, this.origin);
419
- rest.to = require_rewrite.executeRewriteInput(this.rewrite, hrefUrl).pathname;
420
- rest.search = this.options.parseSearch(parsed.search);
421
- rest.hash = parsed.hash.slice(1);
422
- }
423
+ this.buildAndCommitLocation = ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, ...rest } = {}) => {
423
424
  const location = this.buildLocation({
424
425
  ...rest,
425
426
  _includeValidateSearch: true
426
427
  });
427
- if (_redirects) location._redirects = _redirects;
428
428
  this._pendingLocation = location;
429
429
  const commitPromise = this.commitLocation({
430
430
  ...location,
@@ -549,8 +549,8 @@ var RouterCore = class {
549
549
  };
550
550
  this.resolveRedirect = (redirect) => {
551
551
  const locationHeader = redirect.headers.get("Location");
552
- if (!redirect.options.href || redirect.options._builtLocation) {
553
- const href = (redirect.options._builtLocation ?? this.buildLocation(redirect.options)).publicHref || "/";
552
+ if (!redirect.options.href) {
553
+ const href = this.buildLocation(redirect.options).publicHref || "/";
554
554
  redirect.options.href = href;
555
555
  redirect.headers.set("Location", href);
556
556
  } else if (locationHeader) try {
@@ -561,7 +561,7 @@ var RouterCore = class {
561
561
  redirect.headers.set("Location", href);
562
562
  }
563
563
  } catch {}
564
- if (redirect.options.href && !redirect.options._builtLocation && require_utils.isDangerousProtocol(redirect.options.href, this.protocolAllowlist)) throw new Error(process.env.NODE_ENV !== "production" ? `Redirect blocked: unsafe protocol in href "${redirect.options.href}". Allowed protocols: ${Array.from(this.protocolAllowlist).join(", ")}.` : "Redirect blocked: unsafe protocol");
564
+ if (redirect.options.href && require_utils.isDangerousProtocol(redirect.options.href, this.protocolAllowlist)) throw new Error(process.env.NODE_ENV !== "production" ? `Redirect blocked: unsafe protocol in href "${redirect.options.href}". Allowed protocols: ${Array.from(this.protocolAllowlist).join(", ")}.` : "Redirect blocked: unsafe protocol");
565
565
  if (!redirect.headers.get("Location")) redirect.headers.set("Location", redirect.options.href);
566
566
  return redirect;
567
567
  };
@@ -593,7 +593,7 @@ var RouterCore = class {
593
593
  for (const controller of abort) controller.abort();
594
594
  };
595
595
  this.loadRouteChunk = require_load_client.loadRouteChunk;
596
- this.preloadRoute = (opts) => require_load_client.preloadClientRoute(this, opts);
596
+ this.preloadRoute = (opts, builtLocation) => require_load_client.preloadClientRoute(this, opts, 0, builtLocation);
597
597
  this.matchRoute = (location, opts) => {
598
598
  const matchLocation = {
599
599
  ...location,