Skip to content

Conversation

@mgol
Copy link
Member

@mgol mgol commented Feb 10, 2023

CSS.supports( "selector(...)" ) has different semantics than selectors passed to querySelectorAll. Apart from the fact that the former returns false for unrecognized selectors and the latter throws, qSA is more forgiving and accepts some invalid selectors, auto-correcting them where needed - for example, mismatched brackers are auto-closed. This behavior difference is breaking for many users.

To add to that, a recent CSSWG resolution made :is() & :where() the only pseudos with forgiving parsing; browsers are in the process of making :has() parsing unforgiving.

Taking all that into account, we go back to our previous try-catch approach without relying on CSS.supports( "selector(...)" ). The only difference is we detect forgiving parsing in :has() and mark the selector as buggy.

Fixes jquery/jquery#5194
Ref jquery/jquery#5098
Ref gh-486
Ref w3c/csswg-drafts#7676

@mgol mgol added Needs review Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Feb 10, 2023
@mgol mgol added this to the 2.3.10 milestone Feb 10, 2023
@mgol mgol self-assigned this Feb 10, 2023
@timmywil timmywil removed the Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. label Feb 13, 2023
`CSS.supports( "selector(...)" )` has different semantics than selectors passed
to `querySelectorAll`. Apart from the fact that the former returns `false` for
unrecognized selectors and the latter throws, `qSA` is more forgiving and
accepts some invalid selectors, auto-correcting them where needed - for
example, mismatched brackers are auto-closed. This behavior difference is
breaking for many users.

To add to that, a recent CSSWG resolution made `:is()` & `:where()` the only
pseudos with forgiving parsing; browsers are in the process of making `:has()`
parsing unforgiving.

Taking all that into account, we go back to our previous try-catch approach
without relying on `CSS.supports( "selector(...)" )`. The only difference
is we detect forgiving parsing in `:has()` and mark the selector as buggy.

Fixes jquery/jquery#5194
Ref jquery/jquery#5098
Ref jquerygh-486
Ref w3c/csswg-drafts#7676
@mgol mgol force-pushed the has-non-forgiving branch from a46dfef to 42a96b3 Compare February 13, 2023 23:30
@mgol mgol merged commit 15a1238 into jquery:main Feb 14, 2023
@mgol mgol deleted the has-non-forgiving branch February 14, 2023 12:13
@mgol mgol removed the Needs review label Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

jQuery 3.6.3 throws on some invalid selectors accepted in <=3.6.1 in Firefox (it works in Chrome & Safari)

2 participants