Skip to content

Commit

Permalink
Add optional nonce back to ColorModeScript (#6641)
Browse files Browse the repository at this point in the history
* Add optional `nonce` back to ColorModeScript

* docs: add changelog

* Fix nonce

Co-authored-by: Segun Adebayo <joseshegs@gmail.com>
  • Loading branch information
chancegraff and segunadebayo committed Sep 9, 2022
1 parent e626974 commit 1ce7017
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-tomatoes-destroy.md
@@ -0,0 +1,5 @@
---
"@chakra-ui/color-mode": patch
---

Add optional `nonce` back to ColorModeScript
6 changes: 6 additions & 0 deletions packages/components/color-mode/src/color-mode-script.tsx
Expand Up @@ -2,6 +2,7 @@ export type ColorModeScriptProps = {
type?: "localStorage" | "cookie"
initialColorMode?: "light" | "dark" | "system"
storageKey?: string
nonce?: string
}

const VALID_VALUES = new Set(["dark", "light", "system"])
Expand Down Expand Up @@ -38,9 +39,14 @@ export function getScriptSrc(props: ColorModeScriptProps = {}) {
}

export function ColorModeScript(props: ColorModeScriptProps = {}) {
const {
nonce,
} = props

return (
<script
id="chakra-script"
nonce={nonce}
dangerouslySetInnerHTML={{ __html: getScriptSrc(props) }}
/>
)
Expand Down

1 comment on commit 1ce7017

@vercel
Copy link

@vercel vercel bot commented on 1ce7017 Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.