-
Notifications
You must be signed in to change notification settings - Fork 39
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
:scope selector direct children query is not working because of tag name resolution strategy #63
Comments
@sasensi
Thank you in advance for your contribution and for reporting the bug. |
Hey @dperini, thank you for you solution proposal, I'll try it asap and get back to you. |
@dperini, I looked at your solution and I also looked more closely at the codebase. As an example here's a simple way of solving this specific case outside of the library: const rootElement = dom.querySelector(rootElementTagName);
const queryResult = rootElement.querySelectorAll(':scope > div').filter((it) => it.parentElement === rootElement); Do you think that this kind of strategy could be included into the library ? |
@sasensi |
Hi, Diego. Here is a link to the description of the
So your solution, given above and implemented in the library, is wrong. It gives the correct result only if the element has an id, otherwise it refers to all similar elements (that have the same tag and class), which is incorrect. |
@Perfectoff @sasensi |
This was originally reported as part of the
jsdom
repo here.I decided to try to fix it (because I had the exact same issue) and was able to track down the issue until here.
So here's the case: given the following DOM tree:
Getting a reference to the root
<div>
and doing the following query:Doesn't only return the 2 expected "ok" divs but also the "ko" one.
Here's the full reproduction code allowing to easily switch between an ok and a ko case:
And here's a fiddle hosting it.
I don't know this library codebase well, but I investigated a bit and I have the feeling that this is caused by the fact that this pattern :
:scope > div
is turned into a more generic one :div > div
which is solved using a parent tag name resolution strategy and ultimately returns all the element globally matching this pattern:div > div
, somewhat ignoring the element context.I hope that this can help saving time to fix it.
The text was updated successfully, but these errors were encountered: