{"record":{"id":"d43b172000cf97ed","repo":"vercel/next.js","slug":"an-unexpected-response-was-received-from-the-serve","errorCode":null,"errorMessage":"An unexpected response was received from the server.","messagePattern":"An unexpected response was received from the server\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts","lineNumber":234,"sourceCode":"    : 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      {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts#L216-L252","documentation":"Thrown at server-action-reducer.ts:226-234 when a Server Action response is neither an RSC payload (`text/x-component`) nor carries an `x-action-redirect` header. The client expects every valid action response to be Flight data or an external redirect; anything else is treated as a protocol violation and surfaced as a generic `Error` whose message is the response body if it was a `text/plain` error, otherwise this literal string.","triggerScenarios":"The server returned HTML (e.g. a 500 error page, a login redirect, a WAF challenge) instead of an RSC response; a proxy/CDN intercepted the POST and returned a non-Flight body; the action threw an unhandled server exception that Next.js rendered as an error page; the route handler returned a `Response` with the wrong content type.","commonSituations":"Auth middleware redirecting the action POST to a login HTML page; a reverse proxy returning a 502/HTML error page; the server crashing mid-action and returning the default error document; misconfigured `basePath`/`assetPrefix` causing the POST to hit a static host returning HTML.","solutions":["Open the browser devtools Network tab and inspect the action POST response body and status code to identify what the server actually returned.","Check server logs for the unhandled exception that produced an HTML error page instead of an RSC error payload.","Verify no middleware/proxy is intercepting POSTs to the page URL and returning a non-Flight response.","Confirm `basePath` and `assetPrefix` are correct so the action POST reaches the Next.js server."],"exampleFix":"// before: action throws an unhandled error -> HTML error page -> generic message\n'use server'\nexport async function action() {\n  throw 'oops' // non-Error throw produces an opaque server error\n}\n\n// after: throw a proper Error so the server returns a Flight error payload\n'use server'\nexport async function action() {\n  throw new Error('Something went wrong')\n}","handlingStrategy":"try-catch","validationCode":"// Cannot prevent from the client; validate server-side that actions\n// return proper Flight responses. Ensure actions throw Error subclasses\n// so Next.js returns RSC error payloads, not HTML error pages.","typeGuard":"function isLikelyFlightResponse(res: Response): boolean {\n  const ct = res.headers.get('content-type') ?? ''\n  return ct.startsWith('text/x-component')\n}","tryCatchPattern":"'use client'\ntry {\n  await myAction()\n} catch (err) {\n  // err.message may be the server's text/plain body or the generic string.\n  console.error('Action failed:', err instanceof Error ? err.message : err)\n  // Show user-facing fallback UI\n}","preventionTips":["Always throw Error subclasses inside Server Actions so Next.js returns Flight error payloads.","Ensure no middleware/auth layer redirects action POSTs to HTML login pages.","Monitor server logs for unhandled exceptions during action execution.","Verify reverse proxies/CDNs pass through POST bodies and content types unchanged."],"tags":["server-actions","network","app-router","error-handling"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}