So, I am very new to NextJS and I was building an app where a user can sign in and perform CRUD operations relative to the user or even the user himself. The architecture I was following (and I don't even know if its right) was:
- In the /dashboard I get the cookie that contains a token
- The token contains the user's id
- I use server side fetching to fetch the user
- I populate my user's component with the user's info while still in the/dashboard,
- I perform crud operations that follow this logic:
- I use useFormState from "react-dom" (cause I use React 19)
- I pass the formAction to the action of the form (form=formAction)
- The action is a server side action where
- I perform my request when I receive the good response (response.status == 200)
- I use NextJS' revalidatePath('/dashboard') to essentially refetch the new data
The weird problem that occurs is that the revalidatePath only works once. If I try to submit the form a second time without reloading the page, the content of the page isn't re-populated with the new info, cause the 'path' isn't revalidated.
I tried to work client side with router.push or refresh but had the same result. My best guess is that it has something to do with the caching.
There are workarounds to solve my problem like just handling the crud operations in different routes, but I wanted to understand why did revalidate and other next functions only run once when you are on the same url.