{"version":3,"sources":["../../../../../../src/client/components/router-reducer/reducers/server-action-reducer.ts"],"sourcesContent":["import type {\n  ActionFlightResponse,\n  ActionResult,\n} from '../../../../shared/lib/app-router-types'\nimport { callServer } from '../../../app-call-server'\nimport { findSourceMapURL } from '../../../app-find-source-map-url'\nimport {\n  ACTION_HEADER,\n  NEXT_ACTION_NOT_FOUND_HEADER,\n  NEXT_IS_PRERENDER_HEADER,\n  NEXT_HTML_REQUEST_ID_HEADER,\n  NEXT_ROUTER_STATE_TREE_HEADER,\n  NEXT_URL,\n  RSC_CONTENT_TYPE_HEADER,\n  NEXT_REQUEST_ID_HEADER,\n} from '../../app-router-headers'\nimport { UnrecognizedActionError } from '../../unrecognized-action-error'\n\n// TODO: Explicitly import from client.browser\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport {\n  createFromFetch as createFromFetchBrowser,\n  createTemporaryReferenceSet,\n  encodeReply,\n} from 'react-server-dom-webpack/client'\n\nimport type {\n  ReadonlyReducerState,\n  ReducerState,\n  ServerActionAction,\n} from '../router-reducer-types'\nimport { ScrollBehavior } from '../router-reducer-types'\nimport { assignLocation } from '../../../assign-location'\nimport { createHrefFromUrl } from '../create-href-from-url'\nimport { hasInterceptionRouteInCurrentTree } from './has-interception-route-in-current-tree'\nimport {\n  normalizeFlightData,\n  prepareFlightRouterStateForRequest,\n  type NormalizedFlightData,\n} from '../../../flight-data-helpers'\nimport { getRedirectError } from '../../redirect'\nimport type { RedirectType } from '../../redirect-error'\nimport { removeBasePath } from '../../../remove-base-path'\nimport { hasBasePath } from '../../../has-base-path'\nimport {\n  extractInfoFromServerReferenceId,\n  omitUnusedArgs,\n} from '../../../../shared/lib/server-reference-info'\nimport { invalidateEntirePrefetchCache } from '../../segment-cache/cache'\nimport { startRevalidationCooldown } from '../../segment-cache/scheduler'\nimport { getDeploymentId } from '../../../../shared/lib/deployment-id'\nimport { getNavigationBuildId } from '../../../navigation-build-id'\nimport { NEXT_NAV_DEPLOYMENT_ID_HEADER } from '../../../../lib/constants'\nimport {\n  completeHardNavigation,\n  convertServerPatchToFullTree,\n  navigateToKnownRoute,\n  navigate,\n} from '../../segment-cache/navigation'\nimport { discoverKnownRoute } from '../../segment-cache/optimistic-routes'\nimport type { NormalizedSearch } from '../../segment-cache/cache-key'\nimport {\n  ActionDidNotRevalidate,\n  ActionDidRevalidateDynamicOnly,\n  ActionDidRevalidateStaticAndDynamic,\n  type ActionRevalidationKind,\n} from '../../../../shared/lib/action-revalidation-kind'\nimport { isExternalURL } from '../../app-router-utils'\nimport { FreshnessPolicy } from '../ppr-navigations'\nimport { processFetch } from '../fetch-server-response'\nimport {\n  invalidateBfCache,\n  UnknownDynamicStaleTime,\n} from '../../segment-cache/bfcache'\n\nconst createFromFetch =\n  createFromFetchBrowser as (typeof import('react-server-dom-webpack/client.browser'))['createFromFetch']\n\nlet createDebugChannel:\n  | typeof import('../../../dev/debug-channel').createDebugChannel\n  | undefined\n\nif (process.env.__NEXT_DEV_SERVER && process.env.__NEXT_REACT_DEBUG_CHANNEL) {\n  createDebugChannel = (\n    require('../../../dev/debug-channel') as typeof import('../../../dev/debug-channel')\n  ).createDebugChannel\n}\n\n// TODO: Refactor to be a discriminated union. Or just get rid of it;\n// fetchServerAction only has one caller, no reason this intermediate type has\n// to exist.\ntype FetchServerActionResult = {\n  redirectLocation: URL | undefined\n  redirectType: RedirectType | undefined\n  revalidationKind: ActionRevalidationKind\n  actionResult: ActionResult | undefined\n  actionFlightData: NormalizedFlightData[] | string | undefined\n  actionFlightDataRenderedSearch: NormalizedSearch | undefined\n  isPrerender: boolean\n  couldBeIntercepted: boolean\n}\n\nasync function fetchServerAction(\n  state: ReadonlyReducerState,\n  nextUrl: ReadonlyReducerState['nextUrl'],\n  { actionId, actionArgs }: ServerActionAction\n): Promise<FetchServerActionResult> {\n  const temporaryReferences = createTemporaryReferenceSet()\n  const info = extractInfoFromServerReferenceId(actionId)\n  const usedArgs = omitUnusedArgs(actionArgs, info)\n  const body = await encodeReply(usedArgs, { temporaryReferences })\n\n  const headers: Record<string, string> = {\n    Accept: RSC_CONTENT_TYPE_HEADER,\n    [ACTION_HEADER]: actionId,\n    [NEXT_ROUTER_STATE_TREE_HEADER]: prepareFlightRouterStateForRequest(\n      state.tree\n    ),\n  }\n\n  const deploymentId = getDeploymentId()\n  if (deploymentId) {\n    headers['x-deployment-id'] = deploymentId\n  }\n\n  if (nextUrl) {\n    headers[NEXT_URL] = nextUrl\n  }\n\n  if (process.env.__NEXT_DEV_SERVER) {\n    if (self.__next_r) {\n      headers[NEXT_HTML_REQUEST_ID_HEADER] = self.__next_r\n    }\n\n    // Create a new request ID for the server action request. The server uses\n    // this to tag debug information sent via WebSocket to the client, which\n    // then routes those chunks to the debug channel associated with this ID.\n    headers[NEXT_REQUEST_ID_HEADER] = crypto\n      .getRandomValues(new Uint32Array(1))[0]\n      .toString(16)\n  }\n\n  const res = await fetch(state.canonicalUrl, { method: 'POST', headers, body })\n\n  // Handle server actions that the server didn't recognize.\n  const unrecognizedActionHeader = res.headers.get(NEXT_ACTION_NOT_FOUND_HEADER)\n  if (unrecognizedActionHeader === '1') {\n    throw new UnrecognizedActionError(\n      `Server Action \"${actionId}\" was not found on the server. \\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action`\n    )\n  }\n\n  const redirectHeader = res.headers.get('x-action-redirect')\n  const [location, _redirectType] = redirectHeader?.split(';') || []\n  let redirectType: RedirectType | undefined\n  switch (_redirectType) {\n    case 'push':\n      redirectType = 'push'\n      break\n    case 'replace':\n      redirectType = 'replace'\n      break\n    default:\n      redirectType = undefined\n  }\n\n  const isPrerender = !!res.headers.get(NEXT_IS_PRERENDER_HEADER)\n\n  let revalidationKind: ActionRevalidationKind = ActionDidNotRevalidate\n  try {\n    const revalidationHeader = res.headers.get('x-action-revalidated')\n    if (revalidationHeader) {\n      const parsedKind = JSON.parse(revalidationHeader)\n      if (\n        parsedKind === ActionDidRevalidateStaticAndDynamic ||\n        parsedKind === ActionDidRevalidateDynamicOnly\n      ) {\n        revalidationKind = parsedKind\n      }\n    }\n  } catch {}\n\n  const redirectLocation = location\n    ? assignLocation(\n        location,\n        new URL(state.canonicalUrl, window.location.href)\n      )\n    : undefined\n\n  const contentType = res.headers.get('content-type')\n  const isRscResponse = !!(\n    contentType && contentType.startsWith(RSC_CONTENT_TYPE_HEADER)\n  )\n\n  // Handle invalid server action responses.\n  // A valid response must have `content-type: text/x-component`, unless it's an external redirect.\n  // (external redirects have an 'x-action-redirect' header, but the body is an empty 'text/plain')\n  if (!isRscResponse && !redirectLocation) {\n    // The server can respond with a text/plain error message, but we'll fallback to something generic\n    // if there isn't one.\n    const message =\n      res.status >= 400 && contentType === 'text/plain'\n        ? await res.text()\n        : 'An unexpected response was received from the server.'\n\n    throw new Error(message)\n  }\n\n  let actionResult: FetchServerActionResult['actionResult']\n  let actionFlightData: FetchServerActionResult['actionFlightData']\n  let actionFlightDataRenderedSearch: FetchServerActionResult['actionFlightDataRenderedSearch']\n  let couldBeIntercepted: boolean = false\n\n  if (isRscResponse) {\n    // Server action redirect responses carry the Flight data of the redirect\n    // target, which may be prerendered with a completeness marker byte\n    // prepended. Strip it before passing to Flight.\n    const responsePromise = redirectLocation\n      ? processFetch(res).then(({ response: r }) => r)\n      : Promise.resolve(res)\n\n    const response: ActionFlightResponse = await createFromFetch(\n      responsePromise,\n      {\n        callServer,\n        findSourceMapURL,\n        temporaryReferences,\n        debugChannel: createDebugChannel && createDebugChannel(headers),\n      }\n    )\n\n    // An internal redirect can send an RSC response, but does not have a useful `actionResult`.\n    actionResult = redirectLocation ? undefined : response.a\n    couldBeIntercepted = response.i\n\n    // Check if the response build ID matches the client build ID.\n    // In a multi-zone setup, when a server action triggers a redirect,\n    // the server pre-fetches the redirect target as RSC. If the redirect\n    // target is served by a different Next.js zone (different build), the\n    // pre-fetched RSC data will have a foreign build ID. We must discard\n    // the flight data in that case so the redirect triggers an MPA\n    // navigation (full page load) instead of trying to apply the foreign\n    // RSC payload — which would result in a blank page.\n    const responseBuildId =\n      res.headers.get(NEXT_NAV_DEPLOYMENT_ID_HEADER) ?? response.b\n    if (\n      responseBuildId !== undefined &&\n      responseBuildId !== getNavigationBuildId()\n    ) {\n      // Build ID mismatch — discard the flight data. The redirect will\n      // still be processed, and the absence of flight data will cause an\n      // MPA navigation via completeHardNavigation().\n    } else {\n      const maybeFlightData = normalizeFlightData(response.f)\n      if (maybeFlightData !== '') {\n        actionFlightData = maybeFlightData\n        actionFlightDataRenderedSearch = response.q as NormalizedSearch\n      }\n    }\n  } else {\n    // An external redirect doesn't contain RSC data.\n    actionResult = undefined\n    actionFlightData = undefined\n    actionFlightDataRenderedSearch = undefined\n  }\n\n  return {\n    actionResult,\n    actionFlightData,\n    actionFlightDataRenderedSearch,\n    redirectLocation,\n    redirectType,\n    revalidationKind,\n    isPrerender,\n    couldBeIntercepted,\n  }\n}\n\n/*\n * This reducer is responsible for calling the server action and processing any side-effects from the server action.\n * It does not mutate the state by itself but rather delegates to other reducers to do the actual mutation.\n */\nexport function serverActionReducer(\n  state: ReadonlyReducerState,\n  action: ServerActionAction\n): ReducerState {\n  const { resolve, reject } = action\n\n  // only pass along the `nextUrl` param (used for interception routes) if the current route was intercepted.\n  // If the route has been intercepted, the action should be as well.\n  // Otherwise the server action might be intercepted with the wrong action id\n  // (ie, one that corresponds with the intercepted route)\n  const nextUrl =\n    // We always send the last next-url, not the current when\n    // performing a dynamic request. This is because we update\n    // the next-url after a navigation, but we want the same\n    // interception route to be matched that used the last\n    // next-url.\n    (state.previousNextUrl || state.nextUrl) &&\n    hasInterceptionRouteInCurrentTree(state.tree)\n      ? state.previousNextUrl || state.nextUrl\n      : null\n\n  return fetchServerAction(state, nextUrl, action).then(\n    async ({\n      revalidationKind,\n      actionResult,\n      actionFlightData: flightData,\n      actionFlightDataRenderedSearch: flightDataRenderedSearch,\n      redirectLocation,\n      redirectType,\n      isPrerender,\n      couldBeIntercepted,\n    }) => {\n      if (revalidationKind !== ActionDidNotRevalidate) {\n        // There was either a revalidation or a refresh, or maybe both.\n\n        // Evict the BFCache, which may contain dynamic data.\n        invalidateBfCache()\n\n        // Store whether this action triggered any revalidation\n        // The action queue will use this information to potentially\n        // trigger a refresh action if the action was discarded\n        // (ie, due to a navigation, before the action completed)\n        action.didRevalidate = true\n\n        // If there was a revalidation, evict the prefetch cache.\n        // TODO: Evict only segments with matching tags and/or paths.\n        // TODO: We should only invalidate the route cache if cookies were\n        // mutated, since route trees may vary based on cookies. For now we\n        // invalidate both caches until we have a way to detect cookie\n        // mutations on the client.\n        if (revalidationKind === ActionDidRevalidateStaticAndDynamic) {\n          invalidateEntirePrefetchCache(nextUrl, state.tree)\n        }\n\n        // Start a cooldown before re-prefetching to allow CDN cache\n        // propagation.\n        startRevalidationCooldown()\n      }\n\n      const navigateType = redirectType || 'push'\n\n      if (redirectLocation !== undefined) {\n        // If the action triggered a redirect, the action promise will be rejected with\n        // a redirect so that it's handled by RedirectBoundary as we won't have a valid\n        // action result to resolve the promise with. This will effectively reset the state of\n        // the component that called the action as the error boundary will remount the tree.\n        // The status code doesn't matter here as the action handler will have already sent\n        // a response with the correct status code.\n\n        if (isExternalURL(redirectLocation)) {\n          // External redirect. Triggers an MPA navigation.\n          const redirectHref = redirectLocation.href\n          const redirectError = createRedirectErrorForAction(\n            redirectHref,\n            navigateType\n          )\n          reject(redirectError)\n          return completeHardNavigation(state, redirectLocation, navigateType)\n        } else {\n          // Internal redirect. Triggers an SPA navigation.\n          const redirectWithBasepath = createHrefFromUrl(\n            redirectLocation,\n            false\n          )\n          const redirectHref = hasBasePath(redirectWithBasepath)\n            ? removeBasePath(redirectWithBasepath)\n            : redirectWithBasepath\n          const redirectError = createRedirectErrorForAction(\n            redirectHref,\n            navigateType\n          )\n          reject(redirectError)\n        }\n      } else {\n        // If there's no redirect, resolve the action with the result.\n        resolve(actionResult)\n      }\n\n      // Check if we can bail out without updating any state.\n      if (\n        // Did the action trigger a redirect?\n        redirectLocation === undefined &&\n        // Did the action revalidate any data?\n        revalidationKind === ActionDidNotRevalidate &&\n        // Did the server render new data?\n        flightData === undefined\n      ) {\n        // The action did not trigger any revalidations or redirects. No\n        // navigation is required.\n        return state\n      }\n\n      if (flightData === undefined && redirectLocation !== undefined) {\n        // The server redirected, but did not send any Flight data. This implies\n        // an external redirect.\n        // TODO: We should refactor the action response type to be more explicit\n        // about the various response types.\n        return completeHardNavigation(state, redirectLocation, navigateType)\n      }\n\n      if (typeof flightData === 'string') {\n        // If the flight data is just a string, something earlier in the\n        // response handling triggered an external redirect.\n        return completeHardNavigation(\n          state,\n          new URL(flightData, location.origin),\n          navigateType\n        )\n      }\n\n      // The action triggered a navigation — either a redirect, a revalidation,\n      // or both.\n\n      // If there was no redirect, then the target URL is the same as the\n      // current URL.\n      const currentUrl = new URL(state.canonicalUrl, location.origin)\n      const currentRenderedSearch = state.renderedSearch\n      const redirectUrl =\n        redirectLocation !== undefined ? redirectLocation : currentUrl\n      const currentFlightRouterState = state.tree\n      const scrollBehavior = ScrollBehavior.Default\n\n      // If the action triggered a revalidation of the cache, we should also\n      // refresh all the dynamic data.\n      const freshnessPolicy =\n        revalidationKind === ActionDidNotRevalidate\n          ? FreshnessPolicy.Default\n          : FreshnessPolicy.RefreshAll\n\n      // The server may have sent back new data. If so, we will perform a\n      // \"seeded\" navigation that uses the data from the response.\n      // TODO: Currently the server always renders from the root in\n      // response to a Server Action. In the case of a normal redirect\n      // with no revalidation, it should skip over the shared layouts.\n      if (flightData !== undefined && flightDataRenderedSearch !== undefined) {\n        // The server sent back new route data as part of the response. We\n        // will use this to render the new page. If this happens to be only a\n        // subset of the data needed to render the new page, we'll initiate a\n        // new fetch, like we would for a normal navigation.\n        const redirectCanonicalUrl = createHrefFromUrl(redirectUrl)\n        const now = Date.now()\n        // TODO: Store the dynamic stale time on the top-level state so it's\n        // known during restores and refreshes.\n        const redirectSeed = convertServerPatchToFullTree(\n          now,\n          currentFlightRouterState,\n          flightData,\n          flightDataRenderedSearch,\n          UnknownDynamicStaleTime\n        )\n\n        // Learn the route pattern so we can predict it for future navigations.\n        const metadataVaryPath = redirectSeed.metadataVaryPath\n        if (metadataVaryPath !== null) {\n          discoverKnownRoute(\n            now,\n            redirectUrl.pathname,\n            nextUrl,\n            null, // No pending entry\n            redirectSeed.routeTree,\n            metadataVaryPath,\n            couldBeIntercepted,\n            redirectCanonicalUrl,\n            isPrerender,\n            false // hasDynamicRewrite\n          )\n        }\n\n        return navigateToKnownRoute(\n          now,\n          state,\n          redirectUrl,\n          redirectCanonicalUrl,\n          redirectSeed,\n          currentUrl,\n          currentRenderedSearch,\n          state.cache,\n          currentFlightRouterState,\n          freshnessPolicy,\n          nextUrl,\n          scrollBehavior,\n          navigateType,\n          null,\n          // Server action redirects don't use route prediction - we already\n          // have the route tree from the server response. If a mismatch occurs\n          // during dynamic data fetch, the retry handler will traverse the\n          // known route tree to mark the entry as having a dynamic rewrite.\n          null\n        )\n      }\n\n      // The server did not send back new data. We'll perform a regular, non-\n      // seeded navigation — effectively the same as <Link> or router.push().\n      return navigate(\n        state,\n        redirectUrl,\n        currentUrl,\n        currentRenderedSearch,\n        state.cache,\n        currentFlightRouterState,\n        nextUrl,\n        freshnessPolicy,\n        scrollBehavior,\n        navigateType\n      )\n    },\n    (e: any) => {\n      // When the server action is rejected we don't update the state and instead call the reject handler of the promise.\n      reject(e)\n\n      return state\n    }\n  )\n}\n\nfunction createRedirectErrorForAction(\n  redirectHref: string,\n  resolvedRedirectType: RedirectType\n) {\n  const redirectError = getRedirectError(redirectHref, resolvedRedirectType)\n  // We mark the error as handled because we don't want the redirect to be tried later by\n  // the RedirectBoundary, in case the user goes back and `Activity` triggers the redirect\n  // again, as it's run within an effect.\n  // We don't actually need the RedirectBoundary to do a router.push because we already\n  // have all the necessary RSC data to render the new page within a single roundtrip.\n  ;(redirectError as any).handled = true\n  return redirectError\n}\n"],"names":["callServer","findSourceMapURL","ACTION_HEADER","NEXT_ACTION_NOT_FOUND_HEADER","NEXT_IS_PRERENDER_HEADER","NEXT_HTML_REQUEST_ID_HEADER","NEXT_ROUTER_STATE_TREE_HEADER","NEXT_URL","RSC_CONTENT_TYPE_HEADER","NEXT_REQUEST_ID_HEADER","UnrecognizedActionError","createFromFetch","createFromFetchBrowser","createTemporaryReferenceSet","encodeReply","ScrollBehavior","assignLocation","createHrefFromUrl","hasInterceptionRouteInCurrentTree","normalizeFlightData","prepareFlightRouterStateForRequest","getRedirectError","removeBasePath","hasBasePath","extractInfoFromServerReferenceId","omitUnusedArgs","invalidateEntirePrefetchCache","startRevalidationCooldown","getDeploymentId","getNavigationBuildId","NEXT_NAV_DEPLOYMENT_ID_HEADER","completeHardNavigation","convertServerPatchToFullTree","navigateToKnownRoute","navigate","discoverKnownRoute","ActionDidNotRevalidate","ActionDidRevalidateDynamicOnly","ActionDidRevalidateStaticAndDynamic","isExternalURL","FreshnessPolicy","processFetch","invalidateBfCache","UnknownDynamicStaleTime","createDebugChannel","process","env","__NEXT_DEV_SERVER","__NEXT_REACT_DEBUG_CHANNEL","require","fetchServerAction","state","nextUrl","actionId","actionArgs","temporaryReferences","info","usedArgs","body","headers","Accept","tree","deploymentId","self","__next_r","crypto","getRandomValues","Uint32Array","toString","res","fetch","canonicalUrl","method","unrecognizedActionHeader","get","redirectHeader","location","_redirectType","split","redirectType","undefined","isPrerender","revalidationKind","revalidationHeader","parsedKind","JSON","parse","redirectLocation","URL","window","href","contentType","isRscResponse","startsWith","message","status","text","Error","actionResult","actionFlightData","actionFlightDataRenderedSearch","couldBeIntercepted","responsePromise","then","response","r","Promise","resolve","debugChannel","a","i","responseBuildId","b","maybeFlightData","f","q","serverActionReducer","action","reject","previousNextUrl","flightData","flightDataRenderedSearch","didRevalidate","navigateType","redirectHref","redirectError","createRedirectErrorForAction","redirectWithBasepath","origin","currentUrl","currentRenderedSearch","renderedSearch","redirectUrl","currentFlightRouterState","scrollBehavior","Default","freshnessPolicy","RefreshAll","redirectCanonicalUrl","now","Date","redirectSeed","metadataVaryPath","pathname","routeTree","cache","e","resolvedRedirect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