vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.99k stars 26.7k forks source link

Server action redirect ignores type and forces push #66252

Open markedwards opened 3 months ago

markedwards commented 3 months ago

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/epic-kowalevski-y6ghc9

To Reproduce

  1. start the demo app
  2. click the "Redirect" button
  3. observe that the browser history has /foo pushed to it, and it is possible to go back to /

Current vs. Expected behavior

I expect /foo to replace the root / page. According to this documentation:

By default, redirect will use push (adding a new entry to the browser history stack) in Server Actions and replace (replacing the current URL in the browser history stack) everywhere else. You can override this behavior by specifying the type parameter.

However, the behavior is that push is always forced in server actions, and there's no ability to override.

Provide environment information

Operating System:
  Platform: linux
  Arch: arm64
  Version: #1 SMP Sat Apr 27 04:13:19 UTC 2024
  Available memory (MB): 7842
  Available CPU cores: 8
Binaries:
  Node: 20.13.1
  npm: 10.5.2
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
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), next start (local)

Additional context

No response

icyJoseph commented 3 months ago

That codesandbox link is unreachable.

misterbit-pro commented 3 months ago

I can confirm this issue. Its easy to try out just make a server action with a redirect in it and pass RedirectType.replace and the redirect happens correctly but it did no replace because the full browser history is still available, I am having this issue with the latest version, I read about it on stackoverflow where people were talking about this that the RedirectType has no effect in in server actions

icyJoseph commented 3 months ago

Could you make a stackblitz example? just type next.new in your browser URL search bar, setup the repro and post the link back to it.

markedwards commented 3 months ago

Sorry, somehow managed to get the incorrect codesandbox URL originally (fixing in the description).

This should work: https://codesandbox.io/p/devbox/epic-kowalevski-y6ghc9

Is that sufficient?

litehacker commented 1 month ago

I confirm the issue

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!