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

<Link /> and redirect navigation causes route handler being called twice #72909

Open
wxh06 opened this issue Nov 18, 2024 · 0 comments
Open

<Link /> and redirect navigation causes route handler being called twice #72909

wxh06 opened this issue Nov 18, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@wxh06
Copy link
Contributor

wxh06 commented Nov 18, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/t66xm6

To Reproduce

  1. Start the application in development (next dev)
  2. Navigate to /
  3. Click “Link to /route”, “Link to /route without prefetch” or “redirect to /route” to see the current behavior of route.js handler
  4. Click “Link to /page” or “redirect to /page” to see the behavior of page.js for comparison

Current vs. Expected behavior

Current behavior

GET handler being called twice after one click (route is logged twice)

  • click on <Link />
    first has _rsc query string and the second does not
  • server action redirect
    first has rsc: 1 in HTTP header and the second does not

Expected behavior

GET route handler should be called only once (similar to current behavior of page.js) since it's not a React component and there's no need to prefetch

Provide environment information

Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.0.4-canary.15 // Latest available version is detected (15.0.4-canary.15).
  eslint-config-next: N/A
  react: 19.0.0-rc-380f5d67-20241113
  react-dom: 19.0.0-rc-380f5d67-20241113
  typescript: 5.3.3
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

Might relate to #57257 but that one is about page.js instead of route.js handler
I've tested with v14.2.0-canary.48 where that issue is resolved, and the behavior makes no difference to the latest canary version

@wxh06 wxh06 added the bug Issue was opened via the bug report template. label Nov 18, 2024
@github-actions github-actions bot added the Navigation Related to Next.js linking (e.g., <Link>) and navigation. label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

No branches or pull requests

1 participant