From f264b50d5c737fcaa672eadb4d3302acfd136582 Mon Sep 17 00:00:00 2001 From: Kevin Ghadyani Date: Mon, 7 Nov 2022 16:03:21 -0600 Subject: [PATCH] feat: added optional nonce prop to OdysseyCacheProvider --- .../src/OdysseyCacheProvider.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/odyssey-react-mui/src/OdysseyCacheProvider.tsx b/packages/odyssey-react-mui/src/OdysseyCacheProvider.tsx index f07c99612b..4390a37583 100644 --- a/packages/odyssey-react-mui/src/OdysseyCacheProvider.tsx +++ b/packages/odyssey-react-mui/src/OdysseyCacheProvider.tsx @@ -10,23 +10,34 @@ * See the License for the specific language governing permissions and limitations under the License. */ +declare global { + interface Window { + cspNonce: string; + } +} + import createCache from "@emotion/cache"; import { CacheProvider } from "@emotion/react"; import { memo, ReactElement, useMemo } from "react"; import { useUniqueAlphabeticalId } from "./useUniqueAlphabeticalId"; -const OdysseyCacheProvider = ({ children }: { children: ReactElement }) => { +const OdysseyCacheProvider = ({ + children, + nonce, +}: { + children: ReactElement; + nonce?: string; +}) => { const uniqueAlphabeticalId = useUniqueAlphabeticalId(); const emotionCache = useMemo( () => createCache({ key: uniqueAlphabeticalId, - // @ts-expect-error ts(2345) - nonce: window.cspNonce, + nonce: nonce || window.cspNonce, }), - [uniqueAlphabeticalId] + [nonce, uniqueAlphabeticalId] ); return {children};