Next.js Discord

Discord Forum

Router cache shows invalid state when using AI SDK.

Unanswered
Giant Angora posted this in #help-forum
Open in Discord
Avatar
Giant AngoraOP
So I have a ChatGPT-styled application where the user has a list of conversations on the left side. Conversations are all stored in the postgres datase with each conversation having its own route (/chat/{id}). I use server action to load the currently needed conversation (id is extracted from the URL) which is then used to pass initialAIState and initialUIState props to the provider created through Vercel AI SDK's createAI function. However, when the user sends the message, I can do a revalidatePath but what about the AI's response. Once the AI's response is complete, it never invalidates the path (and the user only sees the cached version from the router cache, all on the client side) as it's a stream - I do store it in the database as well though. Any ideas around this? Or what's the best practice to implement such kind of scenarios. Thank you!

0 Replies