Closed Bug 2075194 Opened 22 days ago Closed 18 days ago

@scope roots that differ only by an attribute value resolve to the same scope between siblings

Categories

(Core :: CSS Parsing and Computation, defect, P3)

defect

Tracking

()

RESOLVED FIXED
159 Branch
Tracking Status
firefox159 --- fixed

People

(Reporter: arifdewi.uae, Assigned: dshin)

References

(Blocks 1 open bug)

Details

Attachments

(3 files)

Attached file gecko-scope-repro.html —

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36

Steps to reproduce

Load this page in Firefox:

<!doctype html>
<style>
  @scope ([data-module="a"]) { .row { color: rgb(10, 10, 10); } }
  @scope ([data-module="b"]) { .row { color: rgb(20, 20, 20); } }
</style>
<section data-module="a"><p class="row">first</p></section>
<section data-module="b"><p class="row">second</p></section>

Actual results

Actual results:

Both paragraphs compute color: rgb(10, 10, 10). The second section is styled
by the first section's @scope block; its own block never applies.

Expected results

Expected results:**

The first paragraph is rgb(10, 10, 10) and the second is rgb(20, 20, 20).
Chromium 153 and WebKit 26.6 both do this.


Additional information:

Three conditions are needed together; changing any one of them gives the
correct result:

  1. The two scoping roots are siblings. Nesting the second section inside
    the first is correct.
  2. The two root elements are otherwise indistinguishable: same tag name and
    same class list. Giving them different classes is correct, and so is giving
    them different tag names. Giving them different ids is not — it still
    reproduces.
  3. The roots are selected by attribute value. Using .a / .b as the
    scoping roots is correct.

Adding a lower boundary (to ([data-module])) does not change the outcome, and
neither does wrapping the rules in @layer, nor delivering the two blocks in
separate stylesheets via <link>, @import or adoptedStyleSheets.

Reproduced on Firefox 156.0 (release, macOS 26.6.2) and Firefox 155 (Playwright
build, headless). Not reproduced on Chromium 153.0.8010.12 or WebKit 26.6.

This pattern — one stylesheet per component, each scoped to
[data-component="<name>"] — is a natural way to use @scope, and the failure
is silent: the component is simply styled as its neighbour, with nothing
logged.

Seems like we're incorrectly sharing styles between them. This code is supposed to prevent it afaict.

Maybe we should disable cousin sharing across scope boundaries instead? WDYT David?

Blocks: @scope
Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(dshin)
Priority: -- → P3

Thanks for the quick response ! :)

Assignee: nobody → dshin
Status: NEW → ASSIGNED
Flags: needinfo?(dshin)

Guys, just in case it might be helpful - attached more test cases. gecko-scope-probe2.html

Pushed by dshin@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/c5cb6a8714ec https://hg.mozilla.org/integration/autoland/rev/2d04042257b6 Prevent @scopes with non-trivial attribute selectors from being style shared unconditionally. r=firefox-style-system-reviewers,emilio

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/63045 for changes under testing/web-platform/tests

Status: ASSIGNED → RESOLVED
Closed: 18 days ago
Resolution: --- → FIXED
Target Milestone: --- → 159 Branch

Upstream PR merged by moz-wptsync-bot

Duplicate of this bug: 2080046
QA Whiteboard: [qa-triage-done-c160/b159]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: