vercel / next.js

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

`redirect()` inside Server Actions doesn't work with the same domain #62208

Open steven-tey opened 8 months ago

steven-tey commented 8 months ago

Link to the code that reproduces this issue

https://github.com/steven-tey/server-action-redirect-bug

To Reproduce

Go to https://server-action-redirect-bug.vercel.app/, type in any password and click "Log In". You'll see the URL change to have the ?pw= query param:

CleanShot 2024-02-17 at 20 53 07

However, this is incorrect since we have a middleware that says if there's a pw query param, redirect to https://dub.co. Refreshing the page fixes this.

Current vs. Expected behavior

Current: redirect() does a "soft" redirect and doesn't actually refresh the router Expected: redirect() triggers a router refresh and redirects to the final URL (https://dub.co) (as per the docs)

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6000
Binaries:
  Node: 20.9.0
  npm: 10.2.4
  Yarn: 1.22.21
  pnpm: 8.10.5
Relevant Packages:
  next: 14.1.1-canary.59 // Latest available version is detected (14.1.1-canary.59).
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

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

App Router, Routing (next/router, next/navigation, next/link)

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

next dev (local), Vercel (Deployed)

Additional context

This used to work before next@14.1.1 I believe

NEXT-2840

sameterkanboz commented 5 months ago

i have same issue. on my middleware file i check the user auth with cookie and make some routing for user role or user auth session. for routing work i need the refresh page.

AhmedBaset commented 5 months ago

It works as expected in 14.2.3