{"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":["serverActionReducer","createFromFetch","createFromFetchBrowser","createDebugChannel","process","env","__NEXT_DEV_SERVER","__NEXT_REACT_DEBUG_CHANNEL","require","fetchServerAction","state","nextUrl","actionId","actionArgs","temporaryReferences","createTemporaryReferenceSet","info","extractInfoFromServerReferenceId","usedArgs","omitUnusedArgs","body","encodeReply","headers","Accept","RSC_CONTENT_TYPE_HEADER","ACTION_HEADER","NEXT_ROUTER_STATE_TREE_HEADER","prepareFlightRouterStateForRequest","tree","deploymentId","getDeploymentId","NEXT_URL","self","__next_r","NEXT_HTML_REQUEST_ID_HEADER","NEXT_REQUEST_ID_HEADER","crypto","getRandomValues","Uint32Array","toString","res","fetch","canonicalUrl","method","unrecognizedActionHeader","get","NEXT_ACTION_NOT_FOUND_HEADER","UnrecognizedActionError","redirectHeader","location","_redirectType","split","redirectType","undefined","isPrerender","NEXT_IS_PRERENDER_HEADER","revalidationKind","ActionDidNotRevalidate","revalidationHeader","parsedKind","JSON","parse","ActionDidRevalidateStaticAndDynamic","ActionDidRevalidateDynamicOnly","redirectLocation","assignLocation","URL","window","href","contentType","isRscResponse","startsWith","message","status","text","Error","actionResult","actionFlightData","actionFlightDataRenderedSearch","couldBeIntercepted","responsePromise","processFetch","then","response","r","Promise","resolve","callServer","findSourceMapURL","debugChannel","a","i","responseBuildId","NEXT_NAV_DEPLOYMENT_ID_HEADER","b","getNavigationBuildId","maybeFlightData","normalizeFlightData","f","q","action","reject","previousNextUrl","hasInterceptionRouteInCurrentTree","flightData","flightDataRenderedSearch","invalidateBfCache","didRevalidate","invalidateEntirePrefetchCache","startRevalidationCooldown","navigateType","isExternalURL","redirectHref","redirectError","createRedirectErrorForAction","completeHardNavigation","redirectWithBasepath","createHrefFromUrl","hasBasePath","removeBasePath","origin","currentUrl","currentRenderedSearch","renderedSearch","redirectUrl","currentFlightRouterState","scrollBehavior","ScrollBehavior","Default","freshnessPolicy","FreshnessPolicy","RefreshAll","redirectCanonicalUrl","now","Date","redirectSeed","convertServerPatchToFullTree","UnknownDynamicStaleTime","metadataVaryPath","discoverKnownRoute","pathname","routeTree","navigateToKnownRoute","cache","navigate","e","resolvedRedirectType","getRedirectError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