<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>312074</bug_id>
          
          <creation_ts>2026-04-11 20:48:32 -0700</creation_ts>
          <short_desc>document.styleSheets and shadowRoot.styleSheets incorrectly include adopted style sheets</short_desc>
          <delta_ts>2026-04-15 23:19:48 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://github.com/web-platform-tests/wpt/pull/59255</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar, WPTImpact</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ahmad Saleem">ahmad.saleem792</reporter>
          <assigned_to name="Ahmad Saleem">ahmad.saleem792</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2199344</commentid>
    <comment_count>0</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-04-11 20:48:32 -0700</bug_when>
    <thetext>Per the CSSOM spec (§6.2 CSS Style Sheet Collections), the &quot;document or shadow root CSS style sheets&quot; list should only
   contain:       
                                                                                                                        
  1. CSS style sheets created from HTTP Link headers                                                                    
  2. CSS style sheets associated with the DocumentOrShadowRoot (i.e., from &lt;style&gt; and &lt;link&gt; elements), in tree order
                                                                                                                        
  Adopted style sheets (from adoptedStyleSheets) are only included in the &quot;final CSS style sheets&quot; list, which is a     
  separate concept used for style resolution. The styleSheets attribute (StyleSheetList) should reflect the &quot;document or
   shadow root CSS style sheets&quot;, not the &quot;final CSS style sheets&quot;.                                                     
                  
  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:                                                                                                   
   
  &lt;style id=&quot;sheet1&quot;&gt;body { width: 50%; }&lt;/style&gt;                                                                       
  &lt;script&gt;                                                                                                              
    const sheet = new CSSStyleSheet();                                                                                  
    document.adoptedStyleSheets = [sheet];                                                                              
    console.log(document.styleSheets.length); // Expected: 1, Actual: 2                                                 
  &lt;/script&gt;                                                                                                             
                                                                                                                        
  Expected: document.styleSheets.length is 1 (only the &lt;style&gt; 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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2199345</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2026-04-11 21:09:19 -0700</bug_when>
    <thetext>&lt;rdar://problem/174583340&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2199346</commentid>
    <comment_count>2</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-04-11 21:11:56 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/62572</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2199678</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-04-13 04:53:51 -0700</bug_when>
    <thetext>Committed 311074@main (2dd7e967bacc): &lt;https://commits.webkit.org/311074@main&gt;

Reviewed commits have been landed. Closing PR #62572 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2200970</commentid>
    <comment_count>4</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-04-15 23:19:48 -0700</bug_when>
    <thetext>Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/59255</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>