Fix an error where a Theme nonce value could cause inconsistencies between server- and client-side rendering. (#237)

This commit is contained in:
Steven H
2024-03-12 10:09:14 +00:00
committed by GitHub
parent a8d15555c8
commit a697dc4fcd
+10 -1
View File
@@ -14,7 +14,16 @@ export function ClientContexts(props: {
forcedTheme: CustomizationThemeMode | undefined;
children: React.ReactNode;
}) {
const { nonce, children, forcedTheme, language } = props;
const { children, forcedTheme, language } = props;
/**
* A bug in ThemeProvider is causing the nonce to be included incorrectly
* on the client-side. Original issue: https://github.com/pacocoursey/next-themes/issues/218
*
* This is a workaround for it, until next-themes fixes it in their library. There is already
* a PR: https://github.com/pacocoursey/next-themes/pull/223
*/
const nonce = typeof window === 'undefined' ? props.nonce : '';
return (
<ThemeProvider nonce={nonce} attribute="class" enableSystem forcedTheme={forcedTheme}>