Skip to content

Dynamic styles don't work in the shadow root #55

@robb-j

Description

@robb-j

addGlobalStyle could be refactored to add to the current node's root node, rather than defaulting to the document.

export function addGlobalStyle(id: string, style: string, node: Element) {
  const rootNode = node.getRootNode()

  if (rootNode.getElementById(id)) return

  const elem = document.createElement('style')
  elem.id = id
  elem.innerHTML = style

  if (rootNode instanceof Document) {
    rootNode.head.appendChild(elem)
  } else {
    rootNode.head.appendChild(elem)
  }
}

That should work, I'm not sure if this is useful. Would it only apply when used client-side and/or does it make sense in the desired best usage (static generation)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions