tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 67ab25580840a2f279addf59973b380786fb4f6b
parent 7400562c28364771e38e51aeb30822e5b7d9e397
Author: Anders Hartvoll Ruud <andruud@chromium.org>
Date:   Wed, 26 Nov 2025 08:54:53 +0000

Bug 2001980 [wpt PR 56223] - Use unconnected RuleSets for duplicate contents with cascade layers, a=testonly

Automatic update from web-platform-tests
Use unconnected RuleSets for duplicate contents with cascade layers

We currently deduplicate shared StyleSheetContents during RuleSet-
building in order to avoid "collapsing" distinct anonymous layers
into one. This is done in a somewhat roundabout way with a "fake"
rule mutation event, but is otherwise not an unreasonable way
of handling it.

However, it does not handle the case where the same CSSStyleSheet
instance appears in the list of active stylesheets (which can happen
when the same sheet is listed multiple times in adoptedStyleSheets).
The exact behavior is not handled explicitly by specs, but what we're
doing is not a reasonable default: other things in the RuleSet
(e.g. style rules, named constructs defined by at-rules) do "see"
the different orders when the same sheet is specified multiple times
(see examples in Issue 462744687). Layers are just inconsistent with
this.

To address this, this CL tracks which StyleSheetContents we've already
seen (shared or otherwise), and adds an *unconnected* RuleSet for any
already-seen contents. (Unconnected RuleSets are one-off RuleSets that
ignore the RuleSet cache on StyleSheetContents). In sharing cases
(multiple CSSStyleSheets, same StyleSheetContents) this means we'll
cache less, but also deduplicate less. Under the assumption that
adding the same StyleSheetContents more than once is a rare corner case,
the performance characteristics of this seem unimportant anyway.

This change aligns our behavior with Firefox and Safari.

Fixed: 462744687
Change-Id: I564f7598204227213bce5b9b8eeb62c77acd079b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7185810
Reviewed-by: Steinar H Gunderson <sesse@chromium.org>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1549143}

--

wpt-commits: 0c81e1dd13b565a25cec361b58e9454d378b7ce6
wpt-pr: 56223

Diffstat:
Atesting/web-platform/tests/css/css-cascade/layer-stylesheet-multi-adoption.html | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/testing/web-platform/tests/css/css-cascade/layer-stylesheet-multi-adoption.html b/testing/web-platform/tests/css/css-cascade/layer-stylesheet-multi-adoption.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<link rel="help" href="https://drafts.csswg.org/css-cascade-5/#unnamed-layers"> +<link rel="help" href="https://drafts.csswg.org/cssom/#dom-documentorshadowroot-adoptedstylesheets"> +<link rel="help" href="https://issues.chromium.org/issues/462744687"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=target>Test</div> +<script> + test(() => { + let a = new CSSStyleSheet(); + a.replaceSync(`@layer { div { color: green; } }`); + let b = new CSSStyleSheet(); + b.replaceSync(`@layer { div { color: red; } }`); + document.adoptedStyleSheets = [a, b, a]; + assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)'); + }); +</script>