Pass nonce to children

This commit is contained in:
2023-10-19 16:49:34 -04:00
parent 70b43410ce
commit 5e7779a08d
3 changed files with 10 additions and 5 deletions

View File

@ -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 (