Skip to content

Commit c91eb26

Browse files
committed
docs(changeset): Fix: Add nonce to the script tag
1 parent 452a87d commit c91eb26

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"nextjs-darkmode": patch
3+
---
4+
5+
Fix: Add nonce to the script tag

lib/src/client/core/core.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ export const Core = ({ t, nonce, k = "o" }: CoreProps) => {
8282
setThemeState(state => ({ ...state, s: media.matches ? DARK : LIGHT }) as Store),
8383
);
8484
/** Sync the tabs */
85-
const storageListener = (e: StorageEvent): void => {
86-
if (e.key === k)
87-
setThemeState(state => ({ ...state, m: e.newValue as ColorSchemePreference }));
88-
};
89-
addEventListener("storage", storageListener);
85+
addEventListener("storage", (e: StorageEvent): void => {
86+
e.key === k && setThemeState(state => ({ ...state, m: e.newValue as ColorSchemePreference }));
87+
});
9088
}, []);
9189

9290
useEffect(() => {
@@ -95,5 +93,5 @@ export const Core = ({ t, nonce, k = "o" }: CoreProps) => {
9593
restoreTransitions();
9694
}, [systemMode, mode, t, nonce]);
9795

98-
return <script dangerouslySetInnerHTML={{ __html: `(${s.toString()})('${k}')` }} />;
96+
return <script dangerouslySetInnerHTML={{ __html: `(${s.toString()})('${k}')` }} nonce={nonce} />;
9997
};

0 commit comments

Comments
 (0)