Open eduardodallmann opened 3 weeks ago
I am seeing a similar issue on v14.2.14. I have a link like this:
const debouncedRevalidatePath = useCallback(debounce((path) => revalidate(path), 1000), [revalidate]);
<Link
href={messageLink(row.original)}
onClick={
!row.original.read
? () => debouncedRevalidatePath(pathname)
: undefined
}
prefetch={false}
tabIndex={-1}>link</Link>
where revalidate
is the following server action:
export async function revalidate(path: string) {
revalidatePath(path);
}
What I'm seeing is that after the page navigation when the debounced revalidatePath is called, a new entry gets added to my browser's history stack. So I have to press the back button twice to go back to where I was before clicking the link.
Link to the code that reproduces this issue
https://codesandbox.io/p/github/eduardodallmann/app-next-server-action-problem-2
To Reproduce
Current vs. Expected behavior
I will describe how my application works. It has a listing of events. When I click edit, I navigate to events/[slug]. The form will use a server action with debouncing to save. To control this debouncing I use context api, also to show on the screen that it is saving. After making an edit to the form and waiting 2 seconds, the data is saved and the /events path is revalidated. Everything works perfectly.
Now I will describe the problem. When I edit the form and click on the backdrop quickly before 2 seconds, the drawer is closed and the application navigates to /events again. When the 2 seconds are complete, the server action is executed, the data change is saved, but the list in the table is not updated.
Provide environment information
Which area(s) are affected? (Select all that apply)
Navigation
Which stage(s) are affected? (Select all that apply)
next dev (local), Vercel (Deployed)
Additional context
I tested with 14.2.12 and 15.0.0-canary.158
Repo https://github.com/eduardodallmann/app-next-server-action-problem-2