Skip to content

Commit 610e2a3

Browse files
committed
Element.slot does not ensure Element is slotted
Always read the spec, not MDN.
1 parent 6bead16 commit 610e2a3

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

lib/cssom/CSSStyleDeclaration-impl.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,33 @@ import { isFailure, isOmitted } from '../utils/value.js'
66
import { serializeDeclarationBlock, serializeValue } from '../serialize.js'
77
import expandShorthandDeclaration from '../parse/shorthand.js'
88
import { getResolvedValue } from '../resolve.js'
9+
import { isOfType } from '../utils/dom/element.js'
10+
import { iterate } from '../utils/dom/collection.js'
911
import logical from '../properties/logical.js'
1012
import properties from '../properties/definitions.js'
1113
import shorthands from '../properties/shorthands.js'
1214
import { toLowerCase } from '../utils/string.js'
1315

16+
/**
17+
* @param {Element} element
18+
* @returns {boolean}
19+
*/
20+
function hasResolvedStyle(element) {
21+
if (!element.isConnected) {
22+
return false
23+
}
24+
const shadowRoot = element.parentElement?.shadowRoot
25+
if (shadowRoot) {
26+
for (const node of iterate(shadowRoot.childNodes)) {
27+
if (isOfType(node, 'slot') && node.assignedNodes().some(slotted => slotted === element)) {
28+
return true
29+
}
30+
}
31+
return false
32+
}
33+
return true
34+
}
35+
1436
/**
1537
* @param {object} declaration
1638
* @param {object[]} declarations
@@ -173,7 +195,7 @@ export default class CSSStyleDeclarationImpl {
173195
return ''
174196
}
175197
if (this._computed) {
176-
if (!this._ownerNode.isConnected || (!this._ownerNode.slot && this._ownerNode.parentElement?.shadowRoot)) {
198+
if (!hasResolvedStyle(this._ownerNode)) {
177199
return ''
178200
}
179201
if (shorthands.has(name)) {

0 commit comments

Comments
 (0)