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

vary header can't be overwritten even defined explicitly in middleware #55396

Closed
1 task done
yanv1991 opened this issue Sep 14, 2023 · 4 comments · Fixed by #75536
Closed
1 task done

vary header can't be overwritten even defined explicitly in middleware #55396

yanv1991 opened this issue Sep 14, 2023 · 4 comments · Fixed by #75536
Labels
bug Issue was opened via the bug report template. locked

Comments

@yanv1991
Copy link

Link to the code that reproduces this issue or a replay of the bug

https://github.com/yanv1991/cache-control/

To Reproduce

  • start application in prod mode.
  • open browser devtools in the root page
  • go to network tab and look for the html document at the very top level, click on it
  • look for response headers (vary)

Current vs. Expected behavior

current result:

  • vary is not being set(overwritten), even when we set this in middleware file using dynamic rendering

Screen Shot 2023-09-14 at 11 55 27 AM

expected result

  • vary should be defined in response header according to the value set in middleware file

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 20.6.0: Thu Jul  6 22:12:47 PDT 2023; root:xnu-7195.141.49.702.12~1/RELEASE_X86_64
    Binaries:
      Node: 16.14.2
      npm: 8.5.0
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.20-canary.28
      eslint-config-next: 13.4.19
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A

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

App Router

Additional context

we need to define this vary to be passed to our cdn in order to cache effectively

@yanv1991 yanv1991 added the bug Issue was opened via the bug report template. label Sep 14, 2023
@yanv1991 yanv1991 changed the title vary header can't be overwrite even defined explicitly in middleware vary header can't be overwritten even defined explicitly in middleware Sep 14, 2023
@simonri
Copy link
Contributor

simonri commented Sep 14, 2023

I think this is intentional. As a workaround you can create a patch using patch-package.

Edit the following files and add your values to RSC_VARY_HEADER.

/node_modules/next/dist/client/components/app-router-headers.js
/node_modules/next/dist/client/components/app-router-headers.d.ts
/node_modules/next/dist/esm/client/components/app-router-headers.js

Link to the file

@yanv1991
Copy link
Author

Thanks @simonri, would be nice to see this restriction in the docs, or at least mentioning the reason of doing that

@arvinxx

This comment has been minimized.

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants