Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect function in server action ignores "replace" parameter #70216

Closed
ziyafenn opened this issue Sep 18, 2024 · 2 comments · Fixed by #70279
Closed

Redirect function in server action ignores "replace" parameter #70216

ziyafenn opened this issue Sep 18, 2024 · 2 comments · Fixed by #70279
Labels
bug Issue was opened via the bug report template. Documentation Related to Next.js' official documentation. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@ziyafenn
Copy link
Contributor

Link to the code that reproduces this issue

https://stackblitz.com/edit/stackblitz-starters-c5ngbj?file=app%2Fpage.tsx

To Reproduce

  1. Start the app
  2. Click on Link to child
  3. Submit the form
  4. Click go back button from main page (or use browser back button)

Current vs. Expected behavior

The form is submitting a server action that calls redirect() function with url pointing back to the main page and RedirectType.replace to replace the current URL in the browser history stack.

Current behavior:
After submitting the form and pressing go back button or browser's back button, browser navigates me back to the Child page (where form was submitted).

Expected behaviour:
Browser should not navigate to the Child page, instead should stay where it is ("/") as redirect has property type set to replace.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: Ubuntu 20.04.0 LTS Wed Sep 18 2024 14:52:46 GMT+0200 (Central European Summer Time)
  Available memory (MB): NaN
  Available CPU cores: 8
Binaries:
  Node: 18.20.3
  npm: 10.2.3
  Yarn: 1.22.19
  pnpm: 8.15.6
Relevant Packages:
  next: 14.2.5 // There is a newer version (14.2.12) available, upgrade recommended! 
  eslint-config-next: 14.2.5
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Documentation, Navigation

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

I also tested this on Next.js 15 and could reproduce the bug.

@ziyafenn ziyafenn added the bug Issue was opened via the bug report template. label Sep 18, 2024
@github-actions github-actions bot added Documentation Related to Next.js' official documentation. Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels Sep 18, 2024
@jelmd
Copy link

jelmd commented Sep 20, 2024

Also in v15rc0 the useRouter().replace(URL) does not work as expected and breaks compat. because it actually redirects to the given URL instead of replacing the current entry with it. The only workaround found so far is to use history.replaceState() directly.

Copy link
Contributor

github-actions bot commented Oct 5, 2024

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Oct 5, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Documentation Related to Next.js' official documentation. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants