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

Current scoping root used when matching "selector_matches" doesn't work well for shadow tree links #240

Closed
a4sriniv opened this issue Jan 18, 2023 · 2 comments · Fixed by #241

Comments

@a4sriniv
Copy link
Contributor

Currently, when matching a selector against a link while processing document rule CSS selector predicates, we use the link's document as a scoping root. This would mean that elements inside other tree scopes (including shadow trees attached to the document) would always be excluded when matching these selectors and would never match.

(From spec, "When a selector is scoped, it matches an element only if the element is a descendant of the scoping root.").

I think we should be using the link's root as the scoping root instead. So for links inside a shadow tree, we would use the shadow root as the scoping root.

@jeremyroman
Copy link
Collaborator

Hrm, interesting. It's always been a little awkward because it seems clearly useful to encompass shadow DOM, and yet CSS selectors generally don't pierce that boundary.

  1. What, if anything, is the difference between scoping to the element's root and not scoping here? (I assume whether :scope matches is one thing, but is that it?)
  2. Are there drawbacks to allowing you to apply selectors inside the shadow roots like this? Should we instead consider "scoped" speculation rules? (My reservation about that idea is that it somewhat defeats the purpose, though.)

I suspect your resolution is correct, but wouldn't mind a second opinion from DOM folks if you haven't already asked.

@a4sriniv
Copy link
Contributor Author

  1. What, if anything, is the difference between scoping to the element's root and not scoping here? (I assume whether :scope matches is one thing, but is that it?)

AFAICT, the only difference is that :scope would only match against the document if a scoping root is not specified - and so a selector like :scope .foo would never match an element inside a shadow tree.

(From https://drafts.csswg.org/selectors-4/#the-scope-pseudo: "If there is no scoping root then :scope represents the root of the document (equivalent to :root)")

domenic pushed a commit that referenced this issue Nov 14, 2023
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 22, 2023
See WICG/nav-speculation#240. Using
TreeRoot() as the scoping root allows links inside shadow trees to be
matched.

Bug: 1371522
Change-Id: If830a8d4883bf9c8a769a74915f6a57a3eaa01eb
aarongable pushed a commit to chromium/chromium that referenced this issue Nov 22, 2023
See WICG/nav-speculation#240. Using
TreeRoot() as the scoping root allows links inside shadow trees to be
matched.

Bug: 1371522
Change-Id: If830a8d4883bf9c8a769a74915f6a57a3eaa01eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5054502
Reviewed-by: Jeremy Roman <[email protected]>
Commit-Queue: Adithya Srinivasan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1228203}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 22, 2023
See WICG/nav-speculation#240. Using
TreeRoot() as the scoping root allows links inside shadow trees to be
matched.

Bug: 1371522
Change-Id: If830a8d4883bf9c8a769a74915f6a57a3eaa01eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5054502
Reviewed-by: Jeremy Roman <[email protected]>
Commit-Queue: Adithya Srinivasan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1228203}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 22, 2023
See WICG/nav-speculation#240. Using
TreeRoot() as the scoping root allows links inside shadow trees to be
matched.

Bug: 1371522
Change-Id: If830a8d4883bf9c8a769a74915f6a57a3eaa01eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5054502
Reviewed-by: Jeremy Roman <[email protected]>
Commit-Queue: Adithya Srinivasan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1228203}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Nov 30, 2023
…root, a=testonly

Automatic update from web-platform-tests
DocumentRules: Use tree root as scoping root

See WICG/nav-speculation#240. Using
TreeRoot() as the scoping root allows links inside shadow trees to be
matched.

Bug: 1371522
Change-Id: If830a8d4883bf9c8a769a74915f6a57a3eaa01eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5054502
Reviewed-by: Jeremy Roman <[email protected]>
Commit-Queue: Adithya Srinivasan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1228203}

--

wpt-commits: 7b64f598ab50ac42f769678ba1e9a5d56766645c
wpt-pr: 43312
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Nov 30, 2023
…root, a=testonly

Automatic update from web-platform-tests
DocumentRules: Use tree root as scoping root

See WICG/nav-speculation#240. Using
TreeRoot() as the scoping root allows links inside shadow trees to be
matched.

Bug: 1371522
Change-Id: If830a8d4883bf9c8a769a74915f6a57a3eaa01eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5054502
Reviewed-by: Jeremy Roman <[email protected]>
Commit-Queue: Adithya Srinivasan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1228203}

--

wpt-commits: 7b64f598ab50ac42f769678ba1e9a5d56766645c
wpt-pr: 43312
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Nov 30, 2023
…root, a=testonly

Automatic update from web-platform-tests
DocumentRules: Use tree root as scoping root

See WICG/nav-speculation#240. Using
TreeRoot() as the scoping root allows links inside shadow trees to be
matched.

Bug: 1371522
Change-Id: If830a8d4883bf9c8a769a74915f6a57a3eaa01eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5054502
Reviewed-by: Jeremy Roman <jbromanchromium.org>
Commit-Queue: Adithya Srinivasan <adithyaschromium.org>
Cr-Commit-Position: refs/heads/main{#1228203}

--

wpt-commits: 7b64f598ab50ac42f769678ba1e9a5d56766645c
wpt-pr: 43312

UltraBlame original commit: 1d0db6e7294f9eb89a4e512a3f26a95a884d3475
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Nov 30, 2023
…root, a=testonly

Automatic update from web-platform-tests
DocumentRules: Use tree root as scoping root

See WICG/nav-speculation#240. Using
TreeRoot() as the scoping root allows links inside shadow trees to be
matched.

Bug: 1371522
Change-Id: If830a8d4883bf9c8a769a74915f6a57a3eaa01eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5054502
Reviewed-by: Jeremy Roman <jbromanchromium.org>
Commit-Queue: Adithya Srinivasan <adithyaschromium.org>
Cr-Commit-Position: refs/heads/main{#1228203}

--

wpt-commits: 7b64f598ab50ac42f769678ba1e9a5d56766645c
wpt-pr: 43312

UltraBlame original commit: 1d0db6e7294f9eb89a4e512a3f26a95a884d3475
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Nov 30, 2023
…root, a=testonly

Automatic update from web-platform-tests
DocumentRules: Use tree root as scoping root

See WICG/nav-speculation#240. Using
TreeRoot() as the scoping root allows links inside shadow trees to be
matched.

Bug: 1371522
Change-Id: If830a8d4883bf9c8a769a74915f6a57a3eaa01eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5054502
Reviewed-by: Jeremy Roman <jbromanchromium.org>
Commit-Queue: Adithya Srinivasan <adithyaschromium.org>
Cr-Commit-Position: refs/heads/main{#1228203}

--

wpt-commits: 7b64f598ab50ac42f769678ba1e9a5d56766645c
wpt-pr: 43312

UltraBlame original commit: 1d0db6e7294f9eb89a4e512a3f26a95a884d3475
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 a pull request may close this issue.

2 participants