diff --git a/src/Dom/dynamicCSS.ts b/src/Dom/dynamicCSS.ts index ed2d8973..0fb23f6f 100644 --- a/src/Dom/dynamicCSS.ts +++ b/src/Dom/dynamicCSS.ts @@ -61,7 +61,7 @@ export function injectCSS(css: string, option: Options = {}) { styleNode.setAttribute(APPEND_ORDER, getOrder(prepend)); if (csp?.nonce) { - styleNode.nonce = csp?.nonce; + styleNode.setAttribute('nonce', csp?.nonce); } styleNode.innerHTML = css; @@ -140,8 +140,9 @@ export function updateCSS(css: string, key: string, option: Options = {}) { const existNode = findExistNode(key, option); if (existNode) { - if (option.csp?.nonce && existNode.nonce !== option.csp?.nonce) { - existNode.nonce = option.csp?.nonce; + const existNodeNonce = existNode.getAttribute('nonce'); + if (option.csp?.nonce && existNodeNonce !== option.csp?.nonce) { + existNode.setAttribute('nonce', option.csp?.nonce); } if (existNode.innerHTML !== css) { diff --git a/tests/dynamicCSS.test.tsx b/tests/dynamicCSS.test.tsx index 5ad99b05..625992bc 100644 --- a/tests/dynamicCSS.test.tsx +++ b/tests/dynamicCSS.test.tsx @@ -31,7 +31,9 @@ describe('dynamicCSS', () => { const style = injectCSS(TEST_STYLE, { csp: { nonce: 'light' } }); expect(document.contains(style)); expect(document.querySelector('style').innerHTML).toEqual(TEST_STYLE); - expect(document.querySelector('style').nonce).toEqual('light'); + expect(document.querySelector('style').getAttribute('nonce')).toEqual( + 'light', + ); }); describe('prepend', () => {