From 1a3e61075c6c0b06c151bc069a20083cea77427a Mon Sep 17 00:00:00 2001 From: Shantanu Kardile Date: Wed, 18 Oct 2023 17:52:43 +0530 Subject: [PATCH 1/3] exclude noscript tags while cloning dom --- packages/dom/src/clone-dom.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/dom/src/clone-dom.js b/packages/dom/src/clone-dom.js index 37ca0c9d0..f6a710d77 100644 --- a/packages/dom/src/clone-dom.js +++ b/packages/dom/src/clone-dom.js @@ -15,7 +15,9 @@ export function cloneNodeAndShadow({ dom, disableShadowDOM }) { let cloneNode = (node, parent) => { let walkTree = (nextn, nextp) => { while (nextn) { - cloneNode(nextn, nextp); + if (nextn.nodeName != "NOSCRIPT"){ + cloneNode(nextn, nextp); + } nextn = nextn.nextSibling; } }; From 1f691b87501569a94023172cd68c42861167538e Mon Sep 17 00:00:00 2001 From: Shantanu Kardile Date: Wed, 18 Oct 2023 18:00:01 +0530 Subject: [PATCH 2/3] lint fix --- packages/dom/src/clone-dom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dom/src/clone-dom.js b/packages/dom/src/clone-dom.js index f6a710d77..bf4f0a10e 100644 --- a/packages/dom/src/clone-dom.js +++ b/packages/dom/src/clone-dom.js @@ -15,7 +15,7 @@ export function cloneNodeAndShadow({ dom, disableShadowDOM }) { let cloneNode = (node, parent) => { let walkTree = (nextn, nextp) => { while (nextn) { - if (nextn.nodeName != "NOSCRIPT"){ + if (nextn.nodeName !== 'NOSCRIPT') { cloneNode(nextn, nextp); } nextn = nextn.nextSibling; From 8b59d726f7680f4495bab5bd0bdda79d9948550e Mon Sep 17 00:00:00 2001 From: Shantanu Kardile Date: Thu, 19 Oct 2023 09:09:54 +0530 Subject: [PATCH 3/3] updates + test --- packages/dom/src/clone-dom.js | 5 ++++- packages/dom/test/serialize-dom.test.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/dom/src/clone-dom.js b/packages/dom/src/clone-dom.js index bf4f0a10e..257f2d8e2 100644 --- a/packages/dom/src/clone-dom.js +++ b/packages/dom/src/clone-dom.js @@ -10,12 +10,15 @@ import applyElementTransformations from './transform-dom'; * Deep clone a document while also preserving shadow roots * returns document fragment */ + +const ignoreTags = ['NOSCRIPT']; + export function cloneNodeAndShadow({ dom, disableShadowDOM }) { // clones shadow DOM and light DOM for a given node let cloneNode = (node, parent) => { let walkTree = (nextn, nextp) => { while (nextn) { - if (nextn.nodeName !== 'NOSCRIPT') { + if (!ignoreTags.includes(nextn.nodeName)) { cloneNode(nextn, nextp); } nextn = nextn.nextSibling; diff --git a/packages/dom/test/serialize-dom.test.js b/packages/dom/test/serialize-dom.test.js index 2fa38f6d0..1da2d53ee 100644 --- a/packages/dom/test/serialize-dom.test.js +++ b/packages/dom/test/serialize-dom.test.js @@ -17,6 +17,14 @@ describe('serializeDOM', () => { expect(result.html).toContain('Hey Percy $&'); }); + it('excludes noscript tags when present', () => { + withExample('

Hey Percy $&

'); + + const result = serializeDOM(); + expect(result.html).not.toContain('