<?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>286403</bug_id>
          
          <creation_ts>2025-01-22 20:40:20 -0800</creation_ts>
          <short_desc>:has(:empty) still applied after the content is changed to not be empty</short_desc>
          <delta_ts>2026-05-04 23:12:52 -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>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://bugs.webkit.org/show_bug.cgi?id=286047</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=311750</see_also>
    
    <see_also>https://github.com/web-platform-tests/wpt/pull/59651</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Keavon">keavon</reporter>
          <assigned_to name="Antti Koivisto">koivisto</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>karlcow</cc>
    
    <cc>koivisto</cc>
    
    <cc>pp.koch</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2089169</commentid>
    <comment_count>0</comment_count>
    <who name="Keavon">keavon</who>
    <bug_when>2025-01-22 20:40:20 -0800</bug_when>
    <thetext>Minimal reproduction:

Fiddle:
https://jsfiddle.net/5n1tb2sd/

HTML:
[&lt;span&gt;{&lt;em&gt;&lt;/em&gt;}&lt;/span&gt;]

CSS:
span:has(em:empty) { color: red }

JS:
setTimeout(() =&gt; { document.querySelector(&quot;em&quot;).innerText = &quot;no longer :empty so span shouldn&apos;t render this as red&quot; }, 1000);

The expected behavior is that the curly brackets start out red for the first second, then the text appears (making &lt;em&gt; no longer :empty) and everything should become black. This works in Chrome and Firefox.

It is broken in Safari Version 18.1 (20619.2.8.11.10) which is the latest I can test through BrowserStack, it keeps the curly brackets and the added text red until I manage to force a repaint. Sometimes, merely opening dev tools causes it to repaint. Other times, I have to inspect the element and begin assigning it some CSS property or toggle an existing CSS property to force a repaint. To be clear, the red style is not applied to the &lt;span&gt; in dev tools, but it has been incorrectly painted red until the next repaint can be forced.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2089385</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2025-01-23 16:32:59 -0800</bug_when>
    <thetext>Resizing the window doesn&apos;t make the issue go away, so this is more than a repaint issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2089420</commentid>
    <comment_count>2</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2025-01-23 19:21:58 -0800</bug_when>
    <thetext>That seems related/similar to Bug 286047</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2090630</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-01-29 20:42:07 -0800</bug_when>
    <thetext>&lt;rdar://problem/143864358&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2198348</commentid>
    <comment_count>4</comment_count>
    <who name="Peter-Paul Koch">pp.koch</who>
    <bug_when>2026-04-09 06:59:11 -0700</bug_when>
    <thetext>I also encountered this bug and have more information as well as a simple test case and a workaround at https://quirksmode.org/browserbugs/safari-has-empty.html

Summary:
- y:has(x:empty) is checked for emptiness only one, between DOMContentLoaded and load.
- Emptiness is resolved incorrectly if element x is filled by a JavaScript onload AND the body  overflows the html vertically, but not horizontally.
- If this is the case AND element y has CSS lengths in viewport units AND element x is currently filled, resizing the window updates the styles of element y once.
- a special case applies if y has display: none; see page

I probably got some of the details wrong, but I&apos;m fairly certain of the gist.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2198609</commentid>
    <comment_count>5</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2026-04-09 18:15:07 -0700</bug_when>
    <thetext>*** Bug 311750 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2198611</commentid>
    <comment_count>6</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2026-04-09 18:22:29 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/62402</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2198757</commentid>
    <comment_count>7</comment_count>
    <who name="Antti Koivisto">koivisto</who>
    <bug_when>2026-04-10 03:44:21 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/62436</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2198816</commentid>
    <comment_count>8</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-04-10 08:53:24 -0700</bug_when>
    <thetext>Committed 310932@main (cc50c7dd8a0c): &lt;https://commits.webkit.org/310932@main&gt;

Reviewed commits have been landed. Closing PR #62436 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2199886</commentid>
    <comment_count>9</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-04-13 14:19:24 -0700</bug_when>
    <thetext>Committed 305413.653@safari-7624-branch (9679268f8b84): &lt;https://commits.webkit.org/305413.653@safari-7624-branch&gt;

Reviewed commits have been landed. Closing PR #4921 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>