From d25bd87fa9e79ed3ae33c7fd4bb030a7eac1143c Mon Sep 17 00:00:00 2001 From: shentao1 <573030138@qq.com> Date: Wed, 10 Jan 2024 12:31:42 +0000 Subject: [PATCH 1/2] fix: issues 495 --- src/Dom/dynamicCSS.ts | 7 ++++--- tests/dynamicCSS.test.tsx | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) 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', () => { From 7d034dbe634a24a901bc37cda40da78b0d35d884 Mon Sep 17 00:00:00 2001 From: shentao1 <573030138@qq.com> Date: Wed, 10 Jan 2024 12:37:36 +0000 Subject: [PATCH 2/2] Initial commit