Skip to content

Route handler does not receive searchParams set by middleware without runtime edge #64776

Description

@LuukSantegoeds

Link to the code that reproduces this issue

https://github.com/LuukSantegoeds/nextjs-searchparams-issue

To Reproduce

Within the linked repository:

  1. 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
  2. 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
  3. 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
  4. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions