vercel / next.js

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

Middleware called redirect but the browser is not redirected #73176

Open kuanjiahong opened 4 days ago

kuanjiahong commented 4 days ago

Link to the code that reproduces this issue

https://github.com/kuanjiahong/nextjs-middleware-redirect-issue-demo

To Reproduce

  1. npm run dev
  2. Go to http://localhost:3000
  3. Click "Go to Dashboard" on "/" page
  4. Click "Set Session Cookie" on "/set-cookie" page
  5. Click "Go to Dashboard" on "/" page
  6. Click "Remove Session" on "/dashboard" page
  7. Click "Call Server Action" on "/dashboard" page

Current vs. Expected behavior

Current behavior After clicking "Remove Session" and then clicking "My Server Action", the page is not redirected to "/set-cookie" page

Expected behaviour After clicking "Remove Session" and then clicking "My Server Action", the page should be redirected to "/set-cookie" page

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 16086
  Available CPU cores: 8
Binaries:
  Node: 22.11.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.0.4-canary.27 // Latest available version is detected (15.0.4-canary.27).
  eslint-config-next: N/A
  react: 19.0.0-rc-b01722d5-20241114
  react-dom: 19.0.0-rc-b01722d5-20241114
  typescript: 5.3.3
Next.js Config:
  output: N/A

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

Middleware

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

next dev (local), next start (local)

Additional context

I tested my reproduction on 15.0.4-canary.27 and also 15.0.3. The issues are reproduceable for both of these version.

mostafa6813 commented 3 days ago

this is better place delete cookie and redirect in same server action function