{"record":{"id":"bbb18f405a8206cb","repo":"vercel/next.js","slug":"route-workstore-route-used-unstable-prefetch-bbb18f","errorCode":null,"errorMessage":"Route ${workStore.route} used `unstable_prefetch()` inside `after()` while rendering. The `unstable_prefetch()` function is used to indicate the subsequent code must not run in the app shell, but `after()` executes after the request, so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/app/api-reference/functions/after","messagePattern":"Route (.+?) used `unstable_prefetch\\(\\)` inside `after\\(\\)` while rendering\\. The `unstable_prefetch\\(\\)` function is used to indicate the subsequent code must not run in the app shell, but `after\\(\\)` executes after the request, so this function is not allowed in this scope\\. See more info here: https://nextjs\\.org/docs/app/api-reference/functions/after","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/server/request/cache-stages.ts","lineNumber":43,"sourceCode":" * Unlike `connection()`, it does not mark the subtree as request-dependent —\n * content below `await unstable_prefetch()` remains fully cacheable.\n */\nexport function unstable_prefetch(): Promise<void> {\n  const workStore = workAsyncStorage.getStore()\n  const workUnitStore = workUnitAsyncStorage.getStore()\n\n  if (!workStore || !workUnitStore) {\n    const callingExpression = 'unstable_prefetch'\n    throwForMissingRequestStore(callingExpression)\n  }\n  if (!process.env.__NEXT_CACHE_COMPONENTS) {\n    throw new Error(\n      `Route ${workStore.route} used \\`unstable_prefetch()\\`, which requires Cache Components to be enabled. Learn more: https://nextjs.org/docs/app/api-reference/config/next-config-js/cacheComponents`\n    )\n  }\n\n  if (!isRequestApiAllowedInCurrentPhase(workUnitStore)) {\n    throw new Error(\n      `Route ${workStore.route} used \\`unstable_prefetch()\\` inside \\`after()\\` while rendering. The \\`unstable_prefetch()\\` function is used to indicate the subsequent code must not run in the app shell, but \\`after()\\` executes after the request, so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/app/api-reference/functions/after`\n    )\n  }\n\n  switch (workUnitStore.type) {\n    case 'prerender': {\n      // Content below `prefetch()` is excluded from the shell, but it's\n      // deliberately included in the static output (and thus in static\n      // prefetches), so we only delay it until the static prefetch stage.\n      const { stagedRendering } = workUnitStore\n      if (!stagedRendering) {\n        // Prospective prerender\n        // `unstable_prefetch()` will resolve in the final prerender, so resolve it here as well.\n        return Promise.resolve(undefined)\n      } else {\n        // Final prerender\n        return stagedRendering.delayUntilStage(\n          RENDER_STAGES_BY_DATA_KIND.staticLinkData,","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/vercel/next.js/blob/258b1c1bc05f7099816b88f70b7b3422b24a4b8d/packages/next/src/server/request/cache-stages.ts#L25-L61","documentation":"Error \"Route ${workStore.route} used `unstable_prefetch()` inside `after()` while rendering. The `unstable_prefetch()` function is used to indicate the subsequent code must not run in the app shell, but `after()` executes after the request, so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/app/api-reference/functions/after\" thrown in vercel/next.js.","triggerScenarios":"Thrown at packages/next/src/server/request/cache-stages.ts:42 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the unstable_prefetch() call out of the after() callback so it runs during rendering","Await unstable_prefetch() before starting the after() work if ordering matters","Remove unstable_prefetch() if the deferred work does not need prefetch-stage semantics"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"258b1c1bc05f7099816b88f70b7b3422b24a4b8d","analyzedAt":"2026-08-21T19:56:13.433Z","contentChangedAt":"2026-08-21T19:56:13.433Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}