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

[material-ui-nextjs] Support Nonces in the App Router Provider #40269

Conversation

josh-feldman
Copy link
Contributor

@josh-feldman josh-feldman commented Dec 21, 2023

Summary

Add CSP support by passing the nonce createCache option down into the useServerInsertedHTML script tags.

With this change, you can now follow the NextJS guide on CSP, and in layout.tsx pass the nonce from headers down into the AppRouterCacheProvider to prevent inline style style-src CSP errors.

✅ Tested the code with mui docs and local project with code sandbox build

* pass the cache's existing nonce property to the server inserted html script tags to support csp
@mui-bot
Copy link

mui-bot commented Dec 21, 2023

Netlify deploy preview

https://deploy-preview-40269--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 515c54f

@zannager zannager added the package: system Specific to @mui/system label Dec 22, 2023
@ZeeshanTamboli ZeeshanTamboli added new feature New feature or request package: material-ui Specific to @mui/material nextjs and removed package: system Specific to @mui/system labels Jan 15, 2024
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@ZeeshanTamboli ZeeshanTamboli merged commit b1ea970 into mui:master Jan 15, 2024
23 of 24 checks passed
@josh-feldman josh-feldman deleted the fix/nextjs-support-nonce-cache-option-on-server-html branch February 22, 2024 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request nextjs package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants