-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Selector: Make selector lists work with qSA
again
#5178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4255ed6
to
7f8a7a8
Compare
jQuery 3.6.2 started using `CSS.supports( "selector(SELECTOR)" )` before using `querySelectorAll` on the selector. This was to solve jquerygh-5098 - some selectors, like `:has()`, now had their parameters parsed in a forgiving way, meaning that `:has(:fakepseudo)` no longer throws but just returns 0 results, breaking that jQuery mechanism. A recent spec change made `CSS.supports( "selector(SELECTOR)" )` always use non-forgiving parsing, allowing us to use this API for what we've used `try-catch` before. To solve the issue on the spec side for older jQuery versions, `:has()` parameters are no longer using forgiving parsing in the latest spec update but our new mechanism is more future-proof anyway. However, the jQuery implementation has a bug - in `CSS.supports( "selector(SELECTOR)" )`, `SELECTOR` needs to be a `<complex-selector>` and not a `<complex-selector-list>`. Which means that selector lists now skip `qSA` and go to the jQuery custom traversal: ```js CSS.supports("selector(div:valid, span)"); // false CSS.supports("selector(div:valid)"); // true CSS.supports("selector(span)"); // true ``` To solve this, this commit wraps the selector list passed to `CSS.supports( "selector(:is(SELECTOR))" )` with `:is`, making it a single selector again. See: * https://w3c.github.io/csswg-drafts/css-conditional-4/#at-supports-ext * https://w3c.github.io/csswg-drafts/selectors-4/#typedef-complex-selector * https://w3c.github.io/csswg-drafts/selectors-4/#typedef-complex-selector-list Fixes jquerygh-5177 Ref w3c/csswg-drafts#7280
7f8a7a8
to
71f6ecd
Compare
timmywil
approved these changes
Dec 19, 2022
mgol
commented
Dec 19, 2022
mgol
commented
Dec 19, 2022
mgol
added a commit
that referenced
this pull request
Dec 19, 2022
mgol
added a commit
that referenced
this pull request
Dec 19, 2022
jQuery 3.6.2 started using `CSS.supports( "selector(SELECTOR)" )` before using `querySelectorAll` on the selector. This was to solve gh-5098 - some selectors, like `:has()`, now had their parameters parsed in a forgiving way, meaning that `:has(:fakepseudo)` no longer throws but just returns 0 results, breaking that jQuery mechanism. A recent spec change made `CSS.supports( "selector(SELECTOR)" )` always use non-forgiving parsing, allowing us to use this API for what we've used `try-catch` before. To solve the issue on the spec side for older jQuery versions, `:has()` parameters are no longer using forgiving parsing in the latest spec update but our new mechanism is more future-proof anyway. However, the jQuery implementation has a bug - in `CSS.supports( "selector(SELECTOR)" )`, `SELECTOR` needs to be a `<complex-selector>` and not a `<complex-selector-list>`. Which means that selector lists now skip `qSA` and go to the jQuery custom traversal: ```js CSS.supports("selector(div:valid, span)"); // false CSS.supports("selector(div:valid)"); // true CSS.supports("selector(span)"); // true ``` To solve this, this commit wraps the selector list passed to `CSS.supports( "selector(:is(SELECTOR))" )` with `:is`, making it a single selector again. See: * https://w3c.github.io/csswg-drafts/css-conditional-4/#at-supports-ext * https://w3c.github.io/csswg-drafts/selectors-4/#typedef-complex-selector * https://w3c.github.io/csswg-drafts/selectors-4/#typedef-complex-selector-list Fixes gh-5177 Closes gh-5178 Ref w3c/csswg-drafts#7280 (cherry picked from commit 09d988b)
mgol
added a commit
that referenced
this pull request
Dec 19, 2022
A newly added test making sure a native selector containing the `:valid` pseudo works when no jQuery-specific selectors are used was failing in IE 9 as that browser lacks support for this pseudo. This commit disables that test in IE 9. Ref gh-5178
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
jQuery 3.6.2 started using
CSS.supports( "selector(SELECTOR)" )
before usingquerySelectorAll
on the selector. This was to solve gh-5098 - some selectors, like:has()
, now have their parameters parsed in a forgiving way, meaning that:has(:fakepseudo)
no longer throws but just returns 0 results, breaking that jQuery mechanism.A recent spec change]() made
CSS.supports( "selector(SELECTOR)" )
always use non-forgiving parsing, allowing us to use this API for what we've usedtry-catch
before.To solve the issue on the spec side for older jQuery versions,
:has()
parameters are no longer using forgiving parsing in the latest spec update but our new mechanism is more future-proof anyway.However, the jQuery implementation has a bug - in
CSS.supports( "selector(SELECTOR)" )
,SELECTOR
needs to be a<complex-selector>
and not a<complex-selector-list>
. Which means that selector lists now skipqSA
and go to the jQuery custom traversal:To solve this, this commit wraps the selector list passed to
CSS.supports( "selector(:is(SELECTOR))" )
with:is
, making it a single selector again.See:
Fixes gh-5177
Ref w3c/csswg-drafts#7280
+2 bytes
Checklist
If needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com