-
Notifications
You must be signed in to change notification settings - Fork 37
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
Some uses of :has
throw "not a valid selector"
#123
Comments
+1ing this, the following selectors also throw "not a valid selector" errors for us in Jest (works fine in browsers): Previous sibling selectors: &:has(+ .classA) {
color: red;
} Nested *:has(*:is(.classA, .classB)) + *:is(.classC, .classD) {
color: red;
} |
@cee-chen The previous sibling selectors work with the version |
it seems to be this MR that caused the regression #98, I can install the latest version and then revert that line and the issue is no longer there |
Line 1025 in ee69b43
but with |
Hi @dperini. Thanks for looking into this. We tested your change and @gmarinov's together and separately. For our use case, which is essentially the same as the OP's( - source = 'if(s.match("' + referenceElement.replace(/\x22/g, '\\"') + '",e) && e.querySelector("'+ expr.replace(/\x22/g, '\\"') +'")){' + source + '}';
+ source = 'if(s.match("' + referenceElement.replace(/\x22/g, '\\"') + '",e) && e.querySelector(":scope '+ expr.replace(/\x22/g, '\\"') +'")){' + source + '}'; Yours alone in 0094625 did not, we still had the same invalid selector errors. Not sure if that addresses other issues though. Thanks! |
@cpmotion While testing I realized that maybe ":scope " should only be added in case of mangled selectors arguments, not unconditionally. I may be wrong so your comments and those of other developers are welcome. Also adding "* " instead of ":scope ", when the argument to :has() is a mangled selector, will yield the he same results. @gmarinov thank you for your help and suggestions. Your comments are welcome too and much appreciated. |
i think indeed, |
For the Lines 1023 to 1025 in 0094625
Not sure how to make it work with your recent changes, but if we're working off of the linked commit, the fix could be something like below source = 'if(' + (referenceElement ? 's.match("' + referenceElement.replace(/\x22/g, '\\"') + '",e) && ' : '') + 'e.querySelector("'+ expr.replace(/\x22/g, '\\"') +'")){' + source + '}'; That gets us passing results for a good chunk of the has-basic test from web platform tests. I've been working on this problem myself and adding I manually pattern match on the relative selector if present and then change the behavior. This works for simple relative selectors, but more complicated ones don't work properly since they aren't established in the right context. I'm not sure what the best approach to make a fully-working version is, but my change would work with most common scenarios for relative selector lists. Test results |
@KindaOK I am trying to add a local WPT testing to make it easy for other developer to test and suggest changes for the :has() pseudo-class. Originally the :has() pseudo-class was not supported since this selectors implementation was written in between 2014 and 2016 and at that time neither :scope nor :has() was part of the w3 specifications. Actually the previous selector engine implementation was named "nwmatcher" and included a similar partial implementation of mangled selectors resolution see here by adding left/right context to mangled selector strings: https://github.com/dperini/nwmatcher/blob/master/src/modules/nwmatcher-shortcuts.js this "shortcut" module was added about 12 years ago to the "nwmatcher" selector engine project but might still be useful in the current context to make the implementation compatible with the new specifications. I will try to keep this conversation updated until we can ship these new resolver, maybe not yet fully completed but still very useful looking to other developers interest. Again, your work and help is much appreciated. |
@KindaOK |
@dperini Thanks for the response. I've pushed changes to my fork that get me the following test results. I took a look at your shortcut matcher, but the problem with it is that it changes the DOM by adding an The only correct solution that I can think of at the moment would be to use something like |
@KindaOK |
@dperini My thought was to not use Using The same approach with I need to try some POCs to see if any of these could actually work now that I'm writing this down because my thoughts are not seeming promising. |
@dperini So it looks like the Chrome team did some work on It inspired some experimentation, and I've submitted a draft PR #131 to fix |
@KindaOK great help and info above. Thank you for your time. Hmm ... Rereading the above I am not sure to be able to explain well enough such complexity in English. |
@KindaOK ....
this is very helpful in nwsapi. ;-) |
I found two particular use cases of the
:has
selector, which work fine in modern browsers but nwsapi throws an error:div:has(>div)
results in'>div' is not a valid selector
(so having>
at the start of the subselector string is treated as invalid):has(div)
results in'' is not a valid selector
(so having:has
at the start of the selector string seems to result in it being parsed as empty)I believe the selectors above are valid and should be supported, am I wrong?
I should say I'm using version 2.2.12
The text was updated successfully, but these errors were encountered: