Bug 312074
| Summary: | document.styleSheets and shadowRoot.styleSheets incorrectly include adopted style sheets | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Ahmad Saleem <ahmad.saleem792> |
| Component: | New Bugs | Assignee: | Ahmad Saleem <ahmad.saleem792> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar, WPTImpact |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| See Also: | https://github.com/web-platform-tests/wpt/pull/59255 | ||
Ahmad Saleem
Per the CSSOM spec (§6.2 CSS Style Sheet Collections), the "document or shadow root CSS style sheets" list should only
contain:
1. CSS style sheets created from HTTP Link headers
2. CSS style sheets associated with the DocumentOrShadowRoot (i.e., from <style> and <link> elements), in tree order
Adopted style sheets (from adoptedStyleSheets) are only included in the "final CSS style sheets" list, which is a
separate concept used for style resolution. The styleSheets attribute (StyleSheetList) should reflect the "document or
shadow root CSS style sheets", not the "final CSS style sheets".
WebKit currently includes adopted style sheets in StyleSheetList, causing document.styleSheets and
shadowRoot.styleSheets to report incorrect lengths and entries when adoptedStyleSheets is non-empty.
Steps to Reproduce:
<style id="sheet1">body { width: 50%; }</style>
<script>
const sheet = new CSSStyleSheet();
document.adoptedStyleSheets = [sheet];
console.log(document.styleSheets.length); // Expected: 1, Actual: 2
</script>
Expected: document.styleSheets.length is 1 (only the <style> element sheet).
Actual: document.styleSheets.length is 2 (includes the adopted sheet).
Root Cause:
In Source/WebCore/style/StyleScope.cpp, collectActiveStyleSheets() appends adopted style sheets to both sheets (used
for style resolution — correct) and styleSheetsForStyleSheetsList (backing the DOM-visible StyleSheetList —
incorrect).
Spec Reference: https://drafts.csswg.org/cssom/#css-style-sheet-collections
Failing WPT Tests:
- css/cssom/StyleSheetList-constructable.html
- css/cssom/StyleSheetList-constructable-with-style-recalc.html
---
This also affects shadowRoot.styleSheets since the same code path in StyleScope is shared by both Document and
ShadowRoot.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/174583340>
Ahmad Saleem
Pull request: https://github.com/WebKit/WebKit/pull/62572
EWS
Committed 311074@main (2dd7e967bacc): <https://commits.webkit.org/311074@main>
Reviewed commits have been landed. Closing PR #62572 and removing active labels.
Ahmad Saleem
Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/59255