-
Notifications
You must be signed in to change notification settings - Fork 86
feat: added better custom header support #1358
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
feat: added better custom header support #1358
Conversation
✅ Deploy Preview for netlify-plugin-nextjs-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-export-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-rsc-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-edge-middleware canceled.
|
✅ Deploy Preview for next-i18next-demo canceled.
|
✅ Deploy Preview for netlify-plugin-nextjs-next-auth-demo canceled.
|
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
cc82ac5
to
af4e234
Compare
The failing tests are complaining about not finding a routes-manifest.json file, but I check if it exists before loading it. Will take a peek at this in the AM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great. I think this approach is exactly the right one. Just a couple of comments and questions
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
Thanks for tagging me, @nickytonline! You have several options for a docs update. I'll list them in order of how long it'll likely take to complete (shortest time to longest time).
|
Thanks, @KyleBlankRollins! I'll create a PR to the docs repo for this. |
db53817
to
01df656
Compare
|
89f5b62
to
3acb29f
Compare
…le into consideration
Co-authored-by: Erica Pisani <[email protected]>
8de955e
to
e3c8ed1
Compare
Summary
Improves support for Next.js custom headers. Currently the
headers()
function in next.config.js only works for SSR/ISR. Headers in netlify.toml or a _headers file are completely ignored for SSR/ISR. For SSG pages, only the headers defined in netlify.toml or a _headers file are recognized and headers defined inheaders()
in next.config.js are ignored.Previously, you had to manually copy from the
headers()
function to netlify.toml or vice-versa so all headers were applied. Now all that is required is defining custom headers in theheaders()
function of next.config.js. The build plugin will update the Netlify configuration at build time with all the custom headers defined in theheaders()
function of next.config.js.You can still add headers in netlify.toml or _headers, but those additional headers will only apply to SSG pages.
@KyleBlankRollins, we'll need a documentation update for this as well. Happy to write this up, just not sure how we usually work with the documentation team.
Note that ISR and SSR are not affected by this plugin fix.
Test plan
The source code for test site can be found at https://github.com/nickytonline/next-plugin-issue-1346
Note that unless you load a page explicitly from the browser address bar, Next.js client-side routing will kick in so as you navigate to a new page, from the first-page load, you will not see the custom headers in subsequent pages that load from the client-side as the browser is not refreshing. You will need to refresh the browser to see the headers.
If you want to test the fix locally, you'll need to build the fix locally and run
npm link
, then in the test site repository, you'll need to runnpm link @netlify/plugin-nextjs
. Just a reminder that the fix can only be tested in a site that was deployed to Netlify using the plugin fix. There is no way to test this locally.This is the configuration being used in the sites deployed in the test scenarios, https://github.com/nickytonline/next-plugin-issue-1346/blob/96471d10bb7be58287859e1e62af227eacf9e127/next.config.js
x-all-pages-header
headerRelevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal
Closes #1346
Standard checks:
🧪 Once merged, make sure to update the version if needed and that it was published correctly.