vercel / next.js

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

next-navigation(useRouter().push("/url")) does not redirect to /url if server actions is used immediately after useRouter().push("/url") #65287

Closed ehsanrezaeee closed 1 week ago

ehsanrezaeee commented 2 weeks ago

Link to the code that reproduces this issue

https://github.com/ehsanrezaeee/next-router-report

To Reproduce

  1. clone the github repo
  2. npm i
  3. run the project in dev mode
  4. type something in the input box to make api call and hit the submit button
  5. wait for the router to redirect to different url
  6. url changes but it wont redirect

Current vs. Expected behavior

i expected to redirect to the specific url but instead the url changed and the redirection didnt happen

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32581
  Available CPU cores: 12
Binaries:
  Node: 20.10.0
  npm: N/A
  Yarn: N/A
  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 build (local), next start (local), Other (Deployed)

Additional context

i tested the application on the production and still having issues i mentioned. i didnt test on the canary latest version.

samcx commented 1 week ago

Hi @ehsanrezaeee, this is due to action queuing and is expected. The action might return a revalidate payload so the client needs to wait. We recommend using revalidatePath/redirect instead of router.push, which will also save another round trip to the server.

ehsanrezaeee commented 1 week ago

Thanks for explaining the issue.