Skip to content

Commit d53277a

Browse files
committed
Do not collect declared values in shadow subtrees
Follow up to a57cee4. The algorithm to match a selector against a tree requires considering elements in subtrees when no scope is defined, but only a few pseudo-elements can match them at the moment, and they cannot match elements in the selector tree. The subtree elements do not need to be included in the candidate elements. The root of the element owning the style sheet cannot be defined as a scoping root to fix this, because its selectors would be interpreted as scoped: `html` would be interpreted as `:scope html` and match nothing. This commit explicitly set a flag to skip shadow subtrees for the moment, until the reason for this default behavior is clarified.
1 parent 747f88b commit d53277a

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

lib/match/selector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ function findPreviousSibling({ previousElementSibling }, predicate) {
10961096
* @yields {Element}
10971097
*/
10981098
function* traverse(tree, options = {}, inclusive = options.scopes?.inclusive) {
1099-
const { scopes, excludeShadowTrees } = options
1099+
const { scopes, excludeSubtrees } = options
11001100
if (scopes?.limits?.includes(tree)) {
11011101
return
11021102
}
@@ -1112,7 +1112,7 @@ function* traverse(tree, options = {}, inclusive = options.scopes?.inclusive) {
11121112
for (const element of children) {
11131113
yield* traverse(element, options, true)
11141114
}
1115-
if (shadowRoot && !excludeShadowTrees) {
1115+
if (shadowRoot && !excludeSubtrees) {
11161116
for (const element of shadowRoot.children) {
11171117
yield* traverse(element, {}, true)
11181118
}

lib/resolve.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ function getStyleSheetListDeclarations(property, element, list, context) {
284284
*/
285285
function createContext(tree, origin) {
286286
return {
287+
excludeSubtrees: true,
287288
layers: [],
288289
namespaces: new Map,
289290
origin,

0 commit comments

Comments
 (0)