-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clerk-js): Add nonce to theme provider (#4509)
Co-authored-by: Jacek <[email protected]>
- Loading branch information
1 parent
92a4859
commit 7c27b0c
Showing
4 changed files
with
44 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@clerk/clerk-js": minor | ||
--- | ||
|
||
If a nonce is provided, it is now made available to Clerk's internal components. This allows the nonce to be passed in to style-src in CSPs and work correctly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/clerk-js/src/ui/styledSystem/StyleCacheProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// eslint-disable-next-line no-restricted-imports | ||
import createCache from '@emotion/cache'; | ||
// eslint-disable-next-line no-restricted-imports | ||
import { CacheProvider } from '@emotion/react'; | ||
import React, { useMemo } from 'react'; | ||
|
||
const el = document.querySelector('style#cl-style-insertion-point'); | ||
|
||
type StyleCacheProviderProps = React.PropsWithChildren<{ | ||
nonce?: string; | ||
}>; | ||
|
||
export const StyleCacheProvider = (props: StyleCacheProviderProps) => { | ||
const cache = useMemo( | ||
() => | ||
createCache({ | ||
key: 'cl-internal', | ||
prepend: !el, | ||
insertionPoint: el ? (el as HTMLElement) : undefined, | ||
nonce: props.nonce, | ||
}), | ||
[props.nonce], | ||
); | ||
|
||
return <CacheProvider value={cache}>{props.children}</CacheProvider>; | ||
}; |