Trouble with Revalidation
Unanswered
Masai Lion posted this in #help-forum
Masai LionOP
"On a page
I've attempted revalidation with:
placed in the API route, pre-response, post-saving of last message, and client side post-message load. No luck.
Eventually, I tried the unstable_cache feature like so:
Calling
app/chat/[uuid4]/page.tsx, I use chat = await getChatById(params.uuid4) to fetch chat. In the client side, I can interface with chatGPT via an API. However, when I return to a previously created chat, I don't see updated messages unless I reload the page.I've attempted revalidation with:
revalidatePath("/")revalidatePath("chat/[uuid4]")placed in the API route, pre-response, post-saving of last message, and client side post-message load. No luck.
Eventually, I tried the unstable_cache feature like so:
const getCachedChat = (chatId: string) => {
console.log(`Fetching chat ${chatId}`)
return unstable_cache(() => getChatById(chatId), [`chat-${chatId}`], {
tags: [`chat-${chatId}`, 'chats']
})
}Calling
revalidateTag(chat-${chatId}) and revalidateTag('chats') in both API route & client, but still no revalidation. Oddly, client side only logs the first console log statement. Struggling to understand how revalidation works at all. Any suggestions would be appreciated."3 Replies
Masai LionOP
Video demo.
I tried Next.js versions 13.5.6 and 14.0, same thing. Also only Next.js 14 prints these errors to console for some reason.
Masai LionOP
Update: I put revalidation inside server-action and it worked. For some reason it didn't work in api route or client component.