- Notifications
You must be signed in to change notification settings - Fork20.5k
Selector: Inline Sizzle into the selector module: 3.x version#5113
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
mgol commentedSep 9, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CI is failing due to Chrome |
649cfb2 to084fe49Comparemgol commentedSep 13, 2022
-846 bytes as of051909a. |
mgol commentedSep 13, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I fixed iOS 7+ & Android 4.0-4.3 selector tests and I verified it by running both Sizzle & selector tests (from this branch) on iOS 7 & Android 4.0-4.2 (4.3 is not available in BrowserStack Live). I also run TestSwarm on this branch on the 3.x browsers athttps://swarm.jquery.org/job/12556, results are green. This looks good to go. Of course, just before merging I'll double check if there are any fixes to CP before merging (most notably,jquery/sizzle#486) but for now this is it! 🎉 |
mgol commentedSep 13, 2022
I also run the entire jQuery test suite on Android 4.0 on this branch (it took ages to run!) and there were only two minor |
| // Testing for detecting duplicates is unpredictable so instead assume we can't | ||
| // depend on duplicate detection in all browsers without a stable sort. | ||
| hasDuplicate=!support.sortStable; | ||
| sortInput=!support.sortStable&&slice.call(results,0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The last change in Sizzle affectingsupport.detectDuplicates landed injquery/sizzle@07a5f1f but I had trouble relying on it. Even in Chrome the test sometimes was failing, despite my various attempts withexpando tweaks for the test.
Since both of those tests only fail in Android Browser 4.x fro all of our supported browsers in jQuery 3.x, I started usingsupport.sortStable here instead.
Uh oh!
There was an error while loading.Please reload this page.
13bc0d0 to5f88f31Comparemgol commentedSep 21, 2022
@timmywil@gibson042 this is passing on GitHub now; it's ready for a final review. |
77fe8c0 toac6fe32Comparemgol commentedOct 7, 2022
@timmywil@gibson042 If you want, I can extract test changes to a separate PR to be landed first. That way, this PR would be smaller and we'd have additional validation for the tests that they work in the same way both with the old & new implementation. |
e6a0927 to53e16aeComparemgol commentedNov 17, 2022
I rebased the PR & I added 4 new commits (the first one being titled "Selector:Manipulation: Fix DOM manip within template contents"). This is mostly to address items from other PRs and what already landed in Sizzle / jQuery |
That way, `/* eslint-enable */` comments won't re-enable the rule.
jQuery has followed the following logic for selector handling for ages:1. Modify the selector to adhere to scoping rules jQuery mandates.2. Try `qSA` on the modified selector. If it succeeds, use the results.3. If `qSA` threw an error, run the jQuery custom traversal instead.It worked fine so far but now CSS has a concept of forgiving selector lists thatsome selectors like `:is()` & `:has()` use. That means providing unrecognizedselectors as parameters to `:is()` & `:has()` no longer throws an error, it willjust return no results. That made browsers with native `:has()` support breakselectors using jQuery extensions inside, e.g. `:has(:contains("Item"))`.Detecting support for selectors can also be done via:```jsCSS.supports( "selector(SELECTOR_TO_BE_TESTED)" )```which returns a boolean. There was a recent spec change requiring this API toalways use non-forgiving parsing:w3c/csswg-drafts#7280 (comment)However, no browsers have implemented this change so far.To solve this, two changes are being made:1. In browsers supports the new spec change to `CSS.supports( "selector()" )`, use it before trying `qSA`.2. Otherwise, add `:has` to the buggy selectors list.Refjquerygh-5098Refjquerygh-5107Refjquery/sizzle#486Refw3c/csswg-drafts#7676Backport some changes fromjquerygh-5085 to make selector-native tests pass. Plusa few other fixes.
The tokenization stressor test needs to exclude `.qunit-source` or it sometimesfits into the results.This change has already landed on `main` injquerygh-4550.Refjquerygh-4550
This is a private API but since it's been tested in Sizzle, it makes senseto continue testing it on the jQuery 3.x line.
Previously, they were loaded after test files which meant top level usagewas not evaluated correctly.
This backports custom pseudos tests from Sizzle; they were missed in originaltest backports. Also, the support for legacy custom pseudos has been dropped.The `jQuery.expr` test cleanup has been wrapped in `try-finally` for cleanertest isolation in case anything goes wrong.Refjquerygh-5137
The `<template/>` element `contents` property is a document fragment that mayhave a `null` `documentElement`. In Safari 16 this happens in more cases dueto recent spec changes - in particular, even if that document fragment isexplicitly adopted into an outer document. We're testing both of those casesnow.The crash used to happen in `jQuery.contains`. As it turns out, we don't needto query the supposed container `documentElement` if it has the`Node.DOCUMENT_NODE` (9) `nodeType`; we can call `.contains()` directly onthe `document`. That avoids the crash.Fixesjquerygh-5147Closesjquerygh-5158(cherry picked from commit3299236)
Firefox 106 adjusted to the spec mandating that `CSS.supports("selector(...)")`uses non-forgiving parsing which makes it pass the relevant support test.Closesjquerygh-5141(cherry picked from commit716130e)`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`* `jQuery.find.tokenize`Fixesjquerygh-5259Refjquery/sizzle#242Refjquerygh-5113Refjquerygh-4395Refjquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`* `jQuery.find.tokenize`Fixesjquerygh-5259Refjquery/sizzle#242Refjquerygh-5113Refjquerygh-4395Refjquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`* `jQuery.find.tokenize`Fixesjquerygh-5259Refjquery/sizzle#242Refjquerygh-5113Refjquerygh-4395Refjquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`* `jQuery.find.tokenize`Fixesjquerygh-5259Refjquery/sizzle#242Refjquerygh-5113Refjquerygh-4395Refjquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`A new test was also added for `jQuery.find.tokenize` - even Sizzle wasmissing one.Fixesjquerygh-5259Refjquery/sizzle#242Refjquerygh-5113Refjquerygh-4395Refjquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`A new test was also added for `jQuery.find.tokenize` - even Sizzle wasmissing one.Fixesjquerygh-5259Refjquery/sizzle#242Refjquerygh-5113Refjquerygh-4395Refjquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`A new test was also added for `jQuery.find.tokenize` - even Sizzle wasmissing one.Fixesjquerygh-5259Refjquerygh-5260Refjquery/sizzle#242Refjquerygh-5113Refjquerygh-4395Refjquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`A new test was also added for `jQuery.find.tokenize` - even Sizzle wasmissing one.Fixesjquerygh-5259Refjquerygh-5263Refjquery/sizzle#242Refjquerygh-5113Refjquerygh-4395Refjquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.Some other APIs so far only exposed on the `3.x` line are also addedback:* `jQuery.find.select`* `jQuery.find.compile`* `jQuery.find.setDocument`In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`A new test was also added for `jQuery.find.tokenize` - even Sizzle wasmissing one.Fixesjquerygh-5259Refjquerygh-5260Refjquery/sizzle#242Refjquerygh-5113Refjquerygh-4395Refjquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.Some other APIs so far only exposed on the `3.x` line are also addedback:* `jQuery.find.select`* `jQuery.find.compile`* `jQuery.find.setDocument`In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`A new test was also added for `jQuery.find.tokenize` - even Sizzle wasmissing one.Fixesgh-5259Closesgh-5263Refgh-5260Refjquery/sizzle#242Refgh-5113Refgh-4395Refgh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result,it has historically been available in jQuery via `jQuery.find.tokenize`.That got dropped during Sizzle removal; this change restores the API.In addition to that, Sizzle tests have been backported for the followingAPIs:* `jQuery.find.matchesSelector`* `jQuery.find.matches`* `jQuery.find.compile`* `jQuery.find.select`A new test was also added for `jQuery.find.tokenize` - even Sizzle wasmissing one.Fixesgh-5259Closesgh-5260Refgh-5263Refjquery/sizzle#242Refgh-5113Refgh-4395Refgh-4406
Uh oh!
There was an error while loading.Please reload this page.
Summary
The first commit is a cherry-pick of#4406.
The next commits are cherry-picks of the branch from which I landed#4395; see that PR for more details about this part. The last commit from this batch is named "Selector: Reduce selector-native.js". NOTE: not all of the changes were backported as on
3.x-stablewe need to maintain backwards compatibility. The end ofsrc/selector.jsconsists of a lot of assignments tojQuery.findto keep the old Sizzle interface intact.All the subsequent commits are largely backporting changes to
src/selector.js&src/selector/**/*that landed after#4395 and changes from Sizzle after the backport was done.Some last commits are fixing minor browser issues.
This PR passes all jQuery tests in latest Firefox, Chrome & IE 9-11. All Sizzle tests also pass with
Sizzle = jQuery.find.There are minor issues in iOS 7 (just 2 tests failing that I'll fix) and I still need to verify old Android and generally all remaining browsers supported by 3.x. But considering IE is goodand old iOS has only minor issues, I'm optimistic this can work.I'd love some
preliminaryreviews of this.-851 bytes as of
0715705.TODO for me:
Checklist
If needed, a docs issue/PR was created athttps://github.com/jquery/api.jquery.com