Skip to content
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

Improve accuracy of :scope selector in the real world #131

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KindaOK
Copy link
Contributor

@KindaOK KindaOK commented Oct 28, 2024

Description

Currently, the :scope selector is just a syntactic transform of the :scope selector into the element's name, first class, and id. This sometimes works in real-world situations and generally well on the Web Platform Tests since many elements under test have ids, but in the real world, it causes inaccurate behavior. See fixed issues.

This change uses the Snapshot.from property since that appears to be the context for a given selector. This means that it should work correctly for :has since :has uses querySelector, which will update the context to be the node that it's called on. This could be problematic if :has changes to execute the querySelector on the parentElement, but I suppose that's a later problem.

One thing I'm not sure about is if the mode ternary is necessary. I copied that snippet from the :root pseudoclass and am not entirely sure why it needs to exist there.

Tests

Some wpt tests that were passing are now failing.
Element.closest with context node 'test4' and selector ':scope'
Element.closest with context node 'test4' and selector 'select > :scope'
Element.closest with context node 'test4' and selector ':has(> :scope)' (failing due to bug in :has)

Some of the has-argument-with-explicit-scope that were passing are now failing and vice versa, with 9/13 passing.

I do need some help fixing those since I'm struggling a bit. The previous implementation worked on them since it cheated by using element ids.

The test/scope tests are all passing still.

Should I add some of the reference cases that I used from the linked issues? Where would I add them as regression tests?

Fixed issues

nwsapi

#106 (classname escaping was never added)

jsdom

jsdom/jsdom#3067 (original issue for #63)
jsdom/jsdom#2998

Need to check if the `mode` ternary is actually necessary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant