bodyContains: Walk up the nested shadow root chain to check if the body contains the element#2434
Open
andrejota wants to merge 1 commit into
Open
bodyContains: Walk up the nested shadow root chain to check if the body contains the element#2434andrejota wants to merge 1 commit into
andrejota wants to merge 1 commit into
Conversation
…ement. bodyContains() currently assumes that shadow root host element is always contained in the root body. This change walks up the chain of shadow roots to find the topmost host element and verify for that one if it exists in the root body.
Contributor
Collaborator
|
Hey, following up late on this @andrejota, could you fix your code's formatting ( Ideally, adding a test case would greatly help to identify & ensure the issue is indeed fixed and doesn't get broken again in the future |
Contributor
Author
Yup, happy to do it. On it. |
Collaborator
|
Hey @andrejota , we had a recent PR that addressed the nested shadow roots issue, see #3034 (released alongside htmx 2.0.4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
bodyContains()currently assumes that shadow root host element is always contained in the root body. That may not be the case and I experienced problem when nesting web components that rely on HTMX (e.g.hx-get. This change walks up the chain of shadow roots to find the topmost host element and verify for that one if it exists in the root body.I did not find a corresponding issue, but I did find an older related issue: #718. I didn't file a new issue as it looks like a fairly straight-forward fix for what I think is just a bug.
Testing
I ran this with my test site which uses nested web components ('open' shadow DOM) combined with HTMX. This change enabled
hx-get="..."withhx-target="click"to work for me.Checklist
masterfor website changes,devforsource changes)
approved via an issue
npm run test) and verified that it succeeded