From e708b2746a005bd1099978a1658d325de46928fc Mon Sep 17 00:00:00 2001 From: Per Svensson Date: Thu, 22 Feb 2024 10:30:56 +0100 Subject: [PATCH] Allow nonce to be provided in DOM node --- packages/reactive-element/src/css-tag.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/reactive-element/src/css-tag.ts b/packages/reactive-element/src/css-tag.ts index 147dc45312..9731c0b42c 100644 --- a/packages/reactive-element/src/css-tag.ts +++ b/packages/reactive-element/src/css-tag.ts @@ -178,8 +178,12 @@ export const adoptStyles = ( } else { for (const s of styles) { const style = document.createElement('style'); + // eslint-disable-next-line @typescript-eslint/no-explicit-any - const nonce = (global as any)['litNonce']; + let nonce = (global as any)['litNonce'] + || ((renderRoot as ShadowRoot)?.querySelector("style[nonce]") as HTMLStyleElement)?.nonce + || ((renderRoot as ShadowRoot)?.querySelector("script[nonce]") as HTMLScriptElement)?.nonce; + if (nonce !== undefined) { style.setAttribute('nonce', nonce); }