Bug 244708 - :has() selector does not accept forgiving selector list
Summary: :has() selector does not accept forgiving selector list
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2022-09-02 02:22 PDT by Rune Lillesveen
Modified: 2022-09-20 22:55 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rune Lillesveen 2022-09-02 02:22:35 PDT
The :has() selector takes a <forgiving-relative-selector-list>[1], but a rule like :has(:unknown) {} is fully dropped in WebKit.

There is a failing wpt test in [2].

[1] https://drafts.csswg.org/selectors/#typedef-forgiving-relative-selector-list
[2] https://wpt.fyi/results/css/selectors/has-error-recovery.html?label=experimental&label=master&aligned
Comment 1 Michał Gołębiowski-Owczarek 2022-09-02 03:48:57 PDT
Note that implementing `:has` according to the spec breaks `:has` usage with jQuery for almost all versions in use in the wild: https://github.com/jquery/jquery/issues/5098
Comment 2 Antti Koivisto 2022-09-02 05:26:15 PDT
We currently do use forgiving parsing for :has() but still fail the selector if the selector lists ends up empty. That is

:has(:foo, bar) { }

is valid and parses to

:has(bar) { }

but 

:has(:foo) is invalid.
Comment 3 Antti Koivisto 2022-09-02 05:26:34 PDT
I suppose this saves us from the jQuery problem.
Comment 4 Michał Gołębiowski-Owczarek 2022-09-02 10:02:28 PDT
See https://github.com/w3c/csswg-drafts/issues/7676#issuecomment-1235724730

The WebKit behavior still breaks some jQuery selectors. True, it doesn't break:
```
div:has(span:contains('Item'))
```
but it still breaks:
```
div:has(div, span:contains('Item'))
```
Maybe that latter kind of selectors is not used as often in the wild.
Comment 5 Michał Gołębiowski-Owczarek 2022-09-05 05:51:59 PDT
A full fix for future jQuery versions requires implementing bug 244808 so please have a look at this.
Comment 6 Radar WebKit Bug Importer 2022-09-09 02:23:16 PDT
<rdar://problem/99736653>
Comment 7 Karl Dubost 2022-09-15 09:35:06 PDT
Note that there are discussions about this behavior being beneficial currently, as it doesn't break jQuery.

See the discussion in https://github.com/w3c/csswg-drafts/issues/7676
Comment 8 Karl Dubost 2022-09-15 09:36:50 PDT
oops hit return too early. 
Chrome 106 copies the behavior of Safari.