Skip to content

Cannot use next/cache revalidation like revalidatePath() in jobs #16392

@linobino1

Description

@linobino1

Describe the Bug

Calling revalidation functions in the jobs queue like this:

import type { TaskConfig } from 'payload'
import { revalidatePath } from 'next/cache'

export const updateFeeds: TaskConfig<'updateFeeds'> = {
  slug: 'updateFeeds',
  handler: async () => {
    try {
      revalidatePath(`${process.env.NEXT_PUBLIC_BACKEND_URL}/feed.xml`)
      return {
        state: 'succeeded',
        output: null,
      }
    } catch (error) {
      return {
        state: 'failed',
        output: null,
      }
    }
  },
}

Produces an error:

Route /admin/[[...segments]] used "revalidatePath /feed/google" during render which is unsupported. To ensure revalidation is performed consistently it must always happen outside of renders and cached functions. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering

I think a workaround is to call create an API endpoint for the revalidation and call that in the task.

Link to the code that reproduces this issue

https://github.com/linobino1/repro-payload-revalidate-in-jobs

Reproduction Steps

  1. pnpm build
  2. pnpm start
  3. hit http://localhost:3000
  4. the job should be picked up within 60s
  5. check console for error logs

Which area(s) are affected?

area: core

Environment Info

Binaries:
  Node: 25.9.0
  npm: 11.12.1
  Yarn: N/A
  pnpm: 10.33.2
Relevant Packages:
  payload: 3.84.1
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:54:46 PST 2026; root:xnu-12377.91.3~2/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions