@tanstack/router-core 1.142.8 → 1.142.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -414,8 +414,6 @@ const runLoader = async (inner, matchId, index, route) => {
414
414
  }
415
415
  }
416
416
  if (route._lazyPromise) await route._lazyPromise;
417
- const headResult = executeHead(inner, matchId, route);
418
- const head = headResult ? await headResult : void 0;
419
417
  const pendingPromise = match._nonReactive.minPendingPromise;
420
418
  if (pendingPromise) await pendingPromise;
421
419
  if (route._componentsPromise) await route._componentsPromise;
@@ -424,8 +422,7 @@ const runLoader = async (inner, matchId, index, route) => {
424
422
  error: void 0,
425
423
  status: "success",
426
424
  isFetching: false,
427
- updatedAt: Date.now(),
428
- ...head
425
+ updatedAt: Date.now()
429
426
  }));
430
427
  } catch (e) {
431
428
  let error = e;
@@ -445,27 +442,16 @@ const runLoader = async (inner, matchId, index, route) => {
445
442
  onErrorError
446
443
  );
447
444
  }
448
- const headResult = executeHead(inner, matchId, route);
449
- const head = headResult ? await headResult : void 0;
450
445
  inner.updateMatch(matchId, (prev) => ({
451
446
  ...prev,
452
447
  error,
453
448
  status: "error",
454
- isFetching: false,
455
- ...head
449
+ isFetching: false
456
450
  }));
457
451
  }
458
452
  } catch (err) {
459
453
  const match = inner.router.getMatch(matchId);
460
454
  if (match) {
461
- const headResult = executeHead(inner, matchId, route);
462
- if (headResult) {
463
- const head = await headResult;
464
- inner.updateMatch(matchId, (prev) => ({
465
- ...prev,
466
- ...head
467
- }));
468
- }
469
455
  match._nonReactive.loaderPromise = void 0;
470
456
  }
471
457
  handleRedirectAndNotFound(inner, match, err);
@@ -484,14 +470,6 @@ const loadRouteMatch = async (inner, index) => {
484
470
  };
485
471
  if (shouldSkipLoader(inner, matchId)) {
486
472
  if (inner.router.isServer) {
487
- const headResult = executeHead(inner, matchId, route);
488
- if (headResult) {
489
- const head = await headResult;
490
- inner.updateMatch(matchId, (prev) => ({
491
- ...prev,
492
- ...head
493
- }));
494
- }
495
473
  return inner.router.getMatch(matchId);
496
474
  }
497
475
  } else {
@@ -542,15 +520,6 @@ const loadRouteMatch = async (inner, index) => {
542
520
  })();
543
521
  } else if (status !== "success" || loaderShouldRunAsync && inner.sync) {
544
522
  await runLoader(inner, matchId, index, route);
545
- } else {
546
- const headResult = executeHead(inner, matchId, route);
547
- if (headResult) {
548
- const head = await headResult;
549
- inner.updateMatch(matchId, (prev) => ({
550
- ...prev,
551
- ...head
552
- }));
553
- }
554
523
  }
555
524
  }
556
525
  }
@@ -594,7 +563,38 @@ async function loadMatches(arg) {
594
563
  for (let i = 0; i < max; i++) {
595
564
  inner.matchPromises.push(loadRouteMatch(inner, i));
596
565
  }
597
- await Promise.all(inner.matchPromises);
566
+ const results = await Promise.allSettled(inner.matchPromises);
567
+ const failures = results.filter(
568
+ (result) => result.status === "rejected"
569
+ ).map((result) => result.reason);
570
+ let firstNotFound;
571
+ for (const err of failures) {
572
+ if (redirect.isRedirect(err)) {
573
+ throw err;
574
+ }
575
+ if (!firstNotFound && notFound.isNotFound(err)) {
576
+ firstNotFound = err;
577
+ }
578
+ }
579
+ for (const match of inner.matches) {
580
+ const { id: matchId, routeId } = match;
581
+ const route = inner.router.looseRoutesById[routeId];
582
+ try {
583
+ const headResult = executeHead(inner, matchId, route);
584
+ if (headResult) {
585
+ const head = await headResult;
586
+ inner.updateMatch(matchId, (prev) => ({
587
+ ...prev,
588
+ ...head
589
+ }));
590
+ }
591
+ } catch (err) {
592
+ console.error(`Error executing head for route ${routeId}:`, err);
593
+ }
594
+ }
595
+ if (firstNotFound) {
596
+ throw firstNotFound;
597
+ }
598
598
  const readyPromise = triggerOnReady(inner);
599
599
  if (utils.isPromise(readyPromise)) await readyPromise;
600
600
  } catch (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"load-matches.cjs","sources":["../../src/load-matches.ts"],"sourcesContent":["import { batch } from '@tanstack/store'\nimport invariant from 'tiny-invariant'\nimport { createControlledPromise, isPromise } from './utils'\nimport { isNotFound } from './not-found'\nimport { rootRouteId } from './root'\nimport { isRedirect } from './redirect'\nimport type { NotFoundError } from './not-found'\nimport type { ParsedLocation } from './location'\nimport type {\n AnyRoute,\n BeforeLoadContextOptions,\n LoaderFnContext,\n SsrContextOptions,\n} from './route'\nimport type { AnyRouteMatch, MakeRouteMatch } from './Matches'\nimport type { AnyRouter, SSROption, UpdateMatchFn } from './router'\n\n/**\n * An object of this shape is created when calling `loadMatches`.\n * It contains everything we need for all other functions in this file\n * to work. (It's basically the function's argument, plus a few mutable states)\n */\ntype InnerLoadContext = {\n /** the calling router instance */\n router: AnyRouter\n location: ParsedLocation\n /** mutable state, scoped to a `loadMatches` call */\n firstBadMatchIndex?: number\n /** mutable state, scoped to a `loadMatches` call */\n rendered?: boolean\n updateMatch: UpdateMatchFn\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n sync?: boolean\n /** mutable state, scoped to a `loadMatches` call */\n matchPromises: Array<Promise<AnyRouteMatch>>\n}\n\nconst triggerOnReady = (inner: InnerLoadContext): void | Promise<void> => {\n if (!inner.rendered) {\n inner.rendered = true\n return inner.onReady?.()\n }\n}\n\nconst resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {\n return !!(\n inner.preload && !inner.router.state.matches.some((d) => d.id === matchId)\n )\n}\n\n/**\n * Builds the accumulated context from router options and all matches up to (and optionally including) the given index.\n * Merges __routeContext and __beforeLoadContext from each match.\n */\nconst buildMatchContext = (\n inner: InnerLoadContext,\n index: number,\n includeCurrentMatch: boolean = true,\n): Record<string, unknown> => {\n const context: Record<string, unknown> = {\n ...(inner.router.options.context ?? {}),\n }\n const end = includeCurrentMatch ? index : index - 1\n for (let i = 0; i <= end; i++) {\n const innerMatch = inner.matches[i]\n if (!innerMatch) continue\n const m = inner.router.getMatch(innerMatch.id)\n if (!m) continue\n Object.assign(context, m.__routeContext, m.__beforeLoadContext)\n }\n return context\n}\n\nconst _handleNotFound = (inner: InnerLoadContext, err: NotFoundError) => {\n // Find the route that should handle the not found error\n // First check if a specific route is requested to show the error\n const routeCursor =\n inner.router.routesById[err.routeId ?? ''] ?? inner.router.routeTree\n\n // Ensure a NotFoundComponent exists on the route\n if (\n !routeCursor.options.notFoundComponent &&\n (inner.router.options as any)?.defaultNotFoundComponent\n ) {\n routeCursor.options.notFoundComponent = (\n inner.router.options as any\n ).defaultNotFoundComponent\n }\n\n // Ensure we have a notFoundComponent\n invariant(\n routeCursor.options.notFoundComponent,\n 'No notFoundComponent found. Please set a notFoundComponent on your route or provide a defaultNotFoundComponent to the router.',\n )\n\n // Find the match for this route\n const matchForRoute = inner.matches.find((m) => m.routeId === routeCursor.id)\n\n invariant(matchForRoute, 'Could not find match for route: ' + routeCursor.id)\n\n // Assign the error to the match - using non-null assertion since we've checked with invariant\n inner.updateMatch(matchForRoute.id, (prev) => ({\n ...prev,\n status: 'notFound',\n error: err,\n isFetching: false,\n }))\n\n if ((err as any).routerCode === 'BEFORE_LOAD' && routeCursor.parentRoute) {\n err.routeId = routeCursor.parentRoute.id\n _handleNotFound(inner, err)\n }\n}\n\nconst handleRedirectAndNotFound = (\n inner: InnerLoadContext,\n match: AnyRouteMatch | undefined,\n err: unknown,\n): void => {\n if (!isRedirect(err) && !isNotFound(err)) return\n\n if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {\n throw err\n }\n\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n match._nonReactive.loaderPromise = undefined\n\n const status = isRedirect(err) ? 'redirected' : 'notFound'\n\n match._nonReactive.error = err\n\n inner.updateMatch(match.id, (prev) => ({\n ...prev,\n status,\n isFetching: false,\n error: err,\n }))\n\n if (isNotFound(err) && !err.routeId) {\n err.routeId = match.routeId\n }\n\n match._nonReactive.loadPromise?.resolve()\n }\n\n if (isRedirect(err)) {\n inner.rendered = true\n err.options._fromLocation = inner.location\n err.redirectHandled = true\n err = inner.router.resolveRedirect(err)\n throw err\n } else {\n _handleNotFound(inner, err)\n throw err\n }\n}\n\nconst shouldSkipLoader = (\n inner: InnerLoadContext,\n matchId: string,\n): boolean => {\n const match = inner.router.getMatch(matchId)!\n // upon hydration, we skip the loader if the match has been dehydrated on the server\n if (!inner.router.isServer && match._nonReactive.dehydrated) {\n return true\n }\n\n if (inner.router.isServer && match.ssr === false) {\n return true\n }\n\n return false\n}\n\nconst handleSerialError = (\n inner: InnerLoadContext,\n index: number,\n err: any,\n routerCode: string,\n): void => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n // Much like suspense, we use a promise here to know if\n // we've been outdated by a new loadMatches call and\n // should abort the current async operation\n if (err instanceof Promise) {\n throw err\n }\n\n err.routerCode = routerCode\n inner.firstBadMatchIndex ??= index\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n\n try {\n route.options.onError?.(err)\n } catch (errorHandlerErr) {\n err = errorHandlerErr\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n }\n\n inner.updateMatch(matchId, (prev) => {\n prev._nonReactive.beforeLoadPromise?.resolve()\n prev._nonReactive.beforeLoadPromise = undefined\n prev._nonReactive.loadPromise?.resolve()\n\n return {\n ...prev,\n error: err,\n status: 'error',\n isFetching: false,\n updatedAt: Date.now(),\n abortController: new AbortController(),\n }\n })\n}\n\nconst isBeforeLoadSsr = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n\n // in SPA mode, only SSR the root route\n if (inner.router.isShell()) {\n existingMatch.ssr = route.id === rootRouteId\n return\n }\n\n if (parentMatch?.ssr === false) {\n existingMatch.ssr = false\n return\n }\n\n const parentOverride = (tempSsr: SSROption) => {\n if (tempSsr === true && parentMatch?.ssr === 'data-only') {\n return 'data-only'\n }\n return tempSsr\n }\n\n const defaultSsr = inner.router.options.defaultSsr ?? true\n\n if (route.options.ssr === undefined) {\n existingMatch.ssr = parentOverride(defaultSsr)\n return\n }\n\n if (typeof route.options.ssr !== 'function') {\n existingMatch.ssr = parentOverride(route.options.ssr)\n return\n }\n const { search, params } = existingMatch\n\n const ssrFnContext: SsrContextOptions<any, any, any> = {\n search: makeMaybe(search, existingMatch.searchError),\n params: makeMaybe(params, existingMatch.paramsError),\n location: inner.location,\n matches: inner.matches.map((match) => ({\n index: match.index,\n pathname: match.pathname,\n fullPath: match.fullPath,\n staticData: match.staticData,\n id: match.id,\n routeId: match.routeId,\n search: makeMaybe(match.search, match.searchError),\n params: makeMaybe(match.params, match.paramsError),\n ssr: match.ssr,\n })),\n }\n\n const tempSsr = route.options.ssr(ssrFnContext)\n if (isPromise(tempSsr)) {\n return tempSsr.then((ssr) => {\n existingMatch.ssr = parentOverride(ssr ?? defaultSsr)\n })\n }\n\n existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr)\n return\n}\n\nconst setupPendingTimeout = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n match: AnyRouteMatch,\n): void => {\n if (match._nonReactive.pendingTimeout !== undefined) return\n\n const pendingMs =\n route.options.pendingMs ?? inner.router.options.defaultPendingMs\n const shouldPending = !!(\n inner.onReady &&\n !inner.router.isServer &&\n !resolvePreload(inner, matchId) &&\n (route.options.loader ||\n route.options.beforeLoad ||\n routeNeedsPreload(route)) &&\n typeof pendingMs === 'number' &&\n pendingMs !== Infinity &&\n (route.options.pendingComponent ??\n (inner.router.options as any)?.defaultPendingComponent)\n )\n\n if (shouldPending) {\n const pendingTimeout = setTimeout(() => {\n // Update the match and prematurely resolve the loadMatches promise so that\n // the pending component can start rendering\n triggerOnReady(inner)\n }, pendingMs)\n match._nonReactive.pendingTimeout = pendingTimeout\n }\n}\n\nconst preBeforeLoadSetup = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n\n // If we are in the middle of a load, either of these will be present\n // (not to be confused with `loadPromise`, which is always defined)\n if (\n !existingMatch._nonReactive.beforeLoadPromise &&\n !existingMatch._nonReactive.loaderPromise\n )\n return\n\n setupPendingTimeout(inner, matchId, route, existingMatch)\n\n const then = () => {\n const match = inner.router.getMatch(matchId)!\n if (\n match.preload &&\n (match.status === 'redirected' || match.status === 'notFound')\n ) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n }\n\n // Wait for the previous beforeLoad to resolve before we continue\n return existingMatch._nonReactive.beforeLoadPromise\n ? existingMatch._nonReactive.beforeLoadPromise.then(then)\n : then()\n}\n\nconst executeBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const match = inner.router.getMatch(matchId)!\n\n // explicitly capture the previous loadPromise\n const prevLoadPromise = match._nonReactive.loadPromise\n match._nonReactive.loadPromise = createControlledPromise<void>(() => {\n prevLoadPromise?.resolve()\n })\n\n const { paramsError, searchError } = match\n\n if (paramsError) {\n handleSerialError(inner, index, paramsError, 'PARSE_PARAMS')\n }\n\n if (searchError) {\n handleSerialError(inner, index, searchError, 'VALIDATE_SEARCH')\n }\n\n setupPendingTimeout(inner, matchId, route, match)\n\n const abortController = new AbortController()\n\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n const parentMatchContext =\n parentMatch?.context ?? inner.router.options.context ?? undefined\n\n let isPending = false\n const pending = () => {\n if (isPending) return\n isPending = true\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'beforeLoad',\n fetchCount: prev.fetchCount + 1,\n abortController,\n // Note: We intentionally don't update context here.\n // Context should only be updated after beforeLoad resolves to avoid\n // components seeing incomplete context during async beforeLoad execution.\n }))\n }\n\n const resolve = () => {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: false,\n }))\n }\n\n // if there is no `beforeLoad` option, just mark as pending and resolve\n // Context will be updated later in loadRouteMatch after loader completes\n if (!route.options.beforeLoad) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n\n match._nonReactive.beforeLoadPromise = createControlledPromise<void>()\n\n // Build context from all parent matches, excluding current match's __beforeLoadContext\n // (since we're about to execute beforeLoad for this match)\n const context = {\n ...buildMatchContext(inner, index, false),\n ...match.__routeContext,\n }\n const { search, params, cause } = match\n const preload = resolvePreload(inner, matchId)\n const beforeLoadFnContext: BeforeLoadContextOptions<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = {\n search,\n abortController,\n params,\n preload,\n context,\n location: inner.location,\n navigate: (opts: any) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n buildLocation: inner.router.buildLocation,\n cause: preload ? 'preload' : cause,\n matches: inner.matches,\n ...inner.router.options.additionalContext,\n }\n\n const updateContext = (beforeLoadContext: any) => {\n if (beforeLoadContext === undefined) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {\n pending()\n handleSerialError(inner, index, beforeLoadContext, 'BEFORE_LOAD')\n }\n\n batch(() => {\n pending()\n // Only store __beforeLoadContext here, don't update context yet\n // Context will be updated in loadRouteMatch after loader completes\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n __beforeLoadContext: beforeLoadContext,\n }))\n resolve()\n })\n }\n\n let beforeLoadContext\n try {\n beforeLoadContext = route.options.beforeLoad(beforeLoadFnContext)\n if (isPromise(beforeLoadContext)) {\n pending()\n return beforeLoadContext\n .catch((err) => {\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n })\n .then(updateContext)\n }\n } catch (err) {\n pending()\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n }\n\n updateContext(beforeLoadContext)\n return\n}\n\nconst handleBeforeLoad = (\n inner: InnerLoadContext,\n index: number,\n): void | Promise<void> => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n const serverSsr = () => {\n // on the server, determine whether SSR the current match or not\n if (inner.router.isServer) {\n const maybePromise = isBeforeLoadSsr(inner, matchId, index, route)\n if (isPromise(maybePromise)) return maybePromise.then(queueExecution)\n }\n return queueExecution()\n }\n\n const execute = () => executeBeforeLoad(inner, matchId, index, route)\n\n const queueExecution = () => {\n if (shouldSkipLoader(inner, matchId)) return\n const result = preBeforeLoadSetup(inner, matchId, route)\n return isPromise(result) ? result.then(execute) : execute()\n }\n\n return serverSsr()\n}\n\nconst executeHead = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<\n Pick<\n AnyRouteMatch,\n 'meta' | 'links' | 'headScripts' | 'headers' | 'scripts' | 'styles'\n >\n> => {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (!match) {\n return\n }\n if (!route.options.head && !route.options.scripts && !route.options.headers) {\n return\n }\n const assetContext = {\n matches: inner.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n\n return Promise.all([\n route.options.head?.(assetContext),\n route.options.scripts?.(assetContext),\n route.options.headers?.(assetContext),\n ]).then(([headFnContent, scripts, headers]) => {\n const meta = headFnContent?.meta\n const links = headFnContent?.links\n const headScripts = headFnContent?.scripts\n const styles = headFnContent?.styles\n\n return {\n meta,\n links,\n headScripts,\n headers,\n scripts,\n styles,\n }\n })\n}\n\nconst getLoaderContext = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): LoaderFnContext => {\n const parentMatchPromise = inner.matchPromises[index - 1] as any\n const { params, loaderDeps, abortController, cause } =\n inner.router.getMatch(matchId)!\n\n const context = buildMatchContext(inner, index)\n\n const preload = resolvePreload(inner, matchId)\n\n return {\n params,\n deps: loaderDeps,\n preload: !!preload,\n parentMatchPromise,\n abortController,\n context,\n location: inner.location,\n navigate: (opts) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n cause: preload ? 'preload' : cause,\n route,\n ...inner.router.options.additionalContext,\n }\n}\n\nconst runLoader = async (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): Promise<void> => {\n try {\n // If the Matches component rendered\n // the pending component and needs to show it for\n // a minimum duration, we''ll wait for it to resolve\n // before committing to the match and resolving\n // the loadPromise\n\n const match = inner.router.getMatch(matchId)!\n\n // Actually run the loader and handle the result\n try {\n if (!inner.router.isServer || match.ssr === true) {\n loadRouteChunk(route)\n }\n\n // Kick off the loader!\n const loaderResult = route.options.loader?.(\n getLoaderContext(inner, matchId, index, route),\n )\n const loaderResultIsPromise =\n route.options.loader && isPromise(loaderResult)\n\n const willLoadSomething = !!(\n loaderResultIsPromise ||\n route._lazyPromise ||\n route._componentsPromise ||\n route.options.head ||\n route.options.scripts ||\n route.options.headers ||\n match._nonReactive.minPendingPromise\n )\n\n if (willLoadSomething) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'loader',\n }))\n }\n\n if (route.options.loader) {\n const loaderData = loaderResultIsPromise\n ? await loaderResult\n : loaderResult\n\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n loaderData,\n )\n if (loaderData !== undefined) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n loaderData,\n }))\n }\n }\n\n // Lazy option can modify the route options,\n // so we need to wait for it to resolve before\n // we can use the options\n if (route._lazyPromise) await route._lazyPromise\n const headResult = executeHead(inner, matchId, route)\n const head = headResult ? await headResult : undefined\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n // Last but not least, wait for the the components\n // to be preloaded before we resolve the match\n if (route._componentsPromise) await route._componentsPromise\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error: undefined,\n status: 'success',\n isFetching: false,\n updatedAt: Date.now(),\n ...head,\n }))\n } catch (e) {\n let error = e\n\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n if (isNotFound(e)) {\n await (route.options.notFoundComponent as any)?.preload?.()\n }\n\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), e)\n\n try {\n route.options.onError?.(e)\n } catch (onErrorError) {\n error = onErrorError\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n onErrorError,\n )\n }\n const headResult = executeHead(inner, matchId, route)\n const head = headResult ? await headResult : undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error,\n status: 'error',\n isFetching: false,\n ...head,\n }))\n }\n } catch (err) {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n match._nonReactive.loaderPromise = undefined\n }\n handleRedirectAndNotFound(inner, match, err)\n }\n}\n\nconst loadRouteMatch = async (\n inner: InnerLoadContext,\n index: number,\n): Promise<AnyRouteMatch> => {\n const { id: matchId, routeId } = inner.matches[index]!\n let loaderShouldRunAsync = false\n let loaderIsRunningAsync = false\n const route = inner.router.looseRoutesById[routeId]!\n\n const commitContext = () => {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n context: buildMatchContext(inner, index),\n }))\n }\n\n if (shouldSkipLoader(inner, matchId)) {\n if (inner.router.isServer) {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n return inner.router.getMatch(matchId)!\n }\n } else {\n const prevMatch = inner.router.getMatch(matchId)!\n // there is a loaderPromise, so we are in the middle of a load\n if (prevMatch._nonReactive.loaderPromise) {\n // do not block if we already have stale data we can show\n // but only if the ongoing load is not a preload since error handling is different for preloads\n // and we don't want to swallow errors\n if (prevMatch.status === 'success' && !inner.sync && !prevMatch.preload) {\n return prevMatch\n }\n await prevMatch._nonReactive.loaderPromise\n const match = inner.router.getMatch(matchId)!\n const error = match._nonReactive.error || match.error\n if (error) {\n handleRedirectAndNotFound(inner, match, error)\n }\n } else {\n // This is where all of the stale-while-revalidate magic happens\n const age = Date.now() - prevMatch.updatedAt\n\n const preload = resolvePreload(inner, matchId)\n\n const staleAge = preload\n ? (route.options.preloadStaleTime ??\n inner.router.options.defaultPreloadStaleTime ??\n 30_000) // 30 seconds for preloads by default\n : (route.options.staleTime ??\n inner.router.options.defaultStaleTime ??\n 0)\n\n const shouldReloadOption = route.options.shouldReload\n\n // Default to reloading the route all the time\n // Allow shouldReload to get the last say,\n // if provided.\n const shouldReload =\n typeof shouldReloadOption === 'function'\n ? shouldReloadOption(getLoaderContext(inner, matchId, index, route))\n : shouldReloadOption\n\n const nextPreload =\n !!preload && !inner.router.state.matches.some((d) => d.id === matchId)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise = createControlledPromise<void>()\n if (nextPreload !== match.preload) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n preload: nextPreload,\n }))\n }\n\n // If the route is successful and still fresh, just resolve\n const { status, invalid } = match\n loaderShouldRunAsync =\n status === 'success' && (invalid || (shouldReload ?? age > staleAge))\n if (preload && route.options.preload === false) {\n // Do nothing\n } else if (loaderShouldRunAsync && !inner.sync) {\n loaderIsRunningAsync = true\n ;(async () => {\n try {\n await runLoader(inner, matchId, index, route)\n commitContext()\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n match._nonReactive.loaderPromise = undefined\n } catch (err) {\n if (isRedirect(err)) {\n await inner.router.navigate(err.options)\n }\n }\n })()\n } else if (status !== 'success' || (loaderShouldRunAsync && inner.sync)) {\n await runLoader(inner, matchId, index, route)\n } else {\n // if the loader did not run, still update head.\n // reason: parent's beforeLoad may have changed the route context\n // and only now do we know the route context (and that the loader would not run)\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n }\n }\n }\n const match = inner.router.getMatch(matchId)!\n if (!loaderIsRunningAsync) {\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n }\n\n clearTimeout(match._nonReactive.pendingTimeout)\n match._nonReactive.pendingTimeout = undefined\n if (!loaderIsRunningAsync) match._nonReactive.loaderPromise = undefined\n match._nonReactive.dehydrated = undefined\n\n // Commit context now that loader has completed (or was skipped)\n // For async loaders, this was already done in the async callback\n if (!loaderIsRunningAsync) {\n commitContext()\n }\n\n const nextIsFetching = loaderIsRunningAsync ? match.isFetching : false\n if (nextIsFetching !== match.isFetching || match.invalid !== false) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: nextIsFetching,\n invalid: false,\n }))\n return inner.router.getMatch(matchId)!\n } else {\n return match\n }\n}\n\nexport async function loadMatches(arg: {\n router: AnyRouter\n location: ParsedLocation\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n updateMatch: UpdateMatchFn\n sync?: boolean\n}): Promise<Array<MakeRouteMatch>> {\n const inner: InnerLoadContext = Object.assign(arg, {\n matchPromises: [],\n })\n\n // make sure the pending component is immediately rendered when hydrating a match that is not SSRed\n // the pending component was already rendered on the server and we want to keep it shown on the client until minPendingMs is reached\n if (\n !inner.router.isServer &&\n inner.router.state.matches.some((d) => d._forcePending)\n ) {\n triggerOnReady(inner)\n }\n\n try {\n // Execute all beforeLoads one by one\n for (let i = 0; i < inner.matches.length; i++) {\n const beforeLoad = handleBeforeLoad(inner, i)\n if (isPromise(beforeLoad)) await beforeLoad\n }\n\n // Execute all loaders in parallel\n const max = inner.firstBadMatchIndex ?? inner.matches.length\n for (let i = 0; i < max; i++) {\n inner.matchPromises.push(loadRouteMatch(inner, i))\n }\n await Promise.all(inner.matchPromises)\n\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n } catch (err) {\n if (isNotFound(err) && !inner.preload) {\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n throw err\n }\n if (isRedirect(err)) {\n throw err\n }\n }\n\n return inner.matches\n}\n\nexport async function loadRouteChunk(route: AnyRoute) {\n if (!route._lazyLoaded && route._lazyPromise === undefined) {\n if (route.lazyFn) {\n route._lazyPromise = route.lazyFn().then((lazyRoute) => {\n // explicitly don't copy over the lazy route's id\n const { id: _id, ...options } = lazyRoute.options\n Object.assign(route.options, options)\n route._lazyLoaded = true\n route._lazyPromise = undefined // gc promise, we won't need it anymore\n })\n } else {\n route._lazyLoaded = true\n }\n }\n\n // If for some reason lazy resolves more lazy components...\n // We'll wait for that before we attempt to preload the\n // components themselves.\n if (!route._componentsLoaded && route._componentsPromise === undefined) {\n const loadComponents = () => {\n const preloads = []\n for (const type of componentTypes) {\n const preload = (route.options[type] as any)?.preload\n if (preload) preloads.push(preload())\n }\n if (preloads.length)\n return Promise.all(preloads).then(() => {\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n })\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n return\n }\n route._componentsPromise = route._lazyPromise\n ? route._lazyPromise.then(loadComponents)\n : loadComponents()\n }\n return route._componentsPromise\n}\n\nfunction makeMaybe<TValue, TError>(\n value: TValue,\n error: TError,\n): { status: 'success'; value: TValue } | { status: 'error'; error: TError } {\n if (error) {\n return { status: 'error' as const, error }\n }\n return { status: 'success' as const, value }\n}\n\nexport function routeNeedsPreload(route: AnyRoute) {\n for (const componentType of componentTypes) {\n if ((route.options[componentType] as any)?.preload) {\n return true\n }\n }\n return false\n}\n\nexport const componentTypes = [\n 'component',\n 'errorComponent',\n 'pendingComponent',\n 'notFoundComponent',\n] as const\n"],"names":["isRedirect","isNotFound","rootRouteId","tempSsr","isPromise","createControlledPromise","batch","beforeLoadContext","match"],"mappings":";;;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C1B,YAAM,qBAAqB;AAC3B;AAAA,IACF;AACA,UAAM,qBAAqB,MAAM,eAC7B,MAAM,aAAa,KAAK,cAAc,IACtC,eAAA;AAAA,EACN;AACA,SAAO,MAAM;AACf;AAEA,SAAS,UACP,OACA,OAC2E;AAC3E,MAAI,OAAO;AACT,WAAO,EAAE,QAAQ,SAAkB,MAAA;AAAA,EACrC;AACA,SAAO,EAAE,QAAQ,WAAoB,MAAA;AACvC;AAEO,SAAS,kBAAkB,OAAiB;AACjD,aAAW,iBAAiB,gBAAgB;AAC1C,QAAK,MAAM,QAAQ,aAAa,GAAW,SAAS;AAClD,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;;;"}
1
+ {"version":3,"file":"load-matches.cjs","sources":["../../src/load-matches.ts"],"sourcesContent":["import { batch } from '@tanstack/store'\nimport invariant from 'tiny-invariant'\nimport { createControlledPromise, isPromise } from './utils'\nimport { isNotFound } from './not-found'\nimport { rootRouteId } from './root'\nimport { isRedirect } from './redirect'\nimport type { NotFoundError } from './not-found'\nimport type { ParsedLocation } from './location'\nimport type {\n AnyRoute,\n BeforeLoadContextOptions,\n LoaderFnContext,\n SsrContextOptions,\n} from './route'\nimport type { AnyRouteMatch, MakeRouteMatch } from './Matches'\nimport type { AnyRouter, SSROption, UpdateMatchFn } from './router'\n\n/**\n * An object of this shape is created when calling `loadMatches`.\n * It contains everything we need for all other functions in this file\n * to work. (It's basically the function's argument, plus a few mutable states)\n */\ntype InnerLoadContext = {\n /** the calling router instance */\n router: AnyRouter\n location: ParsedLocation\n /** mutable state, scoped to a `loadMatches` call */\n firstBadMatchIndex?: number\n /** mutable state, scoped to a `loadMatches` call */\n rendered?: boolean\n updateMatch: UpdateMatchFn\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n sync?: boolean\n /** mutable state, scoped to a `loadMatches` call */\n matchPromises: Array<Promise<AnyRouteMatch>>\n}\n\nconst triggerOnReady = (inner: InnerLoadContext): void | Promise<void> => {\n if (!inner.rendered) {\n inner.rendered = true\n return inner.onReady?.()\n }\n}\n\nconst resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {\n return !!(\n inner.preload && !inner.router.state.matches.some((d) => d.id === matchId)\n )\n}\n\n/**\n * Builds the accumulated context from router options and all matches up to (and optionally including) the given index.\n * Merges __routeContext and __beforeLoadContext from each match.\n */\nconst buildMatchContext = (\n inner: InnerLoadContext,\n index: number,\n includeCurrentMatch: boolean = true,\n): Record<string, unknown> => {\n const context: Record<string, unknown> = {\n ...(inner.router.options.context ?? {}),\n }\n const end = includeCurrentMatch ? index : index - 1\n for (let i = 0; i <= end; i++) {\n const innerMatch = inner.matches[i]\n if (!innerMatch) continue\n const m = inner.router.getMatch(innerMatch.id)\n if (!m) continue\n Object.assign(context, m.__routeContext, m.__beforeLoadContext)\n }\n return context\n}\n\nconst _handleNotFound = (inner: InnerLoadContext, err: NotFoundError) => {\n // Find the route that should handle the not found error\n // First check if a specific route is requested to show the error\n const routeCursor =\n inner.router.routesById[err.routeId ?? ''] ?? inner.router.routeTree\n\n // Ensure a NotFoundComponent exists on the route\n if (\n !routeCursor.options.notFoundComponent &&\n (inner.router.options as any)?.defaultNotFoundComponent\n ) {\n routeCursor.options.notFoundComponent = (\n inner.router.options as any\n ).defaultNotFoundComponent\n }\n\n // Ensure we have a notFoundComponent\n invariant(\n routeCursor.options.notFoundComponent,\n 'No notFoundComponent found. Please set a notFoundComponent on your route or provide a defaultNotFoundComponent to the router.',\n )\n\n // Find the match for this route\n const matchForRoute = inner.matches.find((m) => m.routeId === routeCursor.id)\n\n invariant(matchForRoute, 'Could not find match for route: ' + routeCursor.id)\n\n // Assign the error to the match - using non-null assertion since we've checked with invariant\n inner.updateMatch(matchForRoute.id, (prev) => ({\n ...prev,\n status: 'notFound',\n error: err,\n isFetching: false,\n }))\n\n if ((err as any).routerCode === 'BEFORE_LOAD' && routeCursor.parentRoute) {\n err.routeId = routeCursor.parentRoute.id\n _handleNotFound(inner, err)\n }\n}\n\nconst handleRedirectAndNotFound = (\n inner: InnerLoadContext,\n match: AnyRouteMatch | undefined,\n err: unknown,\n): void => {\n if (!isRedirect(err) && !isNotFound(err)) return\n\n if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {\n throw err\n }\n\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n match._nonReactive.loaderPromise = undefined\n\n const status = isRedirect(err) ? 'redirected' : 'notFound'\n\n match._nonReactive.error = err\n\n inner.updateMatch(match.id, (prev) => ({\n ...prev,\n status,\n isFetching: false,\n error: err,\n }))\n\n if (isNotFound(err) && !err.routeId) {\n err.routeId = match.routeId\n }\n\n match._nonReactive.loadPromise?.resolve()\n }\n\n if (isRedirect(err)) {\n inner.rendered = true\n err.options._fromLocation = inner.location\n err.redirectHandled = true\n err = inner.router.resolveRedirect(err)\n throw err\n } else {\n _handleNotFound(inner, err)\n throw err\n }\n}\n\nconst shouldSkipLoader = (\n inner: InnerLoadContext,\n matchId: string,\n): boolean => {\n const match = inner.router.getMatch(matchId)!\n // upon hydration, we skip the loader if the match has been dehydrated on the server\n if (!inner.router.isServer && match._nonReactive.dehydrated) {\n return true\n }\n\n if (inner.router.isServer && match.ssr === false) {\n return true\n }\n\n return false\n}\n\nconst handleSerialError = (\n inner: InnerLoadContext,\n index: number,\n err: any,\n routerCode: string,\n): void => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n // Much like suspense, we use a promise here to know if\n // we've been outdated by a new loadMatches call and\n // should abort the current async operation\n if (err instanceof Promise) {\n throw err\n }\n\n err.routerCode = routerCode\n inner.firstBadMatchIndex ??= index\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n\n try {\n route.options.onError?.(err)\n } catch (errorHandlerErr) {\n err = errorHandlerErr\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n }\n\n inner.updateMatch(matchId, (prev) => {\n prev._nonReactive.beforeLoadPromise?.resolve()\n prev._nonReactive.beforeLoadPromise = undefined\n prev._nonReactive.loadPromise?.resolve()\n\n return {\n ...prev,\n error: err,\n status: 'error',\n isFetching: false,\n updatedAt: Date.now(),\n abortController: new AbortController(),\n }\n })\n}\n\nconst isBeforeLoadSsr = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n\n // in SPA mode, only SSR the root route\n if (inner.router.isShell()) {\n existingMatch.ssr = route.id === rootRouteId\n return\n }\n\n if (parentMatch?.ssr === false) {\n existingMatch.ssr = false\n return\n }\n\n const parentOverride = (tempSsr: SSROption) => {\n if (tempSsr === true && parentMatch?.ssr === 'data-only') {\n return 'data-only'\n }\n return tempSsr\n }\n\n const defaultSsr = inner.router.options.defaultSsr ?? true\n\n if (route.options.ssr === undefined) {\n existingMatch.ssr = parentOverride(defaultSsr)\n return\n }\n\n if (typeof route.options.ssr !== 'function') {\n existingMatch.ssr = parentOverride(route.options.ssr)\n return\n }\n const { search, params } = existingMatch\n\n const ssrFnContext: SsrContextOptions<any, any, any> = {\n search: makeMaybe(search, existingMatch.searchError),\n params: makeMaybe(params, existingMatch.paramsError),\n location: inner.location,\n matches: inner.matches.map((match) => ({\n index: match.index,\n pathname: match.pathname,\n fullPath: match.fullPath,\n staticData: match.staticData,\n id: match.id,\n routeId: match.routeId,\n search: makeMaybe(match.search, match.searchError),\n params: makeMaybe(match.params, match.paramsError),\n ssr: match.ssr,\n })),\n }\n\n const tempSsr = route.options.ssr(ssrFnContext)\n if (isPromise(tempSsr)) {\n return tempSsr.then((ssr) => {\n existingMatch.ssr = parentOverride(ssr ?? defaultSsr)\n })\n }\n\n existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr)\n return\n}\n\nconst setupPendingTimeout = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n match: AnyRouteMatch,\n): void => {\n if (match._nonReactive.pendingTimeout !== undefined) return\n\n const pendingMs =\n route.options.pendingMs ?? inner.router.options.defaultPendingMs\n const shouldPending = !!(\n inner.onReady &&\n !inner.router.isServer &&\n !resolvePreload(inner, matchId) &&\n (route.options.loader ||\n route.options.beforeLoad ||\n routeNeedsPreload(route)) &&\n typeof pendingMs === 'number' &&\n pendingMs !== Infinity &&\n (route.options.pendingComponent ??\n (inner.router.options as any)?.defaultPendingComponent)\n )\n\n if (shouldPending) {\n const pendingTimeout = setTimeout(() => {\n // Update the match and prematurely resolve the loadMatches promise so that\n // the pending component can start rendering\n triggerOnReady(inner)\n }, pendingMs)\n match._nonReactive.pendingTimeout = pendingTimeout\n }\n}\n\nconst preBeforeLoadSetup = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n\n // If we are in the middle of a load, either of these will be present\n // (not to be confused with `loadPromise`, which is always defined)\n if (\n !existingMatch._nonReactive.beforeLoadPromise &&\n !existingMatch._nonReactive.loaderPromise\n )\n return\n\n setupPendingTimeout(inner, matchId, route, existingMatch)\n\n const then = () => {\n const match = inner.router.getMatch(matchId)!\n if (\n match.preload &&\n (match.status === 'redirected' || match.status === 'notFound')\n ) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n }\n\n // Wait for the previous beforeLoad to resolve before we continue\n return existingMatch._nonReactive.beforeLoadPromise\n ? existingMatch._nonReactive.beforeLoadPromise.then(then)\n : then()\n}\n\nconst executeBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const match = inner.router.getMatch(matchId)!\n\n // explicitly capture the previous loadPromise\n const prevLoadPromise = match._nonReactive.loadPromise\n match._nonReactive.loadPromise = createControlledPromise<void>(() => {\n prevLoadPromise?.resolve()\n })\n\n const { paramsError, searchError } = match\n\n if (paramsError) {\n handleSerialError(inner, index, paramsError, 'PARSE_PARAMS')\n }\n\n if (searchError) {\n handleSerialError(inner, index, searchError, 'VALIDATE_SEARCH')\n }\n\n setupPendingTimeout(inner, matchId, route, match)\n\n const abortController = new AbortController()\n\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n const parentMatchContext =\n parentMatch?.context ?? inner.router.options.context ?? undefined\n\n let isPending = false\n const pending = () => {\n if (isPending) return\n isPending = true\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'beforeLoad',\n fetchCount: prev.fetchCount + 1,\n abortController,\n // Note: We intentionally don't update context here.\n // Context should only be updated after beforeLoad resolves to avoid\n // components seeing incomplete context during async beforeLoad execution.\n }))\n }\n\n const resolve = () => {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: false,\n }))\n }\n\n // if there is no `beforeLoad` option, just mark as pending and resolve\n // Context will be updated later in loadRouteMatch after loader completes\n if (!route.options.beforeLoad) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n\n match._nonReactive.beforeLoadPromise = createControlledPromise<void>()\n\n // Build context from all parent matches, excluding current match's __beforeLoadContext\n // (since we're about to execute beforeLoad for this match)\n const context = {\n ...buildMatchContext(inner, index, false),\n ...match.__routeContext,\n }\n const { search, params, cause } = match\n const preload = resolvePreload(inner, matchId)\n const beforeLoadFnContext: BeforeLoadContextOptions<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = {\n search,\n abortController,\n params,\n preload,\n context,\n location: inner.location,\n navigate: (opts: any) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n buildLocation: inner.router.buildLocation,\n cause: preload ? 'preload' : cause,\n matches: inner.matches,\n ...inner.router.options.additionalContext,\n }\n\n const updateContext = (beforeLoadContext: any) => {\n if (beforeLoadContext === undefined) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {\n pending()\n handleSerialError(inner, index, beforeLoadContext, 'BEFORE_LOAD')\n }\n\n batch(() => {\n pending()\n // Only store __beforeLoadContext here, don't update context yet\n // Context will be updated in loadRouteMatch after loader completes\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n __beforeLoadContext: beforeLoadContext,\n }))\n resolve()\n })\n }\n\n let beforeLoadContext\n try {\n beforeLoadContext = route.options.beforeLoad(beforeLoadFnContext)\n if (isPromise(beforeLoadContext)) {\n pending()\n return beforeLoadContext\n .catch((err) => {\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n })\n .then(updateContext)\n }\n } catch (err) {\n pending()\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n }\n\n updateContext(beforeLoadContext)\n return\n}\n\nconst handleBeforeLoad = (\n inner: InnerLoadContext,\n index: number,\n): void | Promise<void> => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n const serverSsr = () => {\n // on the server, determine whether SSR the current match or not\n if (inner.router.isServer) {\n const maybePromise = isBeforeLoadSsr(inner, matchId, index, route)\n if (isPromise(maybePromise)) return maybePromise.then(queueExecution)\n }\n return queueExecution()\n }\n\n const execute = () => executeBeforeLoad(inner, matchId, index, route)\n\n const queueExecution = () => {\n if (shouldSkipLoader(inner, matchId)) return\n const result = preBeforeLoadSetup(inner, matchId, route)\n return isPromise(result) ? result.then(execute) : execute()\n }\n\n return serverSsr()\n}\n\nconst executeHead = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<\n Pick<\n AnyRouteMatch,\n 'meta' | 'links' | 'headScripts' | 'headers' | 'scripts' | 'styles'\n >\n> => {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (!match) {\n return\n }\n if (!route.options.head && !route.options.scripts && !route.options.headers) {\n return\n }\n const assetContext = {\n matches: inner.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n\n return Promise.all([\n route.options.head?.(assetContext),\n route.options.scripts?.(assetContext),\n route.options.headers?.(assetContext),\n ]).then(([headFnContent, scripts, headers]) => {\n const meta = headFnContent?.meta\n const links = headFnContent?.links\n const headScripts = headFnContent?.scripts\n const styles = headFnContent?.styles\n\n return {\n meta,\n links,\n headScripts,\n headers,\n scripts,\n styles,\n }\n })\n}\n\nconst getLoaderContext = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): LoaderFnContext => {\n const parentMatchPromise = inner.matchPromises[index - 1] as any\n const { params, loaderDeps, abortController, cause } =\n inner.router.getMatch(matchId)!\n\n const context = buildMatchContext(inner, index)\n\n const preload = resolvePreload(inner, matchId)\n\n return {\n params,\n deps: loaderDeps,\n preload: !!preload,\n parentMatchPromise,\n abortController,\n context,\n location: inner.location,\n navigate: (opts) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n cause: preload ? 'preload' : cause,\n route,\n ...inner.router.options.additionalContext,\n }\n}\n\nconst runLoader = async (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): Promise<void> => {\n try {\n // If the Matches component rendered\n // the pending component and needs to show it for\n // a minimum duration, we''ll wait for it to resolve\n // before committing to the match and resolving\n // the loadPromise\n\n const match = inner.router.getMatch(matchId)!\n\n // Actually run the loader and handle the result\n try {\n if (!inner.router.isServer || match.ssr === true) {\n loadRouteChunk(route)\n }\n\n // Kick off the loader!\n const loaderResult = route.options.loader?.(\n getLoaderContext(inner, matchId, index, route),\n )\n const loaderResultIsPromise =\n route.options.loader && isPromise(loaderResult)\n\n const willLoadSomething = !!(\n loaderResultIsPromise ||\n route._lazyPromise ||\n route._componentsPromise ||\n route.options.head ||\n route.options.scripts ||\n route.options.headers ||\n match._nonReactive.minPendingPromise\n )\n\n if (willLoadSomething) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'loader',\n }))\n }\n\n if (route.options.loader) {\n const loaderData = loaderResultIsPromise\n ? await loaderResult\n : loaderResult\n\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n loaderData,\n )\n if (loaderData !== undefined) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n loaderData,\n }))\n }\n }\n\n // Lazy option can modify the route options,\n // so we need to wait for it to resolve before\n // we can use the options\n if (route._lazyPromise) await route._lazyPromise\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n // Last but not least, wait for the the components\n // to be preloaded before we resolve the match\n if (route._componentsPromise) await route._componentsPromise\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error: undefined,\n status: 'success',\n isFetching: false,\n updatedAt: Date.now(),\n }))\n } catch (e) {\n let error = e\n\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n if (isNotFound(e)) {\n await (route.options.notFoundComponent as any)?.preload?.()\n }\n\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), e)\n\n try {\n route.options.onError?.(e)\n } catch (onErrorError) {\n error = onErrorError\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n onErrorError,\n )\n }\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error,\n status: 'error',\n isFetching: false,\n }))\n }\n } catch (err) {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.loaderPromise = undefined\n }\n handleRedirectAndNotFound(inner, match, err)\n }\n}\n\nconst loadRouteMatch = async (\n inner: InnerLoadContext,\n index: number,\n): Promise<AnyRouteMatch> => {\n const { id: matchId, routeId } = inner.matches[index]!\n let loaderShouldRunAsync = false\n let loaderIsRunningAsync = false\n const route = inner.router.looseRoutesById[routeId]!\n\n const commitContext = () => {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n context: buildMatchContext(inner, index),\n }))\n }\n\n if (shouldSkipLoader(inner, matchId)) {\n if (inner.router.isServer) {\n return inner.router.getMatch(matchId)!\n }\n } else {\n const prevMatch = inner.router.getMatch(matchId)!\n // there is a loaderPromise, so we are in the middle of a load\n if (prevMatch._nonReactive.loaderPromise) {\n // do not block if we already have stale data we can show\n // but only if the ongoing load is not a preload since error handling is different for preloads\n // and we don't want to swallow errors\n if (prevMatch.status === 'success' && !inner.sync && !prevMatch.preload) {\n return prevMatch\n }\n await prevMatch._nonReactive.loaderPromise\n const match = inner.router.getMatch(matchId)!\n const error = match._nonReactive.error || match.error\n if (error) {\n handleRedirectAndNotFound(inner, match, error)\n }\n } else {\n // This is where all of the stale-while-revalidate magic happens\n const age = Date.now() - prevMatch.updatedAt\n\n const preload = resolvePreload(inner, matchId)\n\n const staleAge = preload\n ? (route.options.preloadStaleTime ??\n inner.router.options.defaultPreloadStaleTime ??\n 30_000) // 30 seconds for preloads by default\n : (route.options.staleTime ??\n inner.router.options.defaultStaleTime ??\n 0)\n\n const shouldReloadOption = route.options.shouldReload\n\n // Default to reloading the route all the time\n // Allow shouldReload to get the last say,\n // if provided.\n const shouldReload =\n typeof shouldReloadOption === 'function'\n ? shouldReloadOption(getLoaderContext(inner, matchId, index, route))\n : shouldReloadOption\n\n const nextPreload =\n !!preload && !inner.router.state.matches.some((d) => d.id === matchId)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise = createControlledPromise<void>()\n if (nextPreload !== match.preload) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n preload: nextPreload,\n }))\n }\n\n // If the route is successful and still fresh, just resolve\n const { status, invalid } = match\n loaderShouldRunAsync =\n status === 'success' && (invalid || (shouldReload ?? age > staleAge))\n if (preload && route.options.preload === false) {\n // Do nothing\n } else if (loaderShouldRunAsync && !inner.sync) {\n loaderIsRunningAsync = true\n ;(async () => {\n try {\n await runLoader(inner, matchId, index, route)\n commitContext()\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n match._nonReactive.loaderPromise = undefined\n } catch (err) {\n if (isRedirect(err)) {\n await inner.router.navigate(err.options)\n }\n }\n })()\n } else if (status !== 'success' || (loaderShouldRunAsync && inner.sync)) {\n await runLoader(inner, matchId, index, route)\n }\n }\n }\n const match = inner.router.getMatch(matchId)!\n if (!loaderIsRunningAsync) {\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n }\n\n clearTimeout(match._nonReactive.pendingTimeout)\n match._nonReactive.pendingTimeout = undefined\n if (!loaderIsRunningAsync) match._nonReactive.loaderPromise = undefined\n match._nonReactive.dehydrated = undefined\n\n // Commit context now that loader has completed (or was skipped)\n // For async loaders, this was already done in the async callback\n if (!loaderIsRunningAsync) {\n commitContext()\n }\n\n const nextIsFetching = loaderIsRunningAsync ? match.isFetching : false\n if (nextIsFetching !== match.isFetching || match.invalid !== false) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: nextIsFetching,\n invalid: false,\n }))\n return inner.router.getMatch(matchId)!\n } else {\n return match\n }\n}\n\nexport async function loadMatches(arg: {\n router: AnyRouter\n location: ParsedLocation\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n updateMatch: UpdateMatchFn\n sync?: boolean\n}): Promise<Array<MakeRouteMatch>> {\n const inner: InnerLoadContext = Object.assign(arg, {\n matchPromises: [],\n })\n\n // make sure the pending component is immediately rendered when hydrating a match that is not SSRed\n // the pending component was already rendered on the server and we want to keep it shown on the client until minPendingMs is reached\n if (\n !inner.router.isServer &&\n inner.router.state.matches.some((d) => d._forcePending)\n ) {\n triggerOnReady(inner)\n }\n\n try {\n // Execute all beforeLoads one by one\n for (let i = 0; i < inner.matches.length; i++) {\n const beforeLoad = handleBeforeLoad(inner, i)\n if (isPromise(beforeLoad)) await beforeLoad\n }\n\n // Execute all loaders in parallel\n const max = inner.firstBadMatchIndex ?? inner.matches.length\n for (let i = 0; i < max; i++) {\n inner.matchPromises.push(loadRouteMatch(inner, i))\n }\n // Use allSettled to ensure all loaders complete regardless of success/failure\n const results = await Promise.allSettled(inner.matchPromises)\n\n const failures = results\n // TODO when we drop support for TS 5.4, we can use the built-in type guard for PromiseRejectedResult\n .filter(\n (result): result is PromiseRejectedResult =>\n result.status === 'rejected',\n )\n .map((result) => result.reason)\n\n // Find first redirect (throw immediately) or notFound (throw after head execution)\n let firstNotFound: unknown\n for (const err of failures) {\n if (isRedirect(err)) {\n throw err\n }\n if (!firstNotFound && isNotFound(err)) {\n firstNotFound = err\n }\n }\n\n // serially execute head functions after all loaders have completed (successfully or not)\n // Each head execution is wrapped in try-catch to ensure all heads run even if one fails\n for (const match of inner.matches) {\n const { id: matchId, routeId } = match\n const route = inner.router.looseRoutesById[routeId]!\n try {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n } catch (err) {\n // Log error but continue executing other head functions\n console.error(`Error executing head for route ${routeId}:`, err)\n }\n }\n\n // Throw notFound after head execution\n if (firstNotFound) {\n throw firstNotFound\n }\n\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n } catch (err) {\n if (isNotFound(err) && !inner.preload) {\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n throw err\n }\n if (isRedirect(err)) {\n throw err\n }\n }\n return inner.matches\n}\n\nexport async function loadRouteChunk(route: AnyRoute) {\n if (!route._lazyLoaded && route._lazyPromise === undefined) {\n if (route.lazyFn) {\n route._lazyPromise = route.lazyFn().then((lazyRoute) => {\n // explicitly don't copy over the lazy route's id\n const { id: _id, ...options } = lazyRoute.options\n Object.assign(route.options, options)\n route._lazyLoaded = true\n route._lazyPromise = undefined // gc promise, we won't need it anymore\n })\n } else {\n route._lazyLoaded = true\n }\n }\n\n // If for some reason lazy resolves more lazy components...\n // We'll wait for that before we attempt to preload the\n // components themselves.\n if (!route._componentsLoaded && route._componentsPromise === undefined) {\n const loadComponents = () => {\n const preloads = []\n for (const type of componentTypes) {\n const preload = (route.options[type] as any)?.preload\n if (preload) preloads.push(preload())\n }\n if (preloads.length)\n return Promise.all(preloads).then(() => {\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n })\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n return\n }\n route._componentsPromise = route._lazyPromise\n ? route._lazyPromise.then(loadComponents)\n : loadComponents()\n }\n return route._componentsPromise\n}\n\nfunction makeMaybe<TValue, TError>(\n value: TValue,\n error: TError,\n): { status: 'success'; value: TValue } | { status: 'error'; error: TError } {\n if (error) {\n return { status: 'error' as const, error }\n }\n return { status: 'success' as const, value }\n}\n\nexport function routeNeedsPreload(route: AnyRoute) {\n for (const componentType of componentTypes) {\n if ((route.options[componentType] as any)?.preload) {\n return true\n }\n }\n return false\n}\n\nexport const componentTypes = [\n 'component',\n 'errorComponent',\n 'pendingComponent',\n 'notFoundComponent',\n] as const\n"],"names":["isRedirect","isNotFound","rootRouteId","tempSsr","isPromise","createControlledPromise","batch","beforeLoadContext","match"],"mappings":";;;;;;;;AAuCA,MAAM,iBAAiB,CAAC,UAAkD;AACxE,MAAI,CAAC,MAAM,UAAU;AACnB,UAAM,WAAW;AACjB,WAAO,MAAM,UAAA;AAAA,EACf;AACF;AAEA,MAAM,iBAAiB,CAAC,OAAyB,YAA6B;AAC5E,SAAO,CAAC,EACN,MAAM,WAAW,CAAC,MAAM,OAAO,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO;AAE7E;AAMA,MAAM,oBAAoB,CACxB,OACA,OACA,sBAA+B,SACH;AAC5B,QAAM,UAAmC;AAAA,IACvC,GAAI,MAAM,OAAO,QAAQ,WAAW,CAAA;AAAA,EAAC;AAEvC,QAAM,M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EO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;;;"}
@@ -1,14 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const headers = require("./headers.cjs");
4
3
  function json(payload, init) {
5
- return new Response(JSON.stringify(payload), {
6
- ...init,
7
- headers: headers.mergeHeaders(
8
- { "content-type": "application/json" },
9
- init?.headers
10
- )
11
- });
4
+ return Response.json(payload, init);
12
5
  }
13
6
  exports.json = json;
14
7
  //# sourceMappingURL=json.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"json.cjs","sources":["../../../src/ssr/json.ts"],"sourcesContent":["import { mergeHeaders } from './headers'\n\nexport interface JsonResponse<TData> extends Response {\n json: () => Promise<TData>\n}\n\nexport function json<TData>(\n payload: TData,\n init?: ResponseInit,\n): JsonResponse<TData> {\n return new Response(JSON.stringify(payload), {\n ...init,\n headers: mergeHeaders(\n { 'content-type': 'application/json' },\n init?.headers,\n ),\n })\n}\n"],"names":["mergeHeaders"],"mappings":";;;AAMO,SAAS,KACd,SACA,MACqB;AACrB,SAAO,IAAI,SAAS,KAAK,UAAU,OAAO,GAAG;AAAA,IAC3C,GAAG;AAAA,IACH,SAASA,QAAAA;AAAAA,MACP,EAAE,gBAAgB,mBAAA;AAAA,MAClB,MAAM;AAAA,IAAA;AAAA,EACR,CACD;AACH;;"}
1
+ {"version":3,"file":"json.cjs","sources":["../../../src/ssr/json.ts"],"sourcesContent":["/**\n * @deprecated Use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) from the standard Web API directly.\n */\nexport interface JsonResponse<TData> extends Response {\n json: () => Promise<TData>\n}\n\n/**\n * @deprecated Use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) from the standard Web API directly.\n */\nexport function json<TData>(\n payload: TData,\n init?: ResponseInit,\n): JsonResponse<TData> {\n return Response.json(payload, init)\n}\n"],"names":[],"mappings":";;AAUO,SAAS,KACd,SACA,MACqB;AACrB,SAAO,SAAS,KAAK,SAAS,IAAI;AACpC;;"}
@@ -1,4 +1,10 @@
1
+ /**
2
+ * @deprecated Use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) from the standard Web API directly.
3
+ */
1
4
  export interface JsonResponse<TData> extends Response {
2
5
  json: () => Promise<TData>;
3
6
  }
7
+ /**
8
+ * @deprecated Use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) from the standard Web API directly.
9
+ */
4
10
  export declare function json<TData>(payload: TData, init?: ResponseInit): JsonResponse<TData>;
@@ -412,8 +412,6 @@ const runLoader = async (inner, matchId, index, route) => {
412
412
  }
413
413
  }
414
414
  if (route._lazyPromise) await route._lazyPromise;
415
- const headResult = executeHead(inner, matchId, route);
416
- const head = headResult ? await headResult : void 0;
417
415
  const pendingPromise = match._nonReactive.minPendingPromise;
418
416
  if (pendingPromise) await pendingPromise;
419
417
  if (route._componentsPromise) await route._componentsPromise;
@@ -422,8 +420,7 @@ const runLoader = async (inner, matchId, index, route) => {
422
420
  error: void 0,
423
421
  status: "success",
424
422
  isFetching: false,
425
- updatedAt: Date.now(),
426
- ...head
423
+ updatedAt: Date.now()
427
424
  }));
428
425
  } catch (e) {
429
426
  let error = e;
@@ -443,27 +440,16 @@ const runLoader = async (inner, matchId, index, route) => {
443
440
  onErrorError
444
441
  );
445
442
  }
446
- const headResult = executeHead(inner, matchId, route);
447
- const head = headResult ? await headResult : void 0;
448
443
  inner.updateMatch(matchId, (prev) => ({
449
444
  ...prev,
450
445
  error,
451
446
  status: "error",
452
- isFetching: false,
453
- ...head
447
+ isFetching: false
454
448
  }));
455
449
  }
456
450
  } catch (err) {
457
451
  const match = inner.router.getMatch(matchId);
458
452
  if (match) {
459
- const headResult = executeHead(inner, matchId, route);
460
- if (headResult) {
461
- const head = await headResult;
462
- inner.updateMatch(matchId, (prev) => ({
463
- ...prev,
464
- ...head
465
- }));
466
- }
467
453
  match._nonReactive.loaderPromise = void 0;
468
454
  }
469
455
  handleRedirectAndNotFound(inner, match, err);
@@ -482,14 +468,6 @@ const loadRouteMatch = async (inner, index) => {
482
468
  };
483
469
  if (shouldSkipLoader(inner, matchId)) {
484
470
  if (inner.router.isServer) {
485
- const headResult = executeHead(inner, matchId, route);
486
- if (headResult) {
487
- const head = await headResult;
488
- inner.updateMatch(matchId, (prev) => ({
489
- ...prev,
490
- ...head
491
- }));
492
- }
493
471
  return inner.router.getMatch(matchId);
494
472
  }
495
473
  } else {
@@ -540,15 +518,6 @@ const loadRouteMatch = async (inner, index) => {
540
518
  })();
541
519
  } else if (status !== "success" || loaderShouldRunAsync && inner.sync) {
542
520
  await runLoader(inner, matchId, index, route);
543
- } else {
544
- const headResult = executeHead(inner, matchId, route);
545
- if (headResult) {
546
- const head = await headResult;
547
- inner.updateMatch(matchId, (prev) => ({
548
- ...prev,
549
- ...head
550
- }));
551
- }
552
521
  }
553
522
  }
554
523
  }
@@ -592,7 +561,38 @@ async function loadMatches(arg) {
592
561
  for (let i = 0; i < max; i++) {
593
562
  inner.matchPromises.push(loadRouteMatch(inner, i));
594
563
  }
595
- await Promise.all(inner.matchPromises);
564
+ const results = await Promise.allSettled(inner.matchPromises);
565
+ const failures = results.filter(
566
+ (result) => result.status === "rejected"
567
+ ).map((result) => result.reason);
568
+ let firstNotFound;
569
+ for (const err of failures) {
570
+ if (isRedirect(err)) {
571
+ throw err;
572
+ }
573
+ if (!firstNotFound && isNotFound(err)) {
574
+ firstNotFound = err;
575
+ }
576
+ }
577
+ for (const match of inner.matches) {
578
+ const { id: matchId, routeId } = match;
579
+ const route = inner.router.looseRoutesById[routeId];
580
+ try {
581
+ const headResult = executeHead(inner, matchId, route);
582
+ if (headResult) {
583
+ const head = await headResult;
584
+ inner.updateMatch(matchId, (prev) => ({
585
+ ...prev,
586
+ ...head
587
+ }));
588
+ }
589
+ } catch (err) {
590
+ console.error(`Error executing head for route ${routeId}:`, err);
591
+ }
592
+ }
593
+ if (firstNotFound) {
594
+ throw firstNotFound;
595
+ }
596
596
  const readyPromise = triggerOnReady(inner);
597
597
  if (isPromise(readyPromise)) await readyPromise;
598
598
  } catch (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"load-matches.js","sources":["../../src/load-matches.ts"],"sourcesContent":["import { batch } from '@tanstack/store'\nimport invariant from 'tiny-invariant'\nimport { createControlledPromise, isPromise } from './utils'\nimport { isNotFound } from './not-found'\nimport { rootRouteId } from './root'\nimport { isRedirect } from './redirect'\nimport type { NotFoundError } from './not-found'\nimport type { ParsedLocation } from './location'\nimport type {\n AnyRoute,\n BeforeLoadContextOptions,\n LoaderFnContext,\n SsrContextOptions,\n} from './route'\nimport type { AnyRouteMatch, MakeRouteMatch } from './Matches'\nimport type { AnyRouter, SSROption, UpdateMatchFn } from './router'\n\n/**\n * An object of this shape is created when calling `loadMatches`.\n * It contains everything we need for all other functions in this file\n * to work. (It's basically the function's argument, plus a few mutable states)\n */\ntype InnerLoadContext = {\n /** the calling router instance */\n router: AnyRouter\n location: ParsedLocation\n /** mutable state, scoped to a `loadMatches` call */\n firstBadMatchIndex?: number\n /** mutable state, scoped to a `loadMatches` call */\n rendered?: boolean\n updateMatch: UpdateMatchFn\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n sync?: boolean\n /** mutable state, scoped to a `loadMatches` call */\n matchPromises: Array<Promise<AnyRouteMatch>>\n}\n\nconst triggerOnReady = (inner: InnerLoadContext): void | Promise<void> => {\n if (!inner.rendered) {\n inner.rendered = true\n return inner.onReady?.()\n }\n}\n\nconst resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {\n return !!(\n inner.preload && !inner.router.state.matches.some((d) => d.id === matchId)\n )\n}\n\n/**\n * Builds the accumulated context from router options and all matches up to (and optionally including) the given index.\n * Merges __routeContext and __beforeLoadContext from each match.\n */\nconst buildMatchContext = (\n inner: InnerLoadContext,\n index: number,\n includeCurrentMatch: boolean = true,\n): Record<string, unknown> => {\n const context: Record<string, unknown> = {\n ...(inner.router.options.context ?? {}),\n }\n const end = includeCurrentMatch ? index : index - 1\n for (let i = 0; i <= end; i++) {\n const innerMatch = inner.matches[i]\n if (!innerMatch) continue\n const m = inner.router.getMatch(innerMatch.id)\n if (!m) continue\n Object.assign(context, m.__routeContext, m.__beforeLoadContext)\n }\n return context\n}\n\nconst _handleNotFound = (inner: InnerLoadContext, err: NotFoundError) => {\n // Find the route that should handle the not found error\n // First check if a specific route is requested to show the error\n const routeCursor =\n inner.router.routesById[err.routeId ?? ''] ?? inner.router.routeTree\n\n // Ensure a NotFoundComponent exists on the route\n if (\n !routeCursor.options.notFoundComponent &&\n (inner.router.options as any)?.defaultNotFoundComponent\n ) {\n routeCursor.options.notFoundComponent = (\n inner.router.options as any\n ).defaultNotFoundComponent\n }\n\n // Ensure we have a notFoundComponent\n invariant(\n routeCursor.options.notFoundComponent,\n 'No notFoundComponent found. Please set a notFoundComponent on your route or provide a defaultNotFoundComponent to the router.',\n )\n\n // Find the match for this route\n const matchForRoute = inner.matches.find((m) => m.routeId === routeCursor.id)\n\n invariant(matchForRoute, 'Could not find match for route: ' + routeCursor.id)\n\n // Assign the error to the match - using non-null assertion since we've checked with invariant\n inner.updateMatch(matchForRoute.id, (prev) => ({\n ...prev,\n status: 'notFound',\n error: err,\n isFetching: false,\n }))\n\n if ((err as any).routerCode === 'BEFORE_LOAD' && routeCursor.parentRoute) {\n err.routeId = routeCursor.parentRoute.id\n _handleNotFound(inner, err)\n }\n}\n\nconst handleRedirectAndNotFound = (\n inner: InnerLoadContext,\n match: AnyRouteMatch | undefined,\n err: unknown,\n): void => {\n if (!isRedirect(err) && !isNotFound(err)) return\n\n if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {\n throw err\n }\n\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n match._nonReactive.loaderPromise = undefined\n\n const status = isRedirect(err) ? 'redirected' : 'notFound'\n\n match._nonReactive.error = err\n\n inner.updateMatch(match.id, (prev) => ({\n ...prev,\n status,\n isFetching: false,\n error: err,\n }))\n\n if (isNotFound(err) && !err.routeId) {\n err.routeId = match.routeId\n }\n\n match._nonReactive.loadPromise?.resolve()\n }\n\n if (isRedirect(err)) {\n inner.rendered = true\n err.options._fromLocation = inner.location\n err.redirectHandled = true\n err = inner.router.resolveRedirect(err)\n throw err\n } else {\n _handleNotFound(inner, err)\n throw err\n }\n}\n\nconst shouldSkipLoader = (\n inner: InnerLoadContext,\n matchId: string,\n): boolean => {\n const match = inner.router.getMatch(matchId)!\n // upon hydration, we skip the loader if the match has been dehydrated on the server\n if (!inner.router.isServer && match._nonReactive.dehydrated) {\n return true\n }\n\n if (inner.router.isServer && match.ssr === false) {\n return true\n }\n\n return false\n}\n\nconst handleSerialError = (\n inner: InnerLoadContext,\n index: number,\n err: any,\n routerCode: string,\n): void => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n // Much like suspense, we use a promise here to know if\n // we've been outdated by a new loadMatches call and\n // should abort the current async operation\n if (err instanceof Promise) {\n throw err\n }\n\n err.routerCode = routerCode\n inner.firstBadMatchIndex ??= index\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n\n try {\n route.options.onError?.(err)\n } catch (errorHandlerErr) {\n err = errorHandlerErr\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n }\n\n inner.updateMatch(matchId, (prev) => {\n prev._nonReactive.beforeLoadPromise?.resolve()\n prev._nonReactive.beforeLoadPromise = undefined\n prev._nonReactive.loadPromise?.resolve()\n\n return {\n ...prev,\n error: err,\n status: 'error',\n isFetching: false,\n updatedAt: Date.now(),\n abortController: new AbortController(),\n }\n })\n}\n\nconst isBeforeLoadSsr = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n\n // in SPA mode, only SSR the root route\n if (inner.router.isShell()) {\n existingMatch.ssr = route.id === rootRouteId\n return\n }\n\n if (parentMatch?.ssr === false) {\n existingMatch.ssr = false\n return\n }\n\n const parentOverride = (tempSsr: SSROption) => {\n if (tempSsr === true && parentMatch?.ssr === 'data-only') {\n return 'data-only'\n }\n return tempSsr\n }\n\n const defaultSsr = inner.router.options.defaultSsr ?? true\n\n if (route.options.ssr === undefined) {\n existingMatch.ssr = parentOverride(defaultSsr)\n return\n }\n\n if (typeof route.options.ssr !== 'function') {\n existingMatch.ssr = parentOverride(route.options.ssr)\n return\n }\n const { search, params } = existingMatch\n\n const ssrFnContext: SsrContextOptions<any, any, any> = {\n search: makeMaybe(search, existingMatch.searchError),\n params: makeMaybe(params, existingMatch.paramsError),\n location: inner.location,\n matches: inner.matches.map((match) => ({\n index: match.index,\n pathname: match.pathname,\n fullPath: match.fullPath,\n staticData: match.staticData,\n id: match.id,\n routeId: match.routeId,\n search: makeMaybe(match.search, match.searchError),\n params: makeMaybe(match.params, match.paramsError),\n ssr: match.ssr,\n })),\n }\n\n const tempSsr = route.options.ssr(ssrFnContext)\n if (isPromise(tempSsr)) {\n return tempSsr.then((ssr) => {\n existingMatch.ssr = parentOverride(ssr ?? defaultSsr)\n })\n }\n\n existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr)\n return\n}\n\nconst setupPendingTimeout = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n match: AnyRouteMatch,\n): void => {\n if (match._nonReactive.pendingTimeout !== undefined) return\n\n const pendingMs =\n route.options.pendingMs ?? inner.router.options.defaultPendingMs\n const shouldPending = !!(\n inner.onReady &&\n !inner.router.isServer &&\n !resolvePreload(inner, matchId) &&\n (route.options.loader ||\n route.options.beforeLoad ||\n routeNeedsPreload(route)) &&\n typeof pendingMs === 'number' &&\n pendingMs !== Infinity &&\n (route.options.pendingComponent ??\n (inner.router.options as any)?.defaultPendingComponent)\n )\n\n if (shouldPending) {\n const pendingTimeout = setTimeout(() => {\n // Update the match and prematurely resolve the loadMatches promise so that\n // the pending component can start rendering\n triggerOnReady(inner)\n }, pendingMs)\n match._nonReactive.pendingTimeout = pendingTimeout\n }\n}\n\nconst preBeforeLoadSetup = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n\n // If we are in the middle of a load, either of these will be present\n // (not to be confused with `loadPromise`, which is always defined)\n if (\n !existingMatch._nonReactive.beforeLoadPromise &&\n !existingMatch._nonReactive.loaderPromise\n )\n return\n\n setupPendingTimeout(inner, matchId, route, existingMatch)\n\n const then = () => {\n const match = inner.router.getMatch(matchId)!\n if (\n match.preload &&\n (match.status === 'redirected' || match.status === 'notFound')\n ) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n }\n\n // Wait for the previous beforeLoad to resolve before we continue\n return existingMatch._nonReactive.beforeLoadPromise\n ? existingMatch._nonReactive.beforeLoadPromise.then(then)\n : then()\n}\n\nconst executeBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const match = inner.router.getMatch(matchId)!\n\n // explicitly capture the previous loadPromise\n const prevLoadPromise = match._nonReactive.loadPromise\n match._nonReactive.loadPromise = createControlledPromise<void>(() => {\n prevLoadPromise?.resolve()\n })\n\n const { paramsError, searchError } = match\n\n if (paramsError) {\n handleSerialError(inner, index, paramsError, 'PARSE_PARAMS')\n }\n\n if (searchError) {\n handleSerialError(inner, index, searchError, 'VALIDATE_SEARCH')\n }\n\n setupPendingTimeout(inner, matchId, route, match)\n\n const abortController = new AbortController()\n\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n const parentMatchContext =\n parentMatch?.context ?? inner.router.options.context ?? undefined\n\n let isPending = false\n const pending = () => {\n if (isPending) return\n isPending = true\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'beforeLoad',\n fetchCount: prev.fetchCount + 1,\n abortController,\n // Note: We intentionally don't update context here.\n // Context should only be updated after beforeLoad resolves to avoid\n // components seeing incomplete context during async beforeLoad execution.\n }))\n }\n\n const resolve = () => {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: false,\n }))\n }\n\n // if there is no `beforeLoad` option, just mark as pending and resolve\n // Context will be updated later in loadRouteMatch after loader completes\n if (!route.options.beforeLoad) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n\n match._nonReactive.beforeLoadPromise = createControlledPromise<void>()\n\n // Build context from all parent matches, excluding current match's __beforeLoadContext\n // (since we're about to execute beforeLoad for this match)\n const context = {\n ...buildMatchContext(inner, index, false),\n ...match.__routeContext,\n }\n const { search, params, cause } = match\n const preload = resolvePreload(inner, matchId)\n const beforeLoadFnContext: BeforeLoadContextOptions<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = {\n search,\n abortController,\n params,\n preload,\n context,\n location: inner.location,\n navigate: (opts: any) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n buildLocation: inner.router.buildLocation,\n cause: preload ? 'preload' : cause,\n matches: inner.matches,\n ...inner.router.options.additionalContext,\n }\n\n const updateContext = (beforeLoadContext: any) => {\n if (beforeLoadContext === undefined) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {\n pending()\n handleSerialError(inner, index, beforeLoadContext, 'BEFORE_LOAD')\n }\n\n batch(() => {\n pending()\n // Only store __beforeLoadContext here, don't update context yet\n // Context will be updated in loadRouteMatch after loader completes\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n __beforeLoadContext: beforeLoadContext,\n }))\n resolve()\n })\n }\n\n let beforeLoadContext\n try {\n beforeLoadContext = route.options.beforeLoad(beforeLoadFnContext)\n if (isPromise(beforeLoadContext)) {\n pending()\n return beforeLoadContext\n .catch((err) => {\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n })\n .then(updateContext)\n }\n } catch (err) {\n pending()\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n }\n\n updateContext(beforeLoadContext)\n return\n}\n\nconst handleBeforeLoad = (\n inner: InnerLoadContext,\n index: number,\n): void | Promise<void> => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n const serverSsr = () => {\n // on the server, determine whether SSR the current match or not\n if (inner.router.isServer) {\n const maybePromise = isBeforeLoadSsr(inner, matchId, index, route)\n if (isPromise(maybePromise)) return maybePromise.then(queueExecution)\n }\n return queueExecution()\n }\n\n const execute = () => executeBeforeLoad(inner, matchId, index, route)\n\n const queueExecution = () => {\n if (shouldSkipLoader(inner, matchId)) return\n const result = preBeforeLoadSetup(inner, matchId, route)\n return isPromise(result) ? result.then(execute) : execute()\n }\n\n return serverSsr()\n}\n\nconst executeHead = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<\n Pick<\n AnyRouteMatch,\n 'meta' | 'links' | 'headScripts' | 'headers' | 'scripts' | 'styles'\n >\n> => {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (!match) {\n return\n }\n if (!route.options.head && !route.options.scripts && !route.options.headers) {\n return\n }\n const assetContext = {\n matches: inner.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n\n return Promise.all([\n route.options.head?.(assetContext),\n route.options.scripts?.(assetContext),\n route.options.headers?.(assetContext),\n ]).then(([headFnContent, scripts, headers]) => {\n const meta = headFnContent?.meta\n const links = headFnContent?.links\n const headScripts = headFnContent?.scripts\n const styles = headFnContent?.styles\n\n return {\n meta,\n links,\n headScripts,\n headers,\n scripts,\n styles,\n }\n })\n}\n\nconst getLoaderContext = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): LoaderFnContext => {\n const parentMatchPromise = inner.matchPromises[index - 1] as any\n const { params, loaderDeps, abortController, cause } =\n inner.router.getMatch(matchId)!\n\n const context = buildMatchContext(inner, index)\n\n const preload = resolvePreload(inner, matchId)\n\n return {\n params,\n deps: loaderDeps,\n preload: !!preload,\n parentMatchPromise,\n abortController,\n context,\n location: inner.location,\n navigate: (opts) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n cause: preload ? 'preload' : cause,\n route,\n ...inner.router.options.additionalContext,\n }\n}\n\nconst runLoader = async (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): Promise<void> => {\n try {\n // If the Matches component rendered\n // the pending component and needs to show it for\n // a minimum duration, we''ll wait for it to resolve\n // before committing to the match and resolving\n // the loadPromise\n\n const match = inner.router.getMatch(matchId)!\n\n // Actually run the loader and handle the result\n try {\n if (!inner.router.isServer || match.ssr === true) {\n loadRouteChunk(route)\n }\n\n // Kick off the loader!\n const loaderResult = route.options.loader?.(\n getLoaderContext(inner, matchId, index, route),\n )\n const loaderResultIsPromise =\n route.options.loader && isPromise(loaderResult)\n\n const willLoadSomething = !!(\n loaderResultIsPromise ||\n route._lazyPromise ||\n route._componentsPromise ||\n route.options.head ||\n route.options.scripts ||\n route.options.headers ||\n match._nonReactive.minPendingPromise\n )\n\n if (willLoadSomething) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'loader',\n }))\n }\n\n if (route.options.loader) {\n const loaderData = loaderResultIsPromise\n ? await loaderResult\n : loaderResult\n\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n loaderData,\n )\n if (loaderData !== undefined) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n loaderData,\n }))\n }\n }\n\n // Lazy option can modify the route options,\n // so we need to wait for it to resolve before\n // we can use the options\n if (route._lazyPromise) await route._lazyPromise\n const headResult = executeHead(inner, matchId, route)\n const head = headResult ? await headResult : undefined\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n // Last but not least, wait for the the components\n // to be preloaded before we resolve the match\n if (route._componentsPromise) await route._componentsPromise\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error: undefined,\n status: 'success',\n isFetching: false,\n updatedAt: Date.now(),\n ...head,\n }))\n } catch (e) {\n let error = e\n\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n if (isNotFound(e)) {\n await (route.options.notFoundComponent as any)?.preload?.()\n }\n\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), e)\n\n try {\n route.options.onError?.(e)\n } catch (onErrorError) {\n error = onErrorError\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n onErrorError,\n )\n }\n const headResult = executeHead(inner, matchId, route)\n const head = headResult ? await headResult : undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error,\n status: 'error',\n isFetching: false,\n ...head,\n }))\n }\n } catch (err) {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n match._nonReactive.loaderPromise = undefined\n }\n handleRedirectAndNotFound(inner, match, err)\n }\n}\n\nconst loadRouteMatch = async (\n inner: InnerLoadContext,\n index: number,\n): Promise<AnyRouteMatch> => {\n const { id: matchId, routeId } = inner.matches[index]!\n let loaderShouldRunAsync = false\n let loaderIsRunningAsync = false\n const route = inner.router.looseRoutesById[routeId]!\n\n const commitContext = () => {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n context: buildMatchContext(inner, index),\n }))\n }\n\n if (shouldSkipLoader(inner, matchId)) {\n if (inner.router.isServer) {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n return inner.router.getMatch(matchId)!\n }\n } else {\n const prevMatch = inner.router.getMatch(matchId)!\n // there is a loaderPromise, so we are in the middle of a load\n if (prevMatch._nonReactive.loaderPromise) {\n // do not block if we already have stale data we can show\n // but only if the ongoing load is not a preload since error handling is different for preloads\n // and we don't want to swallow errors\n if (prevMatch.status === 'success' && !inner.sync && !prevMatch.preload) {\n return prevMatch\n }\n await prevMatch._nonReactive.loaderPromise\n const match = inner.router.getMatch(matchId)!\n const error = match._nonReactive.error || match.error\n if (error) {\n handleRedirectAndNotFound(inner, match, error)\n }\n } else {\n // This is where all of the stale-while-revalidate magic happens\n const age = Date.now() - prevMatch.updatedAt\n\n const preload = resolvePreload(inner, matchId)\n\n const staleAge = preload\n ? (route.options.preloadStaleTime ??\n inner.router.options.defaultPreloadStaleTime ??\n 30_000) // 30 seconds for preloads by default\n : (route.options.staleTime ??\n inner.router.options.defaultStaleTime ??\n 0)\n\n const shouldReloadOption = route.options.shouldReload\n\n // Default to reloading the route all the time\n // Allow shouldReload to get the last say,\n // if provided.\n const shouldReload =\n typeof shouldReloadOption === 'function'\n ? shouldReloadOption(getLoaderContext(inner, matchId, index, route))\n : shouldReloadOption\n\n const nextPreload =\n !!preload && !inner.router.state.matches.some((d) => d.id === matchId)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise = createControlledPromise<void>()\n if (nextPreload !== match.preload) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n preload: nextPreload,\n }))\n }\n\n // If the route is successful and still fresh, just resolve\n const { status, invalid } = match\n loaderShouldRunAsync =\n status === 'success' && (invalid || (shouldReload ?? age > staleAge))\n if (preload && route.options.preload === false) {\n // Do nothing\n } else if (loaderShouldRunAsync && !inner.sync) {\n loaderIsRunningAsync = true\n ;(async () => {\n try {\n await runLoader(inner, matchId, index, route)\n commitContext()\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n match._nonReactive.loaderPromise = undefined\n } catch (err) {\n if (isRedirect(err)) {\n await inner.router.navigate(err.options)\n }\n }\n })()\n } else if (status !== 'success' || (loaderShouldRunAsync && inner.sync)) {\n await runLoader(inner, matchId, index, route)\n } else {\n // if the loader did not run, still update head.\n // reason: parent's beforeLoad may have changed the route context\n // and only now do we know the route context (and that the loader would not run)\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n }\n }\n }\n const match = inner.router.getMatch(matchId)!\n if (!loaderIsRunningAsync) {\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n }\n\n clearTimeout(match._nonReactive.pendingTimeout)\n match._nonReactive.pendingTimeout = undefined\n if (!loaderIsRunningAsync) match._nonReactive.loaderPromise = undefined\n match._nonReactive.dehydrated = undefined\n\n // Commit context now that loader has completed (or was skipped)\n // For async loaders, this was already done in the async callback\n if (!loaderIsRunningAsync) {\n commitContext()\n }\n\n const nextIsFetching = loaderIsRunningAsync ? match.isFetching : false\n if (nextIsFetching !== match.isFetching || match.invalid !== false) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: nextIsFetching,\n invalid: false,\n }))\n return inner.router.getMatch(matchId)!\n } else {\n return match\n }\n}\n\nexport async function loadMatches(arg: {\n router: AnyRouter\n location: ParsedLocation\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n updateMatch: UpdateMatchFn\n sync?: boolean\n}): Promise<Array<MakeRouteMatch>> {\n const inner: InnerLoadContext = Object.assign(arg, {\n matchPromises: [],\n })\n\n // make sure the pending component is immediately rendered when hydrating a match that is not SSRed\n // the pending component was already rendered on the server and we want to keep it shown on the client until minPendingMs is reached\n if (\n !inner.router.isServer &&\n inner.router.state.matches.some((d) => d._forcePending)\n ) {\n triggerOnReady(inner)\n }\n\n try {\n // Execute all beforeLoads one by one\n for (let i = 0; i < inner.matches.length; i++) {\n const beforeLoad = handleBeforeLoad(inner, i)\n if (isPromise(beforeLoad)) await beforeLoad\n }\n\n // Execute all loaders in parallel\n const max = inner.firstBadMatchIndex ?? inner.matches.length\n for (let i = 0; i < max; i++) {\n inner.matchPromises.push(loadRouteMatch(inner, i))\n }\n await Promise.all(inner.matchPromises)\n\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n } catch (err) {\n if (isNotFound(err) && !inner.preload) {\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n throw err\n }\n if (isRedirect(err)) {\n throw err\n }\n }\n\n return inner.matches\n}\n\nexport async function loadRouteChunk(route: AnyRoute) {\n if (!route._lazyLoaded && route._lazyPromise === undefined) {\n if (route.lazyFn) {\n route._lazyPromise = route.lazyFn().then((lazyRoute) => {\n // explicitly don't copy over the lazy route's id\n const { id: _id, ...options } = lazyRoute.options\n Object.assign(route.options, options)\n route._lazyLoaded = true\n route._lazyPromise = undefined // gc promise, we won't need it anymore\n })\n } else {\n route._lazyLoaded = true\n }\n }\n\n // If for some reason lazy resolves more lazy components...\n // We'll wait for that before we attempt to preload the\n // components themselves.\n if (!route._componentsLoaded && route._componentsPromise === undefined) {\n const loadComponents = () => {\n const preloads = []\n for (const type of componentTypes) {\n const preload = (route.options[type] as any)?.preload\n if (preload) preloads.push(preload())\n }\n if (preloads.length)\n return Promise.all(preloads).then(() => {\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n })\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n return\n }\n route._componentsPromise = route._lazyPromise\n ? route._lazyPromise.then(loadComponents)\n : loadComponents()\n }\n return route._componentsPromise\n}\n\nfunction makeMaybe<TValue, TError>(\n value: TValue,\n error: TError,\n): { status: 'success'; value: TValue } | { status: 'error'; error: TError } {\n if (error) {\n return { status: 'error' as const, error }\n }\n return { status: 'success' as const, value }\n}\n\nexport function routeNeedsPreload(route: AnyRoute) {\n for (const componentType of componentTypes) {\n if ((route.options[componentType] as any)?.preload) {\n return true\n }\n }\n return false\n}\n\nexport const componentTypes = [\n 'component',\n 'errorComponent',\n 'pendingComponent',\n 'notFoundComponent',\n] as const\n"],"names":["tempSsr","beforeLoadContext","match"],"mappings":";;;;;;AAuCA,MAAM,iBAAiB,CAAC,UAAkD;AACxE,MAAI,CAAC,MAAM,UAAU;AACnB,UAAM,WAAW;AACjB,WAAO,MAAM,UAAA;AAAA,EACf;AACF;AAEA,MAAM,iBAAiB,CAAC,OAAyB,YAA6B;AAC5E,SAAO,CAAC,EACN,MAAM,WAAW,CAAC,MAAM,OAAO,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO;AAE7E;AAMA,MAAM,oBAAoB,CACxB,OACA,OACA,sBAA+B,SACH;AAC5B,QAAM,UAAmC;AAAA,IACvC,GAAI,MAAM,OAAO,QAAQ,WAAW,CAAA;AAAA,EAAC;AAEvC,QAAM,MAAM,sBAAsB,QAAQ,QAAQ;AAClD,WAAS,IAAI,GAAG,KAAK,KAAK,KAAK;AAC7B,UAAM,aAAa,MAAM,QAAQ,CAAC;AAClC,QAAI,CAAC,WAAY;AACjB,UAAM,IAAI,MAAM,OAAO,SAAS,WAAW,EAAE;AAC7C,QAAI,CAAC,EAAG;AACR,WAAO,OAAO,SAAS,EAAE,gBAAgB,EAAE,mBAAmB;AAAA,EAChE;AACA,SAAO;AACT;AAEA,MAAM,kBAAkB,CAAC,OAAyB,QAAuB;AAGvE,QAAM,cACJ,MAAM,OAAO,WAAW,IAAI,WAAW,EAAE,KAAK,MAAM,OAAO;AAG7D,MACE,CAAC,YAAY,QAAQ,qBACpB,MAAM,OAAO,SAAiB,0BAC/B;AACA,gBAAY,QAAQ,oBAClB,MAAM,OAAO,QACb;AAAA,EACJ;AAGA;AAAA,IACE,YAAY,QAAQ;AAAA,IACpB;AAAA,EAAA;AAIF,QAAM,gB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BAAoB;AAC1B,YAAM,qBAAqB;AAC3B;AAAA,IACF;AACA,UAAM,qBAAqB,MAAM,eAC7B,MAAM,aAAa,KAAK,cAAc,IACtC,eAAA;AAAA,EACN;AACA,SAAO,MAAM;AACf;AAEA,SAAS,UACP,OACA,OAC2E;AAC3E,MAAI,OAAO;AACT,WAAO,EAAE,QAAQ,SAAkB,MAAA;AAAA,EACrC;AACA,SAAO,EAAE,QAAQ,WAAoB,MAAA;AACvC;AAEO,SAAS,kBAAkB,OAAiB;AACjD,aAAW,iBAAiB,gBAAgB;AAC1C,QAAK,MAAM,QAAQ,aAAa,GAAW,SAAS;AAClD,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
1
+ {"version":3,"file":"load-matches.js","sources":["../../src/load-matches.ts"],"sourcesContent":["import { batch } from '@tanstack/store'\nimport invariant from 'tiny-invariant'\nimport { createControlledPromise, isPromise } from './utils'\nimport { isNotFound } from './not-found'\nimport { rootRouteId } from './root'\nimport { isRedirect } from './redirect'\nimport type { NotFoundError } from './not-found'\nimport type { ParsedLocation } from './location'\nimport type {\n AnyRoute,\n BeforeLoadContextOptions,\n LoaderFnContext,\n SsrContextOptions,\n} from './route'\nimport type { AnyRouteMatch, MakeRouteMatch } from './Matches'\nimport type { AnyRouter, SSROption, UpdateMatchFn } from './router'\n\n/**\n * An object of this shape is created when calling `loadMatches`.\n * It contains everything we need for all other functions in this file\n * to work. (It's basically the function's argument, plus a few mutable states)\n */\ntype InnerLoadContext = {\n /** the calling router instance */\n router: AnyRouter\n location: ParsedLocation\n /** mutable state, scoped to a `loadMatches` call */\n firstBadMatchIndex?: number\n /** mutable state, scoped to a `loadMatches` call */\n rendered?: boolean\n updateMatch: UpdateMatchFn\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n sync?: boolean\n /** mutable state, scoped to a `loadMatches` call */\n matchPromises: Array<Promise<AnyRouteMatch>>\n}\n\nconst triggerOnReady = (inner: InnerLoadContext): void | Promise<void> => {\n if (!inner.rendered) {\n inner.rendered = true\n return inner.onReady?.()\n }\n}\n\nconst resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {\n return !!(\n inner.preload && !inner.router.state.matches.some((d) => d.id === matchId)\n )\n}\n\n/**\n * Builds the accumulated context from router options and all matches up to (and optionally including) the given index.\n * Merges __routeContext and __beforeLoadContext from each match.\n */\nconst buildMatchContext = (\n inner: InnerLoadContext,\n index: number,\n includeCurrentMatch: boolean = true,\n): Record<string, unknown> => {\n const context: Record<string, unknown> = {\n ...(inner.router.options.context ?? {}),\n }\n const end = includeCurrentMatch ? index : index - 1\n for (let i = 0; i <= end; i++) {\n const innerMatch = inner.matches[i]\n if (!innerMatch) continue\n const m = inner.router.getMatch(innerMatch.id)\n if (!m) continue\n Object.assign(context, m.__routeContext, m.__beforeLoadContext)\n }\n return context\n}\n\nconst _handleNotFound = (inner: InnerLoadContext, err: NotFoundError) => {\n // Find the route that should handle the not found error\n // First check if a specific route is requested to show the error\n const routeCursor =\n inner.router.routesById[err.routeId ?? ''] ?? inner.router.routeTree\n\n // Ensure a NotFoundComponent exists on the route\n if (\n !routeCursor.options.notFoundComponent &&\n (inner.router.options as any)?.defaultNotFoundComponent\n ) {\n routeCursor.options.notFoundComponent = (\n inner.router.options as any\n ).defaultNotFoundComponent\n }\n\n // Ensure we have a notFoundComponent\n invariant(\n routeCursor.options.notFoundComponent,\n 'No notFoundComponent found. Please set a notFoundComponent on your route or provide a defaultNotFoundComponent to the router.',\n )\n\n // Find the match for this route\n const matchForRoute = inner.matches.find((m) => m.routeId === routeCursor.id)\n\n invariant(matchForRoute, 'Could not find match for route: ' + routeCursor.id)\n\n // Assign the error to the match - using non-null assertion since we've checked with invariant\n inner.updateMatch(matchForRoute.id, (prev) => ({\n ...prev,\n status: 'notFound',\n error: err,\n isFetching: false,\n }))\n\n if ((err as any).routerCode === 'BEFORE_LOAD' && routeCursor.parentRoute) {\n err.routeId = routeCursor.parentRoute.id\n _handleNotFound(inner, err)\n }\n}\n\nconst handleRedirectAndNotFound = (\n inner: InnerLoadContext,\n match: AnyRouteMatch | undefined,\n err: unknown,\n): void => {\n if (!isRedirect(err) && !isNotFound(err)) return\n\n if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {\n throw err\n }\n\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n match._nonReactive.loaderPromise = undefined\n\n const status = isRedirect(err) ? 'redirected' : 'notFound'\n\n match._nonReactive.error = err\n\n inner.updateMatch(match.id, (prev) => ({\n ...prev,\n status,\n isFetching: false,\n error: err,\n }))\n\n if (isNotFound(err) && !err.routeId) {\n err.routeId = match.routeId\n }\n\n match._nonReactive.loadPromise?.resolve()\n }\n\n if (isRedirect(err)) {\n inner.rendered = true\n err.options._fromLocation = inner.location\n err.redirectHandled = true\n err = inner.router.resolveRedirect(err)\n throw err\n } else {\n _handleNotFound(inner, err)\n throw err\n }\n}\n\nconst shouldSkipLoader = (\n inner: InnerLoadContext,\n matchId: string,\n): boolean => {\n const match = inner.router.getMatch(matchId)!\n // upon hydration, we skip the loader if the match has been dehydrated on the server\n if (!inner.router.isServer && match._nonReactive.dehydrated) {\n return true\n }\n\n if (inner.router.isServer && match.ssr === false) {\n return true\n }\n\n return false\n}\n\nconst handleSerialError = (\n inner: InnerLoadContext,\n index: number,\n err: any,\n routerCode: string,\n): void => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n // Much like suspense, we use a promise here to know if\n // we've been outdated by a new loadMatches call and\n // should abort the current async operation\n if (err instanceof Promise) {\n throw err\n }\n\n err.routerCode = routerCode\n inner.firstBadMatchIndex ??= index\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n\n try {\n route.options.onError?.(err)\n } catch (errorHandlerErr) {\n err = errorHandlerErr\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n }\n\n inner.updateMatch(matchId, (prev) => {\n prev._nonReactive.beforeLoadPromise?.resolve()\n prev._nonReactive.beforeLoadPromise = undefined\n prev._nonReactive.loadPromise?.resolve()\n\n return {\n ...prev,\n error: err,\n status: 'error',\n isFetching: false,\n updatedAt: Date.now(),\n abortController: new AbortController(),\n }\n })\n}\n\nconst isBeforeLoadSsr = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n\n // in SPA mode, only SSR the root route\n if (inner.router.isShell()) {\n existingMatch.ssr = route.id === rootRouteId\n return\n }\n\n if (parentMatch?.ssr === false) {\n existingMatch.ssr = false\n return\n }\n\n const parentOverride = (tempSsr: SSROption) => {\n if (tempSsr === true && parentMatch?.ssr === 'data-only') {\n return 'data-only'\n }\n return tempSsr\n }\n\n const defaultSsr = inner.router.options.defaultSsr ?? true\n\n if (route.options.ssr === undefined) {\n existingMatch.ssr = parentOverride(defaultSsr)\n return\n }\n\n if (typeof route.options.ssr !== 'function') {\n existingMatch.ssr = parentOverride(route.options.ssr)\n return\n }\n const { search, params } = existingMatch\n\n const ssrFnContext: SsrContextOptions<any, any, any> = {\n search: makeMaybe(search, existingMatch.searchError),\n params: makeMaybe(params, existingMatch.paramsError),\n location: inner.location,\n matches: inner.matches.map((match) => ({\n index: match.index,\n pathname: match.pathname,\n fullPath: match.fullPath,\n staticData: match.staticData,\n id: match.id,\n routeId: match.routeId,\n search: makeMaybe(match.search, match.searchError),\n params: makeMaybe(match.params, match.paramsError),\n ssr: match.ssr,\n })),\n }\n\n const tempSsr = route.options.ssr(ssrFnContext)\n if (isPromise(tempSsr)) {\n return tempSsr.then((ssr) => {\n existingMatch.ssr = parentOverride(ssr ?? defaultSsr)\n })\n }\n\n existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr)\n return\n}\n\nconst setupPendingTimeout = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n match: AnyRouteMatch,\n): void => {\n if (match._nonReactive.pendingTimeout !== undefined) return\n\n const pendingMs =\n route.options.pendingMs ?? inner.router.options.defaultPendingMs\n const shouldPending = !!(\n inner.onReady &&\n !inner.router.isServer &&\n !resolvePreload(inner, matchId) &&\n (route.options.loader ||\n route.options.beforeLoad ||\n routeNeedsPreload(route)) &&\n typeof pendingMs === 'number' &&\n pendingMs !== Infinity &&\n (route.options.pendingComponent ??\n (inner.router.options as any)?.defaultPendingComponent)\n )\n\n if (shouldPending) {\n const pendingTimeout = setTimeout(() => {\n // Update the match and prematurely resolve the loadMatches promise so that\n // the pending component can start rendering\n triggerOnReady(inner)\n }, pendingMs)\n match._nonReactive.pendingTimeout = pendingTimeout\n }\n}\n\nconst preBeforeLoadSetup = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n\n // If we are in the middle of a load, either of these will be present\n // (not to be confused with `loadPromise`, which is always defined)\n if (\n !existingMatch._nonReactive.beforeLoadPromise &&\n !existingMatch._nonReactive.loaderPromise\n )\n return\n\n setupPendingTimeout(inner, matchId, route, existingMatch)\n\n const then = () => {\n const match = inner.router.getMatch(matchId)!\n if (\n match.preload &&\n (match.status === 'redirected' || match.status === 'notFound')\n ) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n }\n\n // Wait for the previous beforeLoad to resolve before we continue\n return existingMatch._nonReactive.beforeLoadPromise\n ? existingMatch._nonReactive.beforeLoadPromise.then(then)\n : then()\n}\n\nconst executeBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const match = inner.router.getMatch(matchId)!\n\n // explicitly capture the previous loadPromise\n const prevLoadPromise = match._nonReactive.loadPromise\n match._nonReactive.loadPromise = createControlledPromise<void>(() => {\n prevLoadPromise?.resolve()\n })\n\n const { paramsError, searchError } = match\n\n if (paramsError) {\n handleSerialError(inner, index, paramsError, 'PARSE_PARAMS')\n }\n\n if (searchError) {\n handleSerialError(inner, index, searchError, 'VALIDATE_SEARCH')\n }\n\n setupPendingTimeout(inner, matchId, route, match)\n\n const abortController = new AbortController()\n\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n const parentMatchContext =\n parentMatch?.context ?? inner.router.options.context ?? undefined\n\n let isPending = false\n const pending = () => {\n if (isPending) return\n isPending = true\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'beforeLoad',\n fetchCount: prev.fetchCount + 1,\n abortController,\n // Note: We intentionally don't update context here.\n // Context should only be updated after beforeLoad resolves to avoid\n // components seeing incomplete context during async beforeLoad execution.\n }))\n }\n\n const resolve = () => {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: false,\n }))\n }\n\n // if there is no `beforeLoad` option, just mark as pending and resolve\n // Context will be updated later in loadRouteMatch after loader completes\n if (!route.options.beforeLoad) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n\n match._nonReactive.beforeLoadPromise = createControlledPromise<void>()\n\n // Build context from all parent matches, excluding current match's __beforeLoadContext\n // (since we're about to execute beforeLoad for this match)\n const context = {\n ...buildMatchContext(inner, index, false),\n ...match.__routeContext,\n }\n const { search, params, cause } = match\n const preload = resolvePreload(inner, matchId)\n const beforeLoadFnContext: BeforeLoadContextOptions<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = {\n search,\n abortController,\n params,\n preload,\n context,\n location: inner.location,\n navigate: (opts: any) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n buildLocation: inner.router.buildLocation,\n cause: preload ? 'preload' : cause,\n matches: inner.matches,\n ...inner.router.options.additionalContext,\n }\n\n const updateContext = (beforeLoadContext: any) => {\n if (beforeLoadContext === undefined) {\n batch(() => {\n pending()\n resolve()\n })\n return\n }\n if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {\n pending()\n handleSerialError(inner, index, beforeLoadContext, 'BEFORE_LOAD')\n }\n\n batch(() => {\n pending()\n // Only store __beforeLoadContext here, don't update context yet\n // Context will be updated in loadRouteMatch after loader completes\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n __beforeLoadContext: beforeLoadContext,\n }))\n resolve()\n })\n }\n\n let beforeLoadContext\n try {\n beforeLoadContext = route.options.beforeLoad(beforeLoadFnContext)\n if (isPromise(beforeLoadContext)) {\n pending()\n return beforeLoadContext\n .catch((err) => {\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n })\n .then(updateContext)\n }\n } catch (err) {\n pending()\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n }\n\n updateContext(beforeLoadContext)\n return\n}\n\nconst handleBeforeLoad = (\n inner: InnerLoadContext,\n index: number,\n): void | Promise<void> => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n const serverSsr = () => {\n // on the server, determine whether SSR the current match or not\n if (inner.router.isServer) {\n const maybePromise = isBeforeLoadSsr(inner, matchId, index, route)\n if (isPromise(maybePromise)) return maybePromise.then(queueExecution)\n }\n return queueExecution()\n }\n\n const execute = () => executeBeforeLoad(inner, matchId, index, route)\n\n const queueExecution = () => {\n if (shouldSkipLoader(inner, matchId)) return\n const result = preBeforeLoadSetup(inner, matchId, route)\n return isPromise(result) ? result.then(execute) : execute()\n }\n\n return serverSsr()\n}\n\nconst executeHead = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<\n Pick<\n AnyRouteMatch,\n 'meta' | 'links' | 'headScripts' | 'headers' | 'scripts' | 'styles'\n >\n> => {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (!match) {\n return\n }\n if (!route.options.head && !route.options.scripts && !route.options.headers) {\n return\n }\n const assetContext = {\n matches: inner.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n\n return Promise.all([\n route.options.head?.(assetContext),\n route.options.scripts?.(assetContext),\n route.options.headers?.(assetContext),\n ]).then(([headFnContent, scripts, headers]) => {\n const meta = headFnContent?.meta\n const links = headFnContent?.links\n const headScripts = headFnContent?.scripts\n const styles = headFnContent?.styles\n\n return {\n meta,\n links,\n headScripts,\n headers,\n scripts,\n styles,\n }\n })\n}\n\nconst getLoaderContext = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): LoaderFnContext => {\n const parentMatchPromise = inner.matchPromises[index - 1] as any\n const { params, loaderDeps, abortController, cause } =\n inner.router.getMatch(matchId)!\n\n const context = buildMatchContext(inner, index)\n\n const preload = resolvePreload(inner, matchId)\n\n return {\n params,\n deps: loaderDeps,\n preload: !!preload,\n parentMatchPromise,\n abortController,\n context,\n location: inner.location,\n navigate: (opts) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n cause: preload ? 'preload' : cause,\n route,\n ...inner.router.options.additionalContext,\n }\n}\n\nconst runLoader = async (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): Promise<void> => {\n try {\n // If the Matches component rendered\n // the pending component and needs to show it for\n // a minimum duration, we''ll wait for it to resolve\n // before committing to the match and resolving\n // the loadPromise\n\n const match = inner.router.getMatch(matchId)!\n\n // Actually run the loader and handle the result\n try {\n if (!inner.router.isServer || match.ssr === true) {\n loadRouteChunk(route)\n }\n\n // Kick off the loader!\n const loaderResult = route.options.loader?.(\n getLoaderContext(inner, matchId, index, route),\n )\n const loaderResultIsPromise =\n route.options.loader && isPromise(loaderResult)\n\n const willLoadSomething = !!(\n loaderResultIsPromise ||\n route._lazyPromise ||\n route._componentsPromise ||\n route.options.head ||\n route.options.scripts ||\n route.options.headers ||\n match._nonReactive.minPendingPromise\n )\n\n if (willLoadSomething) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'loader',\n }))\n }\n\n if (route.options.loader) {\n const loaderData = loaderResultIsPromise\n ? await loaderResult\n : loaderResult\n\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n loaderData,\n )\n if (loaderData !== undefined) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n loaderData,\n }))\n }\n }\n\n // Lazy option can modify the route options,\n // so we need to wait for it to resolve before\n // we can use the options\n if (route._lazyPromise) await route._lazyPromise\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n // Last but not least, wait for the the components\n // to be preloaded before we resolve the match\n if (route._componentsPromise) await route._componentsPromise\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error: undefined,\n status: 'success',\n isFetching: false,\n updatedAt: Date.now(),\n }))\n } catch (e) {\n let error = e\n\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n if (isNotFound(e)) {\n await (route.options.notFoundComponent as any)?.preload?.()\n }\n\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), e)\n\n try {\n route.options.onError?.(e)\n } catch (onErrorError) {\n error = onErrorError\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n onErrorError,\n )\n }\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error,\n status: 'error',\n isFetching: false,\n }))\n }\n } catch (err) {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.loaderPromise = undefined\n }\n handleRedirectAndNotFound(inner, match, err)\n }\n}\n\nconst loadRouteMatch = async (\n inner: InnerLoadContext,\n index: number,\n): Promise<AnyRouteMatch> => {\n const { id: matchId, routeId } = inner.matches[index]!\n let loaderShouldRunAsync = false\n let loaderIsRunningAsync = false\n const route = inner.router.looseRoutesById[routeId]!\n\n const commitContext = () => {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n context: buildMatchContext(inner, index),\n }))\n }\n\n if (shouldSkipLoader(inner, matchId)) {\n if (inner.router.isServer) {\n return inner.router.getMatch(matchId)!\n }\n } else {\n const prevMatch = inner.router.getMatch(matchId)!\n // there is a loaderPromise, so we are in the middle of a load\n if (prevMatch._nonReactive.loaderPromise) {\n // do not block if we already have stale data we can show\n // but only if the ongoing load is not a preload since error handling is different for preloads\n // and we don't want to swallow errors\n if (prevMatch.status === 'success' && !inner.sync && !prevMatch.preload) {\n return prevMatch\n }\n await prevMatch._nonReactive.loaderPromise\n const match = inner.router.getMatch(matchId)!\n const error = match._nonReactive.error || match.error\n if (error) {\n handleRedirectAndNotFound(inner, match, error)\n }\n } else {\n // This is where all of the stale-while-revalidate magic happens\n const age = Date.now() - prevMatch.updatedAt\n\n const preload = resolvePreload(inner, matchId)\n\n const staleAge = preload\n ? (route.options.preloadStaleTime ??\n inner.router.options.defaultPreloadStaleTime ??\n 30_000) // 30 seconds for preloads by default\n : (route.options.staleTime ??\n inner.router.options.defaultStaleTime ??\n 0)\n\n const shouldReloadOption = route.options.shouldReload\n\n // Default to reloading the route all the time\n // Allow shouldReload to get the last say,\n // if provided.\n const shouldReload =\n typeof shouldReloadOption === 'function'\n ? shouldReloadOption(getLoaderContext(inner, matchId, index, route))\n : shouldReloadOption\n\n const nextPreload =\n !!preload && !inner.router.state.matches.some((d) => d.id === matchId)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise = createControlledPromise<void>()\n if (nextPreload !== match.preload) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n preload: nextPreload,\n }))\n }\n\n // If the route is successful and still fresh, just resolve\n const { status, invalid } = match\n loaderShouldRunAsync =\n status === 'success' && (invalid || (shouldReload ?? age > staleAge))\n if (preload && route.options.preload === false) {\n // Do nothing\n } else if (loaderShouldRunAsync && !inner.sync) {\n loaderIsRunningAsync = true\n ;(async () => {\n try {\n await runLoader(inner, matchId, index, route)\n commitContext()\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n match._nonReactive.loaderPromise = undefined\n } catch (err) {\n if (isRedirect(err)) {\n await inner.router.navigate(err.options)\n }\n }\n })()\n } else if (status !== 'success' || (loaderShouldRunAsync && inner.sync)) {\n await runLoader(inner, matchId, index, route)\n }\n }\n }\n const match = inner.router.getMatch(matchId)!\n if (!loaderIsRunningAsync) {\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n }\n\n clearTimeout(match._nonReactive.pendingTimeout)\n match._nonReactive.pendingTimeout = undefined\n if (!loaderIsRunningAsync) match._nonReactive.loaderPromise = undefined\n match._nonReactive.dehydrated = undefined\n\n // Commit context now that loader has completed (or was skipped)\n // For async loaders, this was already done in the async callback\n if (!loaderIsRunningAsync) {\n commitContext()\n }\n\n const nextIsFetching = loaderIsRunningAsync ? match.isFetching : false\n if (nextIsFetching !== match.isFetching || match.invalid !== false) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: nextIsFetching,\n invalid: false,\n }))\n return inner.router.getMatch(matchId)!\n } else {\n return match\n }\n}\n\nexport async function loadMatches(arg: {\n router: AnyRouter\n location: ParsedLocation\n matches: Array<AnyRouteMatch>\n preload?: boolean\n onReady?: () => Promise<void>\n updateMatch: UpdateMatchFn\n sync?: boolean\n}): Promise<Array<MakeRouteMatch>> {\n const inner: InnerLoadContext = Object.assign(arg, {\n matchPromises: [],\n })\n\n // make sure the pending component is immediately rendered when hydrating a match that is not SSRed\n // the pending component was already rendered on the server and we want to keep it shown on the client until minPendingMs is reached\n if (\n !inner.router.isServer &&\n inner.router.state.matches.some((d) => d._forcePending)\n ) {\n triggerOnReady(inner)\n }\n\n try {\n // Execute all beforeLoads one by one\n for (let i = 0; i < inner.matches.length; i++) {\n const beforeLoad = handleBeforeLoad(inner, i)\n if (isPromise(beforeLoad)) await beforeLoad\n }\n\n // Execute all loaders in parallel\n const max = inner.firstBadMatchIndex ?? inner.matches.length\n for (let i = 0; i < max; i++) {\n inner.matchPromises.push(loadRouteMatch(inner, i))\n }\n // Use allSettled to ensure all loaders complete regardless of success/failure\n const results = await Promise.allSettled(inner.matchPromises)\n\n const failures = results\n // TODO when we drop support for TS 5.4, we can use the built-in type guard for PromiseRejectedResult\n .filter(\n (result): result is PromiseRejectedResult =>\n result.status === 'rejected',\n )\n .map((result) => result.reason)\n\n // Find first redirect (throw immediately) or notFound (throw after head execution)\n let firstNotFound: unknown\n for (const err of failures) {\n if (isRedirect(err)) {\n throw err\n }\n if (!firstNotFound && isNotFound(err)) {\n firstNotFound = err\n }\n }\n\n // serially execute head functions after all loaders have completed (successfully or not)\n // Each head execution is wrapped in try-catch to ensure all heads run even if one fails\n for (const match of inner.matches) {\n const { id: matchId, routeId } = match\n const route = inner.router.looseRoutesById[routeId]!\n try {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n } catch (err) {\n // Log error but continue executing other head functions\n console.error(`Error executing head for route ${routeId}:`, err)\n }\n }\n\n // Throw notFound after head execution\n if (firstNotFound) {\n throw firstNotFound\n }\n\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n } catch (err) {\n if (isNotFound(err) && !inner.preload) {\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) await readyPromise\n throw err\n }\n if (isRedirect(err)) {\n throw err\n }\n }\n return inner.matches\n}\n\nexport async function loadRouteChunk(route: AnyRoute) {\n if (!route._lazyLoaded && route._lazyPromise === undefined) {\n if (route.lazyFn) {\n route._lazyPromise = route.lazyFn().then((lazyRoute) => {\n // explicitly don't copy over the lazy route's id\n const { id: _id, ...options } = lazyRoute.options\n Object.assign(route.options, options)\n route._lazyLoaded = true\n route._lazyPromise = undefined // gc promise, we won't need it anymore\n })\n } else {\n route._lazyLoaded = true\n }\n }\n\n // If for some reason lazy resolves more lazy components...\n // We'll wait for that before we attempt to preload the\n // components themselves.\n if (!route._componentsLoaded && route._componentsPromise === undefined) {\n const loadComponents = () => {\n const preloads = []\n for (const type of componentTypes) {\n const preload = (route.options[type] as any)?.preload\n if (preload) preloads.push(preload())\n }\n if (preloads.length)\n return Promise.all(preloads).then(() => {\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n })\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n return\n }\n route._componentsPromise = route._lazyPromise\n ? route._lazyPromise.then(loadComponents)\n : loadComponents()\n }\n return route._componentsPromise\n}\n\nfunction makeMaybe<TValue, TError>(\n value: TValue,\n error: TError,\n): { status: 'success'; value: TValue } | { status: 'error'; error: TError } {\n if (error) {\n return { status: 'error' as const, error }\n }\n return { status: 'success' as const, value }\n}\n\nexport function routeNeedsPreload(route: AnyRoute) {\n for (const componentType of componentTypes) {\n if ((route.options[componentType] as any)?.preload) {\n return true\n }\n }\n return false\n}\n\nexport const componentTypes = [\n 'component',\n 'errorComponent',\n 'pendingComponent',\n 'notFoundComponent',\n] as const\n"],"names":["tempSsr","beforeLoadContext","match"],"mappings":";;;;;;AAuCA,MAAM,iBAAiB,CAAC,UAAkD;AACxE,MAAI,CAAC,MAAM,UAAU;AACnB,UAAM,WAAW;AACjB,WAAO,MAAM,UAAA;AAAA,EACf;AACF;AAEA,MAAM,iBAAiB,CAAC,OAAyB,YAA6B;AAC5E,SAAO,CAAC,EACN,MAAM,WAAW,CAAC,MAAM,OAAO,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO;AAE7E;AAMA,MAAM,oBAAoB,CACxB,OACA,OACA,sBAA+B,SACH;AAC5B,QAAM,UAAmC;AAAA,IACvC,GAAI,MAAM,OAAO,QAAQ,WAAW,CAAA;AAAA,EAAC;AAEvC,QAAM,MAAM,sBAAsB,QAAQ,QAAQ;AAClD,WAAS,IA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,UAAU;AAC1C,eAAO,OAAO,MAAM,SAAS,OAAO;AACpC,cAAM,cAAc;AACpB,cAAM,eAAe;AAAA,MACvB,CAAC;AAAA,IACH,OAAO;AACL,YAAM,cAAc;AAAA,IACtB;AAAA,EACF;AAKA,MAAI,CAAC,MAAM,qBAAqB,MAAM,uBAAuB,QAAW;AACtE,UAAM,iBAAiB,MAAM;AAC3B,YAAM,WAAW,CAAA;AACjB,iBAAW,QAAQ,gBAAgB;AACjC,cAAM,UAAW,MAAM,QAAQ,IAAI,GAAW;AAC9C,YAAI,QAAS,UAAS,KAAK,QAAA,CAAS;AAAA,MACtC;AACA,UAAI,SAAS;AACX,eAAO,QAAQ,IAAI,QAAQ,EAAE,KAAK,MAAM;AACtC,gBAAM,oBAAoB;AAC1B,gBAAM,qBAAqB;AAAA,QAC7B,CAAC;AACH,YAAM,oBAAoB;AAC1B,YAAM,qBAAqB;AAC3B;AAAA,IACF;AACA,UAAM,qBAAqB,MAAM,eAC7B,MAAM,aAAa,KAAK,cAAc,IACtC,eAAA;AAAA,EACN;AACA,SAAO,MAAM;AACf;AAEA,SAAS,UACP,OACA,OAC2E;AAC3E,MAAI,OAAO;AACT,WAAO,EAAE,QAAQ,SAAkB,MAAA;AAAA,EACrC;AACA,SAAO,EAAE,QAAQ,WAAoB,MAAA;AACvC;AAEO,SAAS,kBAAkB,OAAiB;AACjD,aAAW,iBAAiB,gBAAgB;AAC1C,QAAK,MAAM,QAAQ,aAAa,GAAW,SAAS;AAClD,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
@@ -1,4 +1,10 @@
1
+ /**
2
+ * @deprecated Use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) from the standard Web API directly.
3
+ */
1
4
  export interface JsonResponse<TData> extends Response {
2
5
  json: () => Promise<TData>;
3
6
  }
7
+ /**
8
+ * @deprecated Use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) from the standard Web API directly.
9
+ */
4
10
  export declare function json<TData>(payload: TData, init?: ResponseInit): JsonResponse<TData>;
@@ -1,12 +1,5 @@
1
- import { mergeHeaders } from "./headers.js";
2
1
  function json(payload, init) {
3
- return new Response(JSON.stringify(payload), {
4
- ...init,
5
- headers: mergeHeaders(
6
- { "content-type": "application/json" },
7
- init?.headers
8
- )
9
- });
2
+ return Response.json(payload, init);
10
3
  }
11
4
  export {
12
5
  json
@@ -1 +1 @@
1
- {"version":3,"file":"json.js","sources":["../../../src/ssr/json.ts"],"sourcesContent":["import { mergeHeaders } from './headers'\n\nexport interface JsonResponse<TData> extends Response {\n json: () => Promise<TData>\n}\n\nexport function json<TData>(\n payload: TData,\n init?: ResponseInit,\n): JsonResponse<TData> {\n return new Response(JSON.stringify(payload), {\n ...init,\n headers: mergeHeaders(\n { 'content-type': 'application/json' },\n init?.headers,\n ),\n })\n}\n"],"names":[],"mappings":";AAMO,SAAS,KACd,SACA,MACqB;AACrB,SAAO,IAAI,SAAS,KAAK,UAAU,OAAO,GAAG;AAAA,IAC3C,GAAG;AAAA,IACH,SAAS;AAAA,MACP,EAAE,gBAAgB,mBAAA;AAAA,MAClB,MAAM;AAAA,IAAA;AAAA,EACR,CACD;AACH;"}
1
+ {"version":3,"file":"json.js","sources":["../../../src/ssr/json.ts"],"sourcesContent":["/**\n * @deprecated Use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) from the standard Web API directly.\n */\nexport interface JsonResponse<TData> extends Response {\n json: () => Promise<TData>\n}\n\n/**\n * @deprecated Use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) from the standard Web API directly.\n */\nexport function json<TData>(\n payload: TData,\n init?: ResponseInit,\n): JsonResponse<TData> {\n return Response.json(payload, init)\n}\n"],"names":[],"mappings":"AAUO,SAAS,KACd,SACA,MACqB;AACrB,SAAO,SAAS,KAAK,SAAS,IAAI;AACpC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
- "version": "1.142.8",
3
+ "version": "1.142.13",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -683,8 +683,6 @@ const runLoader = async (
683
683
  // so we need to wait for it to resolve before
684
684
  // we can use the options
685
685
  if (route._lazyPromise) await route._lazyPromise
686
- const headResult = executeHead(inner, matchId, route)
687
- const head = headResult ? await headResult : undefined
688
686
  const pendingPromise = match._nonReactive.minPendingPromise
689
687
  if (pendingPromise) await pendingPromise
690
688
 
@@ -697,7 +695,6 @@ const runLoader = async (
697
695
  status: 'success',
698
696
  isFetching: false,
699
697
  updatedAt: Date.now(),
700
- ...head,
701
698
  }))
702
699
  } catch (e) {
703
700
  let error = e
@@ -721,28 +718,17 @@ const runLoader = async (
721
718
  onErrorError,
722
719
  )
723
720
  }
724
- const headResult = executeHead(inner, matchId, route)
725
- const head = headResult ? await headResult : undefined
726
721
  inner.updateMatch(matchId, (prev) => ({
727
722
  ...prev,
728
723
  error,
729
724
  status: 'error',
730
725
  isFetching: false,
731
- ...head,
732
726
  }))
733
727
  }
734
728
  } catch (err) {
735
729
  const match = inner.router.getMatch(matchId)
736
730
  // in case of a redirecting match during preload, the match does not exist
737
731
  if (match) {
738
- const headResult = executeHead(inner, matchId, route)
739
- if (headResult) {
740
- const head = await headResult
741
- inner.updateMatch(matchId, (prev) => ({
742
- ...prev,
743
- ...head,
744
- }))
745
- }
746
732
  match._nonReactive.loaderPromise = undefined
747
733
  }
748
734
  handleRedirectAndNotFound(inner, match, err)
@@ -767,14 +753,6 @@ const loadRouteMatch = async (
767
753
 
768
754
  if (shouldSkipLoader(inner, matchId)) {
769
755
  if (inner.router.isServer) {
770
- const headResult = executeHead(inner, matchId, route)
771
- if (headResult) {
772
- const head = await headResult
773
- inner.updateMatch(matchId, (prev) => ({
774
- ...prev,
775
- ...head,
776
- }))
777
- }
778
756
  return inner.router.getMatch(matchId)!
779
757
  }
780
758
  } else {
@@ -852,18 +830,6 @@ const loadRouteMatch = async (
852
830
  })()
853
831
  } else if (status !== 'success' || (loaderShouldRunAsync && inner.sync)) {
854
832
  await runLoader(inner, matchId, index, route)
855
- } else {
856
- // if the loader did not run, still update head.
857
- // reason: parent's beforeLoad may have changed the route context
858
- // and only now do we know the route context (and that the loader would not run)
859
- const headResult = executeHead(inner, matchId, route)
860
- if (headResult) {
861
- const head = await headResult
862
- inner.updateMatch(matchId, (prev) => ({
863
- ...prev,
864
- ...head,
865
- }))
866
- }
867
833
  }
868
834
  }
869
835
  }
@@ -931,7 +897,52 @@ export async function loadMatches(arg: {
931
897
  for (let i = 0; i < max; i++) {
932
898
  inner.matchPromises.push(loadRouteMatch(inner, i))
933
899
  }
934
- await Promise.all(inner.matchPromises)
900
+ // Use allSettled to ensure all loaders complete regardless of success/failure
901
+ const results = await Promise.allSettled(inner.matchPromises)
902
+
903
+ const failures = results
904
+ // TODO when we drop support for TS 5.4, we can use the built-in type guard for PromiseRejectedResult
905
+ .filter(
906
+ (result): result is PromiseRejectedResult =>
907
+ result.status === 'rejected',
908
+ )
909
+ .map((result) => result.reason)
910
+
911
+ // Find first redirect (throw immediately) or notFound (throw after head execution)
912
+ let firstNotFound: unknown
913
+ for (const err of failures) {
914
+ if (isRedirect(err)) {
915
+ throw err
916
+ }
917
+ if (!firstNotFound && isNotFound(err)) {
918
+ firstNotFound = err
919
+ }
920
+ }
921
+
922
+ // serially execute head functions after all loaders have completed (successfully or not)
923
+ // Each head execution is wrapped in try-catch to ensure all heads run even if one fails
924
+ for (const match of inner.matches) {
925
+ const { id: matchId, routeId } = match
926
+ const route = inner.router.looseRoutesById[routeId]!
927
+ try {
928
+ const headResult = executeHead(inner, matchId, route)
929
+ if (headResult) {
930
+ const head = await headResult
931
+ inner.updateMatch(matchId, (prev) => ({
932
+ ...prev,
933
+ ...head,
934
+ }))
935
+ }
936
+ } catch (err) {
937
+ // Log error but continue executing other head functions
938
+ console.error(`Error executing head for route ${routeId}:`, err)
939
+ }
940
+ }
941
+
942
+ // Throw notFound after head execution
943
+ if (firstNotFound) {
944
+ throw firstNotFound
945
+ }
935
946
 
936
947
  const readyPromise = triggerOnReady(inner)
937
948
  if (isPromise(readyPromise)) await readyPromise
@@ -945,7 +956,6 @@ export async function loadMatches(arg: {
945
956
  throw err
946
957
  }
947
958
  }
948
-
949
959
  return inner.matches
950
960
  }
951
961
 
package/src/ssr/json.ts CHANGED
@@ -1,18 +1,16 @@
1
- import { mergeHeaders } from './headers'
2
-
1
+ /**
2
+ * @deprecated Use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) from the standard Web API directly.
3
+ */
3
4
  export interface JsonResponse<TData> extends Response {
4
5
  json: () => Promise<TData>
5
6
  }
6
7
 
8
+ /**
9
+ * @deprecated Use [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static) from the standard Web API directly.
10
+ */
7
11
  export function json<TData>(
8
12
  payload: TData,
9
13
  init?: ResponseInit,
10
14
  ): JsonResponse<TData> {
11
- return new Response(JSON.stringify(payload), {
12
- ...init,
13
- headers: mergeHeaders(
14
- { 'content-type': 'application/json' },
15
- init?.headers,
16
- ),
17
- })
15
+ return Response.json(payload, init)
18
16
  }