From 50d40338dc9fae42fef211cd5cc74b74c66436af Mon Sep 17 00:00:00 2001 From: amit3200 Date: Tue, 26 Nov 2024 03:59:29 +0530 Subject: [PATCH 1/5] Shadowroot support using getHTML --- packages/dom/src/clone-dom.js | 12 +++++++++--- packages/dom/test/serialize-css.test.js | 6 +++--- packages/dom/test/serialize-dom.test.js | 12 ++++++------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/dom/src/clone-dom.js b/packages/dom/src/clone-dom.js index d63679f54..99a9a5a24 100644 --- a/packages/dom/src/clone-dom.js +++ b/packages/dom/src/clone-dom.js @@ -54,7 +54,8 @@ export function cloneNodeAndShadow(ctx) { clone.shadowRoot.innerHTML = ''; } else { clone.attachShadow({ - mode: 'open' + mode: 'open', + serializable: true }); } // clone dom elements @@ -85,9 +86,14 @@ export function cloneNodeAndShadow(ctx) { */ export function getOuterHTML(docElement) { // firefox doesn't serialize shadow DOM, we're awaiting API's by firefox to become ready and are not polyfilling it. - if (!docElement.getInnerHTML) { return docElement.outerHTML; } + if (!docElement.getHTML) { return docElement.outerHTML; } // chromium gives us declarative shadow DOM serialization API - let innerHTML = docElement.getInnerHTML({ includeShadowRoots: true }); + let innerHTML = ''; + if (docElement.getInnerHTML) { + innerHTML = docElement.getInnerHTML({ includeShadowRoots: true }); + } else if (docElement.getHTML) { + innerHTML = docElement.getHTML({ serializableShadowRoots: true }); + } docElement.textContent = ''; // Note: Here we are specifically passing replacer function to avoid any replacements due to // special characters in client's dom like $& diff --git a/packages/dom/test/serialize-css.test.js b/packages/dom/test/serialize-css.test.js index 2012b4ebf..ea0bbebc8 100644 --- a/packages/dom/test/serialize-css.test.js +++ b/packages/dom/test/serialize-css.test.js @@ -118,7 +118,7 @@ describe('serializeCSSOM', () => { }])); expect(resultShadowEl.innerHTML).toEqual([ - '