Replies: 1 comment 2 replies
-
Hi @april0391, Thanks for the detailed description. This behavior where redirect() inside a Server Action triggers the redirect server-side but the browser doesn’t navigate on the first attempt is a known quirk with the current App Router and Server Actions implementation. What’s happening? However, the client-side navigation depends on the client receiving and handling that redirect correctly. Sometimes on the very first attempt, the client doesn’t fully hydrate or hasn’t yet loaded the necessary JavaScript for the new route, so it fails to navigate, even though the network shows the redirect. Refreshing works because all JS bundles are loaded by then. Workarounds: Force reload after redirect Keep an eye on Next.js updates In short: for reliable navigation on the first try, handling redirects client-side after the server action resolves is the current best practice. Let me know if you want help refactoring your code that way. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm using the App Router in Next.js and calling a server action via useActionState. Inside that server action, I perform some validation and then call redirect(/download/${download.id}) if everything passes.
Here's a simplified version of my client component:
In the verifyOrderInfo server action, I call redirect() like this:
The Problem:
On the first attempt, the server action runs successfully.
The server log shows a redirect to /download/${downloadId}, and I can see a GET request for that path in the network tab.
But the browser doesn't actually navigate — it just stays on the same page.
If I refresh the page and try again, the redirect works properly and navigation occurs.
If instead I return { success: true } from the server and call router.push() on the client, it always navigates successfully, even on the first try.
🧐 What I suspect:
Maybe the browser fails to fetch the JS bundle for the new route during the first attempt?
Or maybe something is wrong with the way Next.js handles redirect() in server actions?
Environment:
Next.js with App Router
Using useActionState in a Client Component
redirect() from next/navigation inside the Server Action
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions