vercel / next.js

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

redirect to url with a different base path in server action does not work #65257

Open levinqdl opened 2 weeks ago

levinqdl commented 2 weeks ago

Link to the code that reproduces this issue

https://github.com/levinqdl/reproduction-app

Config the app with base path /app. To demonstrate the issue, a rewrite from /external to https://example.vercel.sh is added, in production, it should be another app with the same origin and a different base path.

To Reproduce

  1. Start the app in development (next dev)
  2. Visit http://localhost:3000/app
  3. Click redirect

Current vs. Expected behavior

Expect:

the page is redirected to bing.com

Current:

  1. the route changes to http:/localhost:3000/external, and the page got a 404 error page from next.js
  2. if I refresh browser on the 404 page, contents of https://example.vercel.sh is shown

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: 1.22.19
  pnpm: 9.0.6
Relevant Packages:
  next: 14.3.0-canary.36 // Latest available version is detected (14.3.0-canary.36).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.1.3
Next.js Config:
  output: N/A

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

Navigation, server action, base path

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

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

Additional context

The issue breaks navigation from apps routed by different base paths, such as OAuth flow. I think it's because Next.js perform redirects to same origin of the app as a client side navigation, not considering the base path.