Skip to content

Commit 3a34a13

Browse files
bwaldermanchromium-wpt-export-bot
authored andcommitted
[css-mixins] Invalidate shadow DOM mixin consumers
Changing a mixin in an outer tree scope only rebuilt RuleSets in that scope. Descendant shadow styles that applied the inherited mixin could remain flattened against the old definition. Propagate mixin changes along paths to dependent shadow scopes and refresh intermediate scope identities so local mixins cannot hide an inherited change. Preserve the existing identity when the effective mixin map is unchanged to avoid rebuilding dependent RuleSets after unrelated stylesheet updates. CSSOM mutation can modify a mixin in place without changing its rule pointer. Track a monotonic revision for each stylesheet's extracted mixins so every collection sharing a constructable stylesheet observes the mutation independently. Add coverage for direct and nested shadow consumers, including a shared constructable stylesheet adopted into sibling scopes. Also expose the dependent-scope invalidation phase as a trace metric for the mixin invalidation perf tests. Bug: 542873370 Change-Id: I0760313de69d51d02aa8cf00068b5cd8c7662d9c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8450115 Reviewed-by: Kevin Babbitt <[email protected]> Commit-Queue: Brandon Walderman <[email protected]> Cr-Commit-Position: refs/heads/main@{#1710484}
1 parent b01090a commit 3a34a13

1 file changed

Lines changed: 139 additions & 0 deletions

File tree

‎css/css-mixins/mixins/mixin-shadow-dom.html‎

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,5 +315,144 @@
315315
}, 'Nested shadows use the nearest mixin along each tree branch');
316316
</script>
317317

318+
<style>
319+
@mixin --dynamic-document-mixin() {
320+
@result {
321+
color: red;
322+
}
323+
}
324+
</style>
325+
<div id="host8">
326+
<template shadowrootmode="open">
327+
<style>
328+
#target {
329+
@apply --dynamic-document-mixin;
330+
}
331+
</style>
332+
<div id="target">This text should become green.</div>
333+
</template>
334+
</div>
335+
<script>
336+
test(() => {
337+
const target = document.getElementById('host8')
338+
.shadowRoot.getElementById('target');
339+
assert_equals(getComputedStyle(target).color, 'rgb(255, 0, 0)');
340+
341+
const style = document.createElement('style');
342+
style.textContent = `
343+
@mixin --dynamic-document-mixin() {
344+
@result {
345+
color: green;
346+
}
347+
}
348+
`;
349+
document.body.append(style);
350+
351+
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
352+
353+
style.sheet.cssRules[0].cssRules[0].cssRules[0].style.color = 'blue';
354+
assert_equals(getComputedStyle(target).color, 'rgb(0, 0, 255)');
355+
}, 'Changing a document mixin invalidates dependent shadow styles');
356+
</script>
357+
358+
<style>
359+
@mixin --dynamic-nested-mixin() {
360+
@result {
361+
color: red;
362+
}
363+
}
364+
</style>
365+
<div id="host9">
366+
<template shadowrootmode="open">
367+
<style>
368+
@mixin --local-mixin() {
369+
@result {
370+
background-color: blue;
371+
}
372+
}
373+
</style>
374+
<div id="inner-host">
375+
<template shadowrootmode="open">
376+
<style>
377+
#target {
378+
@apply --dynamic-nested-mixin;
379+
@apply --local-mixin;
380+
}
381+
</style>
382+
<div id="target">This text should become green.</div>
383+
</template>
384+
</div>
385+
</template>
386+
</div>
387+
<script>
388+
test(() => {
389+
const target = document.getElementById('host9')
390+
.shadowRoot.getElementById('inner-host')
391+
.shadowRoot.getElementById('target');
392+
assert_equals(getComputedStyle(target).color, 'rgb(255, 0, 0)');
393+
assert_equals(getComputedStyle(target).backgroundColor,
394+
'rgb(0, 0, 255)');
395+
396+
const style = document.createElement('style');
397+
style.textContent = `
398+
@mixin --dynamic-nested-mixin() {
399+
@result {
400+
color: green;
401+
}
402+
}
403+
`;
404+
document.body.append(style);
405+
406+
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
407+
assert_equals(getComputedStyle(target).backgroundColor,
408+
'rgb(0, 0, 255)');
409+
}, 'Changing a document mixin invalidates through a local mixin scope');
410+
</script>
411+
412+
<script>
413+
test(() => {
414+
const mixinSheet = new CSSStyleSheet();
415+
mixinSheet.replaceSync(`
416+
@mixin --shared-dynamic-mixin() {
417+
@result {
418+
color: red;
419+
}
420+
}
421+
`);
422+
423+
const targets = [];
424+
for (let i = 0; i < 2; ++i) {
425+
const outerHost = document.createElement('div');
426+
const outerRoot = outerHost.attachShadow({mode: 'open'});
427+
outerRoot.adoptedStyleSheets = [mixinSheet];
428+
429+
const innerHost = document.createElement('div');
430+
outerRoot.append(innerHost);
431+
const innerRoot = innerHost.attachShadow({mode: 'open'});
432+
innerRoot.innerHTML = `
433+
<style>
434+
#target {
435+
@apply --shared-dynamic-mixin;
436+
}
437+
</style>
438+
<div id="target"></div>
439+
`;
440+
targets.push(innerRoot.getElementById('target'));
441+
document.body.append(outerHost);
442+
}
443+
444+
for (const target of targets) {
445+
assert_equals(getComputedStyle(target).color, 'rgb(255, 0, 0)');
446+
}
447+
448+
mixinSheet.cssRules[0].cssRules[0].cssRules[0].style.color =
449+
'green';
450+
451+
for (const target of targets) {
452+
assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)');
453+
}
454+
}, 'A shared adopted mixin invalidates all dependent shadow branches');
455+
</script>
456+
318457
</body>
319458
</html>

0 commit comments

Comments
 (0)