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

:host pseudo-class does not apply styles when used in shadow roots #3661

Open
nolanlawson opened this issue Jan 16, 2024 · 0 comments
Open

Comments

@nolanlawson
Copy link

Basic info:

  • Node.js version: 20.9.0
  • jsdom version: 23.2.0

Minimal reproduction case

const jsdom = require("jsdom")
const { JSDOM } = jsdom

const dom = new JSDOM(`<!DOCTYPE html>`)
const { window } = dom
const { document } = window

window.customElements.define('x-foo', class extends window.HTMLElement {
  constructor() {
    super()
    const style = document.createElement('style')
    style.textContent = ':host { color: red }'
    this.attachShadow({ mode: 'open' }).appendChild(style)
  }
})

const elm = document.createElement('x-foo')
document.body.appendChild(elm)

console.log(window.getComputedStyle(elm).color) // should log rgb(255, 0, 0)

In JSDOM, this code will log the empty string.

How does similar code behave in browsers?

CodePen repro

In the browser, the code above logs rgb(255, 0, 0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant