🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@mgol
Copy link
Member

@mgol mgol commented Feb 9, 2023

Summary

This is a 3.x-stable version of #5206

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.

The PR also updates playwright-webkit so that we test against a version of WebKit that already has non-forgiving :has().

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

-46 bytes

Checklist

  • New tests have been added to show the fix or feature works
  • Grunt build and unit tests pass locally with these changes
  • If needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com

@mgol mgol added Selector Needs review Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Feb 9, 2023
@mgol mgol added this to the 3.7.0 milestone Feb 9, 2023
@mgol mgol self-assigned this Feb 9, 2023
@mgol
Copy link
Member Author

mgol commented Feb 10, 2023

Sizzle PR: jquery/sizzle#493

@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.

The PR also updates `playwright-webkit` so that we test against a version
of WebKit that already has non-forgiving `:has()`.

Fixes jquerygh-5194
Ref jquerygh-5098
Ref jquerygh-5107
Ref w3c/csswg-drafts#7676
@mgol mgol force-pushed the 3.x-has-non-forgiving branch from bcb54ed to 2d2c2ef Compare February 13, 2023 23:30
@mgol mgol merged commit 63c3af4 into jquery:3.x-stable Feb 14, 2023
@mgol mgol removed the Needs review label Feb 14, 2023
@mgol mgol deleted the 3.x-has-non-forgiving branch February 14, 2023 10:42
mgol added a commit to jquery/sizzle that referenced this pull request Feb 14, 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
Closes gh-493
Ref jquery/jquery#5098
Ref jquery/jquery#5206
Ref jquery/jquery#5207
Ref gh-486
Ref w3c/csswg-drafts#7676
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

2 participants