Skip to content

Commit 5ab508f

Browse files
authored
Make bodyContains return true for nested shadow roots (#3034)
This fixes an issues in which `bodyContains()` would incorrectly return false for nested shadow roots.
1 parent c24fb71 commit 5ab508f

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/htmx.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,17 +754,14 @@ var htmx = (function() {
754754
}
755755

756756
/**
757+
* Checks whether the element is in the document (includes shadow roots).
758+
* This function this is a slight misnomer; it will return true even for elements in the head.
759+
*
757760
* @param {Node} elt
758761
* @returns {boolean}
759762
*/
760763
function bodyContains(elt) {
761-
// IE Fix
762-
const rootNode = elt.getRootNode && elt.getRootNode()
763-
if (rootNode && rootNode instanceof window.ShadowRoot) {
764-
return getDocument().body.contains(rootNode.host)
765-
} else {
766-
return getDocument().body.contains(elt)
767-
}
764+
return elt.getRootNode({ composed: true }) === document
768765
}
769766

770767
/**

0 commit comments

Comments
 (0)