Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rsc header and query params always null on middleware #65787

Open
zecka opened this issue May 15, 2024 · 7 comments
Open

Rsc header and query params always null on middleware #65787

zecka opened this issue May 15, 2024 · 7 comments
Labels
Middleware Related to Next.js Middleware.

Comments

@zecka
Copy link

zecka commented May 15, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/nextjs-middleware-get-rsc-query-params-and-header-vfy9hk?file=%2Fmiddleware.ts%3A23%2C15

To Reproduce

  1. Go to https://codesandbox.io/p/devbox/nextjs-middleware-get-rsc-query-params-and-header-vfy9hk?file=%2Fmiddleware.ts%3A23%2C15
  2. Open network tab on your browser
  3. Clique on link "Page2?test=1"
  4. You will a request to "https://vfy9hk-3000.csb.app/page2?test=1&_rsc=1dou9"

Current vs. Expected behavior

Check console query params test is successfully log but _rsc params is null. rsc header is also null
image

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 14.3.0-canary.63 // Latest available version is detected (14.3.0-canary.63).
  eslint-config-next: N/A
  react: 19.0.0-beta-4508873393-20240430
  react-dom: 19.0.0-beta-4508873393-20240430
  typescript: 5.1.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 build (local), next start (local), Other (Deployed)

Additional context

No response

@zecka zecka added the bug Issue was opened via the bug report template. label May 15, 2024
@github-actions github-actions bot added the Middleware Related to Next.js Middleware. label May 15, 2024
@tigerabrodi
Copy link

tigerabrodi commented May 19, 2024

@zecka good catch!

Is this the most recent version, Next.js 14.2?

@zecka
Copy link
Author

zecka commented May 20, 2024

@tigerabrodi Yes I tested it on 14.2 and 14.3 and Both have the issue

@PSoltes
Copy link

PSoltes commented Sep 6, 2024

is there an ETA on this being fixed?

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

@lubieowoce
Copy link
Member

This is currently intended behavior. See e.g. test here

const rscQuery = request.nextUrl.searchParams.get(NEXT_RSC_UNION_QUERY)
// Test that the RSC query is not present in the middleware
if (rscQuery) {
throw new Error('RSC query should not be present in the middleware')
}

@PSoltes
Copy link

PSoltes commented Sep 6, 2024

If it is intended behaviour, why is this issue open as a bug? Maybe change it to feature request? But also my personal opinion kinda weird to hide it.

@lubieowoce lubieowoce removed the bug Issue was opened via the bug report template. label Sep 6, 2024
@marco910
Copy link

It would be pretty nice to have access to the rsc param in the middleware. There is a use case in our app where we need this

@saikatmitra91
Copy link

One use case:
If you have a middleware where authentication is being done, too many prefetch RSC calls lead to rate limit on our auth service.

Is there any alternate approach to detect RSC calls ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Middleware Related to Next.js Middleware.
Projects
None yet
Development

No branches or pull requests

6 participants