capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.24k stars 194 forks source link

`el.shadowRoot?.querySelector(":host")` returns null with happy-dom after 13.8.5 #1313

Closed odanado closed 5 months ago

odanado commented 5 months ago

Describe the bug I found that when I create a custom element and run querySelector(":host") against shadowRoot, the return value is different depending on the version of happy-dom.

To Reproduce Steps to reproduce the behavior:

  1. git clone https://github.com/odan-sandbox/happy-dom-query-selector-with-lit-sandbox
  2. run npm i
  3. run node src/index.js

Expected behavior Expect non-null values to be returned for both happy-dom@13.8.4 and happy-dom@13.8.5.

Device:

capricorn86 commented 5 months ago

Thank you for reporting @odanado! :slightly_smiling_face:

I believe that the current behavior is correct, which is to always return null for the query selector ':host' as it is pseudo element selector, which is not possible to use together with querySelector().

When I run the example code in Chrome, I get the same result.

capricorn86 commented 5 months ago

I'm closing this now. Please re-open if your problem hasn't been solved based on the answer.

odanado commented 5 months ago

Thank you for a comment. I also checked the behavior in Chrome.

I use host property instead of :host.