Pre-hydration redirect from server actions does not prepend base path
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/greenlynx/nextjs-bad-redirect-repro
To Reproduce
Our application has a base path set, and a form that submits to a server action that causes a redirect. When the app is tested using Playwright, and the form is submitted before the page is hydrated, the redirect location in the 303 response is wrong (it is missing the base path).
Steps to reproduce
- Disable Javascript in browser
pnpm dev- Click submit button
Current vs. Expected behavior
Current behaviour
- Redirect to
/successand see a 404 error (because the base path/customwas not prepended to the redirect location)
Expected behaviour
- Redirect to
/custom/success, and see "OK" message
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
Available memory (MB): 49152
Available CPU cores: 14
Binaries:
Node: 22.20.0
npm: 10.9.3
Yarn: 1.22.22
pnpm: 10.18.3
Relevant Packages:
next: 16.0.1-canary.5 // Latest available version is detected (16.0.1-canary.5).
eslint-config-next: N/A
react: 19.2.0
react-dom: 19.2.0
typescript: 5.9.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Redirects, Server Actions, Runtime
Which stage(s) are affected? (Select all that apply)
next dev (local), Other (Deployed), Vercel (Deployed)
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked nextjs-bad-redirect-repro and run pnpm dev with JavaScript disabled, then submit the form before hydration. Trace the Next.js server action redirect handling for the 303 response. Done means the redirect location includes /custom, leading to /custom/success and the “OK” message instead of a 404.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs, playwright, react
- Domain
- backend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100