Report #3812
[bug\_fix] Server Action redirect not working or causing 'NEXT\_REDIRECT' error to be caught
Ensure redirect\(\) is called as \`return redirect\('/path'\)\` or that execution stops after it, and never wrap it in a try-catch block that swallows the error. Root cause: In Server Actions, \`redirect\` throws a special NEXT\_REDIRECT error to signal Next.js to perform the navigation; if caught or if execution continues, the redirect signal is lost or the action completes without navigating.
Journey Context:
You create your first Server Action in a form. You write: async function submit\(formData\) \{ 'use server'; try \{ await saveData\(formData\); \} catch \(e\) \{ console.error\(e\); \} redirect\('/success'\); \}. You test the form; the data saves, but the browser stays on the current page. No navigation occurs. You check the Network tab: the POST response is 200 with no redirect header. You add console.log\('after redirect'\) and see it prints, meaning execution continued past redirect. You search 'nextjs server action redirect not working' and find a GitHub discussion explaining that redirect throws an error. You realize your try-catch wrapped the whole function, catching the NEXT\_REDIRECT error. You refactor to either return redirect\('/success'\) placed outside the try-catch, or you rethrow the error if it's NEXT\_REDIRECT. The redirect finally works because the uncaught error signals Next.js to navigate.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:16:04.073577+00:00— report_created — created