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

bodyContains: Walk up the nested shadow root chain to check if the body contains the element #2434

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,16 @@
* @returns {boolean}
*/
function bodyContains(elt) {
// IE Fix
const rootNode = elt.getRootNode && elt.getRootNode()
if (rootNode && rootNode instanceof window.ShadowRoot) {
return getDocument().body.contains(rootNode.host)
} else {
return getDocument().body.contains(elt)
// Shortcut for older browsers missing getRootNode() to avoid checking
// the condition on every iteration.
if (!elt.getRootNode) {
return getDocument().body.contains(elt);

Check failure on line 770 in src/htmx.js

View workflow job for this annotation

GitHub Actions / test_suite

Extra semicolon
}
// Escape from shadow root.
while (elt.getRootNode() instanceof window.ShadowRoot) {
elt = elt.getRootNode().host;

Check failure on line 774 in src/htmx.js

View workflow job for this annotation

GitHub Actions / test_suite

Extra semicolon
}
return getDocument().body.contains(elt);

Check failure on line 776 in src/htmx.js

View workflow job for this annotation

GitHub Actions / test_suite

Extra semicolon
}

/**
Expand Down