<?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>285114</bug_id>
          
          <creation_ts>2024-12-23 14:57:06 -0800</creation_ts>
          <short_desc>Subsequent nested styles ignored after incorrect nested selector</short_desc>
          <delta_ts>2025-03-28 09:44:17 -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>CSS</component>
          <version>Safari 17</version>
          <rep_platform>Mac (Intel)</rep_platform>
          <op_sys>macOS 14</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://github.com/web-platform-tests/wpt/pull/50310</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=290584</see_also>
          <bug_file_loc>https://codepen.io/alvaromontoro/pen/emORgey</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Minor</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alvaro Montoro">alvaromontoro</reporter>
          <assigned_to name="Matthieu Dubet">m_dubet</assigned_to>
          <cc>alvaromontoro</cc>
    
    <cc>karlcow</cc>
    
    <cc>koivisto</cc>
    
    <cc>lx2798</cc>
    
    <cc>m_dubet</cc>
    
    <cc>vincent.emonet</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2083703</commentid>
    <comment_count>0</comment_count>
    <who name="Alvaro Montoro">alvaromontoro</who>
    <bug_when>2024-12-23 14:57:06 -0800</bug_when>
    <thetext>In CSS Nesting, if an &quot;erroneous&quot; selector is included, the following rules will be ignored and not applied. This behavior happens on Safari, but it is not the same on Chrome or Firefox.

For example (you can find a running demo on this CodePen https://codepen.io/alvaromontoro/pen/emORgey): if we have the following code:

```html
&lt;div&gt;
  Hello &lt;span&gt;World&lt;/span&gt;!
&lt;/div&gt;

&lt;style&gt;
div {
  color: blue;
  
  span {
    color: red;
  }
  
  /* this is an incorrect selector because the brackets are empty */
  error[] {
    color: yellow;
  }
  
  span {
    color: green;
  }
}
&lt;/style&gt;
```

The word &quot;World&quot; will be green on Chrome and Firefox, but red on Safari. That happens because the styles after the incorrect selector are not processed by Safari, providing a different experience to other browsers.

-----

I ran into this issue while styling a custom input range. There is no fully standard way of doing this, so I had to use special vendor-prefixed pseudo-classes. My code was organized by feature, first the styles for the track, then the styles for the thumb:

```css
.range {
  /* track styles */
  &amp;::-webkit-slider-runnable-track { ... }
  &amp;::-moz-range-track { ... }
  /* thumb styles */
  &amp;::-webkit-slider-thumb { ... }
  &amp;::-moz-range-thumb { ... }
}
```

When I did that, the thumb styles were not applied correctly on Safari (while they worked just fine on other browsers). I solved it by rearranging the code by vendor prefixes instead of by feature:

```css
.range {
  /* Chrome + Safari */
  &amp;::-webkit-slider-runnable-track { ... }
  &amp;::-webkit-slider-thumb { ... }
  /* Firefox */
  &amp;::-moz-range-track { ... }
  &amp;::-moz-range-thumb { ... }
}
```

Another option that worked was removing the nesting. But, ideally, it should not matter which order these styles were nested in as they are mutually exclusive. It would be better if WebKit/Safari ignored the incorrect nested selector, then kept processing the remaining ones.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2083712</commentid>
    <comment_count>1</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-12-23 16:14:01 -0800</bug_when>
    <thetext>Confirmed.
I tried also with `err/or {color: yellow;}` to make sure it was not an artefact of `error[]`

```
FAIL Safari Technology Preview  209           20621.1.6
PASS Firefox Nightly            135.0a1       13524.12.18
PASS Google Chrome Canary       133.0.6914.0  6914.0
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2084290</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-12-30 14:58:13 -0800</bug_when>
    <thetext>&lt;rdar://problem/142187930&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2088855</commentid>
    <comment_count>3</comment_count>
    <who name="Matthieu Dubet">m_dubet</who>
    <bug_when>2025-01-21 17:00:23 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/39356</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2088999</commentid>
    <comment_count>4</comment_count>
    <who name="Matthieu Dubet">m_dubet</who>
    <bug_when>2025-01-22 08:32:08 -0800</bug_when>
    <thetext>*** Bug 284746 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2089977</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-01-27 09:11:44 -0800</bug_when>
    <thetext>Committed 289429@main (ae311f82a32c): &lt;https://commits.webkit.org/289429@main&gt;

Reviewed commits have been landed. Closing PR #39356 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106837</commentid>
    <comment_count>6</comment_count>
    <who name="Matthieu Dubet">m_dubet</who>
    <bug_when>2025-03-28 09:44:17 -0700</bug_when>
    <thetext>*** Bug 290584 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>