Files
ladybird/Tests/LibWeb/Text/input/HTML/HTMLLinkElement-appends-and-removes-from-ShadowRoot-styleSheets.html
Luke Wilde cd72e788e9 LibWeb: Append style sheet to ShadowRoot's list if link el is in one
We were handling removing the style sheet from the shadow root, but not
appending to it. Fixing this also revealed a bug that a removed link
element would always try to remove from the document's list, as the
root is no longer the shadow root it's in. The fix is to use the passed
in old root to remove the style sheet from.

Fixes the cookie banner on https://nos.nl/
2025-04-08 23:20:54 +02:00

41 lines
1.4 KiB
HTML

<!DOCTYPE html>
<div id="shadowhost"></div>
<script src="../include.js"></script>
<script>
asyncTest((done) => {
const shadowHost = document.getElementById("shadowhost");
const shadowRoot = shadowHost.attachShadow({ mode: "closed" });
const linkEl = document.createElement("link");
linkEl.href = "../valid.css";
linkEl.rel = "stylesheet";
const printSheets = () => {
println(`is linkEl.sheet null? ${linkEl.sheet === null}`)
println(`- document stylesheets (length = ${document.styleSheets.length})`);
for (const sheet of document.styleSheets) {
println(`-- document stylesheet linkEl.sheet === sheet: ${linkEl.sheet === sheet}`);
}
println(`- shadow root stylesheets (length = ${shadowRoot.styleSheets.length})`);
for (const sheet of shadowRoot.styleSheets) {
println(`-- shadow root linkEl.sheet === sheet: ${linkEl.sheet === sheet}`);
}
};
println("== before appending");
printSheets();
linkEl.addEventListener("load", () => {
println("== link loaded");
printSheets();
linkEl.remove();
println("== link removed");
printSheets();
done();
}, { once: true });
shadowRoot.appendChild(linkEl);
});
</script>