Open tilman opened 2 weeks ago
UPDATE: I have added a new example to the bug repo: awaitedTimeout I this example the setTimeout is working. Most likely due to being awaited and the response is sent after the revalidatePath was called and not the other way around as in the regular timeout example route
Link to the code that reproduces this issue
https://github.com/trieb-work/nextjs-bug-revalidatetag-inside-settimeout
To Reproduce
NODE_ENV=production VERCEL_ENV=production pnpm build && NODE_ENV=production VERCEL_ENV=production pnpm start
Current vs. Expected behavior
if revalidateTag/revalidatePath is used inside a setTimeout it does not have any effect (tested in nodejs), but still the remaining code inside the setTimeout is executed. I implemented my own cache handler (like here: https://nextjs.org/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath) and could see that the revalidateTag function from the cache handler is never called if the nextjs revalidateTag function is called inside a setTimeout.
Provide environment information
Which area(s) are affected? (Select all that apply)
Performance, Runtime
Which stage(s) are affected? (Select all that apply)
Other (Deployed)
Additional context
I have not tested it in deployed vercel env as we are self hosting using docker and nodejs.
I have also tested to wrap the setTimeout in an
unstable_after
function but this has not helped as well.As a workaround the code can be rewritten to use a sleep/delay function (
const sleep = (ms: number) => new Promise((res) => setTimeout(res, ms));
) instead of a setTimout directly. Calling revalidateTag after the sleep function works as expected (await sleep(100); revalidatePath("/")
)