Skip to content

Commit 3024ad4

Browse files
authored
chore(integration-karma): remove programmatic DSD check (#5299)
comment says the workaround is for Firefox, which added support a few months/versions ago
1 parent ba8ff37 commit 3024ad4

File tree

1 file changed

+2
-39
lines changed

1 file changed

+2
-39
lines changed

packages/@lwc/integration-karma/helpers/test-hydrate.js

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,15 @@ window.HydrateTest = (function (lwc, testUtils) {
1010
sanitizeHtmlContent: (content) => content,
1111
});
1212

13-
// As of this writing, Firefox does not support programmatic access to parsing DSD,
14-
// i.e. `Document.parseHTMLUnsafe`
15-
// See: https://developer.mozilla.org/en-US/docs/Web/API/Document/parseHTMLUnsafe_static
16-
function testSupportsProgrammaticDSD() {
17-
const html = '<div><template shadowrootmode="open"></template></div>';
18-
try {
19-
return !!Document.parseHTMLUnsafe(html).body.firstChild.shadowRoot;
20-
} catch (_err) {
21-
return false;
22-
}
23-
}
24-
25-
const browserSupportsProgrammaticDSD = testSupportsProgrammaticDSD();
26-
2713
function parseStringToDom(html) {
28-
if (browserSupportsProgrammaticDSD) {
29-
return Document.parseHTMLUnsafe(html).body.firstChild;
30-
} else {
31-
return new DOMParser().parseFromString(html, 'text/html').body.firstChild;
32-
}
33-
}
34-
35-
function polyfillDeclarativeShadowDom(root) {
36-
root.querySelectorAll('template[shadowrootmode]').forEach((template) => {
37-
const mode = template.getAttribute('shadowrootmode');
38-
const shadowRoot = template.parentNode.attachShadow({ mode });
39-
shadowRoot.appendChild(template.content);
40-
template.remove();
41-
42-
polyfillDeclarativeShadowDom(shadowRoot);
43-
});
14+
return Document.parseHTMLUnsafe(html).body.firstChild;
4415
}
4516

4617
function appendTestTarget(ssrText) {
4718
const div = document.createElement('div');
48-
4919
const testTarget = parseStringToDom(ssrText);
50-
if (!browserSupportsProgrammaticDSD) {
51-
polyfillDeclarativeShadowDom(testTarget);
52-
}
5320
div.appendChild(testTarget);
54-
5521
document.body.appendChild(div);
56-
5722
return div;
5823
}
5924

@@ -91,7 +56,5 @@ window.HydrateTest = (function (lwc, testUtils) {
9156
return testResult;
9257
}
9358

94-
return {
95-
runTest,
96-
};
59+
return { runTest };
9760
})(window.LWC, window.TestUtils);

0 commit comments

Comments
 (0)