@@ -25,10 +25,12 @@ export default class CSSRuntime extends MasterCSS {
2525 public baseConfig ?: Config
2626 ) {
2727 super ( customConfig , baseConfig )
28- if ( this . root instanceof Document || this . root instanceof HTMLDocument ) {
29- this . root . defaultView ! . globalThis . cssRuntime = this
30- this . container = this . root . head
31- this . host = this . root . documentElement
28+ // Do not use instanceof here, because it will not work
29+ const rootConstructorName = root ?. constructor . name
30+ if ( rootConstructorName === 'HTMLDocument' || rootConstructorName === 'Document' ) {
31+ ( this . root as Document ) . defaultView ! . globalThis . cssRuntime = this
32+ this . container = ( this . root as Document ) . head
33+ this . host = ( this . root as Document ) . documentElement
3234 } else {
3335 this . container = this . root as CSSRuntime [ 'container' ]
3436 this . host = ( this . root as ShadowRoot ) . host
@@ -69,12 +71,7 @@ export default class CSSRuntime extends MasterCSS {
6971 if ( ! count ) connectedNames . add ( className )
7072 this . classCounts . set ( className , count + 1 )
7173 }
72-
73- const rootEl = this . root instanceof Document || this . root instanceof HTMLDocument
74- ? this . root
75- : this . container
76-
77- const elementsWithClass = rootEl . querySelectorAll ( '[class]' )
74+ const elementsWithClass = this . root . querySelectorAll ( '[class]' )
7875 elementsWithClass . forEach ( el => {
7976 const clsList = el . classList
8077 if ( clsList ) {
0 commit comments