Files
ladybird/Tests/LibWeb/Text/input/css/adopted-stylesheet-pending-invalidation-survives-adoption.html
Andreas Kling e29281893a LibWeb: Preserve pending style-update flags across document adoption
Adopting a node into another document preserves the node's dirty style
flags, but the destination ancestor chain never sees them propagate. If
a style update is already pending in the new document, it can skip the
adopted subtree entirely.

Snapshot the subtree and child dirty bits before set_document() updates
m_document, then walk the new ancestor chain and re-mark
child_needs_style_update so the pending restyle still descends into the
adopted subtree.
2026-04-23 16:45:22 +02:00

32 lines
1.2 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
const host = document.createElement("div");
const shadowRoot = host.attachShadow({ mode: "open" });
const shadowSpan = document.createElement("span");
shadowSpan.textContent = "shadow";
shadowRoot.append(shadowSpan);
const sheet = new CSSStyleSheet();
sheet.replaceSync("span { color: red; }");
shadowRoot.adoptedStyleSheets = [sheet];
document.body.append(host);
const iframe = document.createElement("iframe");
document.body.append(iframe);
println(`initial color: ${getComputedStyle(shadowSpan).color}`);
// Schedule a broad shadow-root invalidation by mutating the sheet, then
// adopt the host into a new document before style update runs. The
// pending dirty flags must survive the adoption so the new computed
// style reflects the mutation.
sheet.replaceSync("span { color: green; }");
iframe.contentDocument.adoptNode(host);
iframe.contentDocument.body.append(host);
println(`after adoption color: ${iframe.contentWindow.getComputedStyle(shadowSpan).color}`);
});
</script>