-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Plugin version
0.8.2
Payload version
3.37.0
Auth.js version
5.0.0-beta.28
Describe the bug
When using unstable_cache
from Next.js in combination with the payload-authjs
plugin, the application fails during the build process (pnpm build && pnpm start
) with the following error:
Error: Invariant: incrementalCache missing in unstable_cache async function s(){return await new Promise(e=>setTimeout(e,100)),Math.floor(1e3*Math.random())+1}
at <unknown> (C:\repos\Win\test-cache\.next\server\chunks\1906.js:711:4902)
at Object.onInit (C:\repos\Win\test-cache\.next\server\app\(payload)\api\[...slug]\route.js:1:1800)
at tJ.init (C:\repos\Win\test-cache\.next\server\chunks\1906.js:588:18842)
at async tQ (C:\repos\Win\test-cache\.next\server\chunks\1906.js:588:20621)
at async (C:\repos\Win\test-cache\.next\server\chunks\1906.js:710:16006)
The error occurs specifically when calling a cached function within the onInit
hook of the Payload configuration. This works perfectly fine in a vanilla PayloadCMS setup without the payload-authjs
plugin.
To Reproduce
Steps to reproduce the behavior:
-
Create a Next.js 15.3.2 project with PayloadCMS 3.37.0
-
Install and configure
payload-authjs@0.8.2
plugin -
Create a cached function using
unstable_cache
:import { unstable_cache } from 'next/cache' async function generateRandomNumber(): Promise<number> { await new Promise((resolve) => setTimeout(resolve, 100)) return Math.floor(Math.random() * 1000) + 1 } export const getCachedRandomNumber = unstable_cache(generateRandomNumber, ['random-number'], { revalidate: 60, tags: ['random-number'], })
-
Use the cached function in the
onInit
hook:export default buildConfig({ // ... other config onInit: async (payload) => { const randomNumber = await getCachedRandomNumber() console.log(randomNumber) payload.logger.info(`Random number: ${randomNumber}`) }, })
-
Run
pnpm build && pnpm start
-
The error occurs during the initialization process
Additional context / Screenshots
Expected behavior
The cached function should work normally during the build process, just as it does in development mode and in vanilla PayloadCMS setups.
Environment
- Node.js: 18.20.2+ / 20.9.0+
- Package Manager: pnpm
- Next.js: 15.3.2
- PayloadCMS: 3.37.0
- payload-authjs: 0.8.2
- next-auth: 5.0.0-beta.28