Unexpected behaviour in redirect next/navigation function - Next.js 15 #74258
Labels
bug
Issue was opened via the bug report template.
Navigation
Related to Next.js linking (e.g., <Link>) and navigation.
Link to the code that reproduces this issue
https://github.com/leox182/next-unexpected-redirect-behavior
To Reproduce
the repository has two projects, next-14 and next-15 that contain the same code with only difference between versions (14.2.21 and 15.1.2 respectively).
Current vs. Expected behavior
Expected Behavior
Following the steps to reproduce, I expect the server action to execute its logic and then redirect the user without throwing an error (like on 14 version).
Actual Behavior
Instead of only redirecting, the server action throws an error, causing unexpected client-side behavior such as error messages.
Provide environment information
Operating System: Platform: win32 Arch: x64 Version: Windows 11 Pro for Workstations Available memory (MB): 32671 Available CPU cores: 12 Binaries: Node: 22.12.0 npm: 10.5.0 Yarn: N/A pnpm: 9.15.1 Relevant Packages: next: 15.1.2 // Latest available version is detected (15.1.2). eslint-config-next: 15.1.2 react: 19.0.0 react-dom: 19.0.0 typescript: 5.7.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Navigation
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
After upgrading to Next.js 15, I noticed a change in the behavior of the
redirect
function fromnext/navigation
when used in a server action.In Next.js 14, calling
redirect
within a server action executes the action and then performs the redirect as expected. However, in Next.js 15, callingredirect
not only redirects, but also causes the server action to throw an error that is cached on the client. This causes unexpected behaviour on the client, such as displaying an error message, even though no error has occurred.While this can be handled on the client by checking if
error.message === "NEXT_REDIRECT"
and ignoring such errors, this change in behavior was not documented as a breaking change or improvement on Next.js release post. Hence, I believe it is a bug.The text was updated successfully, but these errors were encountered: