Bug 242328 - Wrong specificity of :has() pseudo-classes
Summary: Wrong specificity of :has() pseudo-classes
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: Safari 15
Hardware: Mac (Apple Silicon) macOS 12
: P2 Normal
Assignee: Antti Koivisto
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-07-04 19:24 PDT by Ilya Streltsyn
Modified: 2022-07-05 10:10 PDT (History)
14 users (show)

See Also:


Attachments
Patch (3.85 KB, patch)
2022-07-05 01:55 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ilya Streltsyn 2022-07-04 19:24:59 PDT
The specificity of the selector containing the `:has()` pseudo-class appears to be higher than the specificity of the selector with the same number of classes without it.
 
Steps to reproduce:

1. Navigate to the https://codesandbox.io/s/peaceful-edison-8kcudt?file=/index.html demo
2. Check the background color of the three cards
3. Open Web Inspector
4. Inspect computed styles of the first card

Expected results:

The first card is light green, the next two cards are light blue.
Web Inspector shows that the rule for the `.card.card--green` selector has overridden the rule for the `.card:has(.title)` selector (as having the same specificity but coming later in the code).

Actual results:

All three cards are light blue.
Web Inspector shows that the rule for the `.card:has(.title)` selector has overridden the rule for the `.card.card--green` selector.


There is a closed bug https://bugs.webkit.org/show_bug.cgi?id=235351 regarding the same topic, so it might be a regression.

Both stable Safari 15.5 and Safari TP 148 display the same behavior. Chrome 103 with the "Experimental Web Platform features" flag enabled displays expected results.
Comment 1 Tim Nguyen (:ntim) 2022-07-04 21:50:26 PDT Comment hidden (obsolete)
Comment 2 Antti Koivisto 2022-07-05 00:59:37 PDT
(In reply to Tim Nguyen (:ntim) from comment #1)
> :is() & :not() have the same issue.

I see the :has() issue but I'm not seeing that. Please file a separate bug with a test case.
Comment 3 Antti Koivisto 2022-07-05 01:55:34 PDT
Created attachment 460675 [details]
Patch
Comment 4 EWS Watchlist 2022-07-05 01:57:47 PDT
This patch modifies the imported WPT tests. Please ensure that any changes on the tests (not coming from a WPT import) are exported to WPT. Please see https://trac.webkit.org/wiki/WPTExportProcess
Comment 5 EWS 2022-07-05 10:09:30 PDT
Committed 252140@main (7af18efe7e89): <https://commits.webkit.org/252140@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 460675 [details].
Comment 6 Radar WebKit Bug Importer 2022-07-05 10:10:14 PDT
<rdar://problem/96449421>