Skip to content

Commit

Permalink
Use unsafe-inline with styles (mui/material-ui#19938)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavberi committed Oct 4, 2024
1 parent 1a2fe6c commit d2074f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/components/ThemeRegistry/EmotionCache.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CacheProvider as DefaultCacheProvider } from "@emotion/react";

// This implementation is taken from https://github.com/garronej/tss-react/blob/main/src/next/appDir.tsx
export default function NextAppDirEmotionCacheProvider(props) {
const { options, CacheProvider = DefaultCacheProvider, nonce, children } = props;
const { options, CacheProvider = DefaultCacheProvider, children } = props;

const [{ cache, flush }] = React.useState(() => {
// eslint-disable-next-line @typescript-eslint/no-shadow
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function NextAppDirEmotionCacheProvider(props) {
return (
<style
key={cache.key}
nonce={nonce}
nonce={options.nonce}
data-emotion={`${cache.key} ${names.join(" ")}`}
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
Expand All @@ -54,5 +54,9 @@ export default function NextAppDirEmotionCacheProvider(props) {
);
});

return <CacheProvider value={cache}>{children}</CacheProvider>;
return (
<CacheProvider value={cache} prepend={true} nonce={options.nonce}>
{children}
</CacheProvider>
);
}
2 changes: 1 addition & 1 deletion src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function middleware(req) {
script-src 'self' 'nonce-${nonce}' 'strict-dynamic' https: http: 'unsafe-inline' ${
process.env.NODE_ENV === "production" ? "" : `'unsafe-eval'`
};
style-src 'self' 'nonce-${nonce}';
style-src 'self' 'unsafe-inline';
img-src 'self' blob: data:;
font-src 'self' data:;
object-src 'none';
Expand Down

0 comments on commit d2074f1

Please sign in to comment.