{"record":{"id":"32eda4cf3467c639","repo":"vercel/next.js","slug":"route-workstore-route-used-headers-inside","errorCode":null,"errorMessage":"Route ${workStore.route} used `headers()` inside `after()` while rendering. This is not supported. If you need this data inside an `after()` callback, use `headers()` outside of the callback. See more info here: https://nextjs.org/docs/app/api-reference/functions/after","messagePattern":"Route (.+?) used `headers\\(\\)` inside `after\\(\\)` while rendering\\. This is not supported\\. If you need this data inside an `after\\(\\)` callback, use `headers\\(\\)` outside of the callback\\. See more info here: https://nextjs\\.org/docs/app/api-reference/functions/after","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next/src/server/request/headers.ts","lineNumber":50,"sourceCode":"} from '../use-cache/use-cache-messages'\n\n/**\n * This function allows you to read the HTTP incoming request headers in\n * [Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components),\n * [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations),\n * [Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers) and\n * [Middleware](https://nextjs.org/docs/app/building-your-application/routing/middleware).\n *\n * Read more: [Next.js Docs: `headers`](https://nextjs.org/docs/app/api-reference/functions/headers)\n */\nexport function headers(): Promise<ReadonlyHeaders> {\n  const callingExpression = 'headers'\n  const workStore = workAsyncStorage.getStore()\n  const workUnitStore = workUnitAsyncStorage.getStore()\n\n  if (workStore) {\n    if (workUnitStore && !isRequestApiAllowedInCurrentPhase(workUnitStore)) {\n      throw new Error(\n        `Route ${workStore.route} used \\`headers()\\` inside \\`after()\\` while rendering. This is not supported. If you need this data inside an \\`after()\\` callback, use \\`headers()\\` outside of the callback. See more info here: https://nextjs.org/docs/app/api-reference/functions/after`\n      )\n    }\n\n    if (workStore.forceStatic) {\n      // When using forceStatic we override all other logic and always just return an empty\n      // headers object without tracking\n      const underlyingHeaders = HeadersAdapter.seal(new Headers({}))\n      return makeUntrackedHeaders(underlyingHeaders)\n    }\n\n    if (workUnitStore) {\n      switch (workUnitStore.type) {\n        case 'cache': {\n          const error = createHeadersInUseCacheError(workStore.route)\n          Error.captureStackTrace(error, headers)\n          applyOwnerStack(error)\n          workStore.invalidDynamicUsageError ??= error","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/vercel/next.js/blob/258b1c1bc05f7099816b88f70b7b3422b24a4b8d/packages/next/src/server/request/headers.ts#L32-L68","documentation":"Error \"Route ${workStore.route} used `headers()` inside `after()` while rendering. This is not supported. If you need this data inside an `after()` callback, use `headers()` outside of the callback. See more info here: https://nextjs.org/docs/app/api-reference/functions/after\" thrown in vercel/next.js.","triggerScenarios":"headers() is called inside an after() callback during render.","commonSituations":"Reading headers inside unstable_after; read them outside and pass values in.","solutions":["Read headers() before scheduling after(), and pass the values into the callback closure."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"258b1c1bc05f7099816b88f70b7b3422b24a4b8d","analyzedAt":"2026-08-19T02:10:13.922Z","contentChangedAt":"2026-08-19T02:10:13.922Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}