Open Chenalejandro opened 1 month ago
Also not sure yet if this is our mistake or Next.js (suspicion is on the latter), but definitely something that should be fixed. Maybe we should also stop depending on loading.tsx
in the Handler component for the moment, that would lessen the impact of this.
Thanks for the report!
When using
useUser()
andloading.tsx
, the next.js revalidatePath() will not work correctly.Steps to reproduce:
Expected: the input field will be showing the new displayName. Actual: the input field will show the previous displayName.
This bug only happens in the first server action invocation after page refresh. Subsequent server action invocation will revalidate the path correctly.
This issue happens in both dev and production, local or deployed.
The example udpates the displayName, but it can be anything that changes some data and uses revalidatePath() to refresh the page.
I'm not sure if this is a bug caused by next.js itself or by stack-auth. I checked the issues from next.js and the only one that might be related is https://github.com/vercel/next.js/issues/66431
The workaround is to not use
useUser()
and removeloading.tsx
. Just pass the user data from a parent RSC to the child client component. Update: this doesn't work since the /handler/[...stack] still needs the loading.tsx file Second update: just move everything related to the stack-auth to a route group and use the loading.tsx therePlease feel free to contact me if you need any further information.