Route handler does not receive searchParams set by middleware without runtime edge
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/LuukSantegoeds/nextjs-searchparams-issue
To Reproduce
Within the linked repository:
- Navigate to http://localhost:3000/route-default?foo=bar (default runtime) and validate that the searchParam is received by the route by checking the json response
- Navigate to http://localhost:3000/route-edge?foo=bar (edge runtime) and validate that the searchParam is received by the route by checking the json response
- Navigate to http://localhost:3000/middleware/route-edge?bar=foo (edge runtime) and validate that a searchParam is added by the middleware to the searchParam already provided
- Navigate to http://localhost:3000/middleware/route-default?bar=foo where no will see that no additional searchParam is added by the middleware
Current vs. Expected behavior
I would expect that the searchParam added by the middleware (in case of the default runtime) would also be received by the route handler, just like with the edge runtime.
This only occurs in combination with a rewrite in the middleware. I you were to disable the middleware and do direct requests to the route handler, searchParams are received in both runtime situations as demonstrated within the first 2 steps.
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Enterprise
Available memory (MB): 32488
Available CPU cores: 16
Binaries:
Node: 20.9.0
npm: 10.1.0
Yarn: N/A
pnpm: 8.15.7
Relevant Packages:
next: 14.2.2 // Latest available version is detected (14.2.2).
eslint-config-next: 14.2.2
react: 18.2.0
react-dom: 18.2.0
typescript: 5.4.5
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Middleware & route handlers
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local)
Additional context
This was tested locally
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 reproduction repository and run the four listed URLs to compare default and edge runtimes. Inspect the middleware rewrite and the route handlers used by those paths. Done means the default-runtime handler receives the search parameter added by middleware, matching edge-runtime behavior, with a regression test covering the case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100