Nextjs server actions does not work with revalidatePath
Hi there!
I'm struggling with basic data refreshing on a simple next14 app directory page.tsx. Basically this is all code taken from https://docs.convex.dev/client/react/nextjs/server-rendering#server-actions-and-route-handlers.
/src/app/testpage
Everything works quite well. The workspace is created, but the page data does not refresh when using revalidatePath. I'm wondering what could be causing this problem and does it work for anyone else? And will it be possible to revalidate the queries using the next tags?
I can add that I tried using
preloadQuery
and usePreloadedQuery
. Then everything works and refreshes.
But it would be nice however to use revalidate method.5 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
not sure you need to use revalidate and revalidate path with convex
can you say more about why that's a benefit?
you're trying to avoid the server-side computation if you can? for speed?
When I want to keep everything like above getting/creating workspace on server side the data does not refresh. After manually refreshing the page it does, but that's not the point.
I'm only giving the example you have in the documentation because I wanted to test it, and I thought it will work on a server with revalidate.
I just tried something similar and this code works for me:
Is your file
/src/app/testpage/page.tsx
?
Can you one of these working without Convex? I'm guessing Convex is not the issue here, and there's some Next.js subtlety. What version of Next.js are you using?I am very grateful that you wanted to help.
Well after a one day research adventure I am done with it.
https://github.com/vercel/next.js/issues/50659
The problem is in the middleware. This was my middleware.
Unfortunately, here revalidatePath and server actions do not want to work. So I changed the config to
Revalidatepath started working, server actions too, but login and logout stopped working.
so, with the help of chatgpt, I ended up converting the middleware to something like this
I've seen that a lot of people have had this problem so maybe this will be useful to someone if they need it