WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
312074
document.styleSheets and shadowRoot.styleSheets incorrectly include adopted style sheets
https://bugs.webkit.org/show_bug.cgi?id=312074
Summary
document.styleSheets and shadowRoot.styleSheets incorrectly include adopted s...
Ahmad Saleem
Reported
2026-04-11 20:48:32 PDT
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
Comment 1
2026-04-11 21:09:19 PDT
<
rdar://problem/174583340
>
Ahmad Saleem
Comment 2
2026-04-11 21:11:56 PDT
Pull request:
https://github.com/WebKit/WebKit/pull/62572
EWS
Comment 3
2026-04-13 04:53:51 PDT
Committed
311074@main
(2dd7e967bacc): <
https://commits.webkit.org/311074@main
> Reviewed commits have been landed. Closing PR #62572 and removing active labels.
Ahmad Saleem
Comment 4
2026-04-15 23:19:48 PDT
Submitted web-platform-tests pull request:
https://github.com/web-platform-tests/wpt/pull/59255
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug