diff --git a/app/entry.client.tsx b/app/entry.client.tsx index 5be2e90..5721e6e 100644 --- a/app/entry.client.tsx +++ b/app/entry.client.tsx @@ -1,6 +1,6 @@ import { CacheProvider } from "@emotion/react"; import { ClientStyleContext } from "./context.js"; -import createEmotionCache, { defaultCache } from "./createEmotionCache.js"; +import createEmotionCache from "./createEmotionCache.js"; import { hydrateRoot } from "react-dom/client"; import { Integrations } from "@sentry/tracing"; import { RemixBrowser } from "@remix-run/react"; @@ -16,10 +16,14 @@ Sentry.init({ }); function ClientCacheProvider({ children }: { children: ReactNode }) { - const [cache, setCache] = useState(defaultCache); + const nonce = + document + .querySelector("meta[name='style-nonce']") + ?.getAttribute("content") || undefined; + const [cache, setCache] = useState(createEmotionCache(nonce)); function reset() { - setCache(createEmotionCache()); + setCache(createEmotionCache(nonce)); } return ( diff --git a/app/entry.server.tsx b/app/entry.server.tsx index 89fac37..e08052c 100644 --- a/app/entry.server.tsx +++ b/app/entry.server.tsx @@ -10,9 +10,9 @@ export default function handleRequest( request: Request, responseStatusCode: number, responseHeaders: Headers, - remixContext: EntryContext + remixContext: EntryContext & RequestContext ) { - const cache = createEmotionCache(); + const cache = createEmotionCache(remixContext.data.nonce); const { extractCriticalToChunks } = createEmotionServer(cache); const html = renderToString( diff --git a/app/root.tsx b/app/root.tsx index cd097c5..c9290aa 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -157,6 +157,7 @@ function getMarkup( {loaderData.dsn ? ( ) : null} +