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

composedPath is incorrect for composed bubbling events originating from HTMLAnchorElement #709

Closed
romansp opened this issue Feb 1, 2023 · 1 comment · Fixed by #710
Closed
Labels
bug Something isn't working

Comments

@romansp
Copy link
Contributor

romansp commented Feb 1, 2023

Describe the bug
There's an issue where Event.composedPath will be constructed incorrectly if event.target is HTMLAnchorElement with href attribute being set.

To Reproduce
Steps to reproduce the behavior:

  1. Create an element with href attribute set to a valid domain, e.g. https://example.com and it attach to body.
  2. Add event listener for created element, e.g. click.
  3. Trigger click event on this element. Event should have both bubbles and composed set to true.
  4. Inspect value of event.composedPath() inside click event handler.

Expected behavior
Composed path should be the following array: [HTMLAnchorElement, document.body, document.documentElement, document, window].

Additional context
Looks like composedPath checks eventTarget.host to detect IShadowRoot boundary. Unfortunately HTMLAnchorElement also has host property which breaks while loop through parent nodes of the event target.

if (this.bubbles) {
if (this.composed && (<IShadowRoot>eventTarget).host) {
eventTarget = (<IShadowRoot>eventTarget).host;
} else if ((<INode>(<unknown>this.target)).ownerDocument === eventTarget) {
eventTarget = (<INode>(<unknown>this.target)).ownerDocument.defaultView;
} else {
eventTarget = (<INode>(<unknown>eventTarget)).parentNode || null;
}

@romansp romansp added the bug Something isn't working label Feb 1, 2023
romansp added a commit to romansp/happy-dom that referenced this issue Feb 1, 2023
romansp added a commit to romansp/happy-dom that referenced this issue Feb 1, 2023
capricorn86 added a commit to romansp/happy-dom that referenced this issue Feb 2, 2023
…ot in more places where the host property is used.
capricorn86 added a commit that referenced this issue Feb 2, 2023
…-element

#709@patch: Properly detect `ShadowRoot` boundary when constructing `composedPath`
@capricorn86
Copy link
Owner

Thanks again for your contribution @romansp! 🙂

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v8.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants