vercel/next.js · error · Error

Route ${workStore.route} used `unstable_prefetch()` inside `

Error message

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

What it means

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.

Source

Thrown at packages/next/src/server/request/cache-stages.ts:43

 * Unlike `connection()`, it does not mark the subtree as request-dependent —
 * content below `await unstable_prefetch()` remains fully cacheable.
 */
export function unstable_prefetch(): Promise<void> {
  const workStore = workAsyncStorage.getStore()
  const workUnitStore = workUnitAsyncStorage.getStore()

  if (!workStore || !workUnitStore) {
    const callingExpression = 'unstable_prefetch'
    throwForMissingRequestStore(callingExpression)
  }
  if (!process.env.__NEXT_CACHE_COMPONENTS) {
    throw new Error(
      `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`
    )
  }

  if (!isRequestApiAllowedInCurrentPhase(workUnitStore)) {
    throw new 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`
    )
  }

  switch (workUnitStore.type) {
    case 'prerender': {
      // Content below `prefetch()` is excluded from the shell, but it's
      // deliberately included in the static output (and thus in static
      // prefetches), so we only delay it until the static prefetch stage.
      const { stagedRendering } = workUnitStore
      if (!stagedRendering) {
        // Prospective prerender
        // `unstable_prefetch()` will resolve in the final prerender, so resolve it here as well.
        return Promise.resolve(undefined)
      } else {
        // Final prerender
        return stagedRendering.delayUntilStage(
          RENDER_STAGES_BY_DATA_KIND.staticLinkData,

View on GitHub (pinned to 258b1c1bc0)

Solutions

  1. Move the unstable_prefetch() call out of the after() callback so it runs during rendering
  2. Await unstable_prefetch() before starting the after() work if ordering matters
  3. Remove unstable_prefetch() if the deferred work does not need prefetch-stage semantics
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/next/src/server/request/cache-stages.ts:42 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of vercel/next.js@258b1c1bc0 (2026-08-21). Data as JSON: /api/errors/bbb18f405a8206cb. Report an issue: GitHub.