@@ -599,8 +599,8 @@ class NoneEncapsulationDomRenderer extends DefaultDomRenderer2 {
599599 applyStyles ( styleRoot : StyleRoot ) : void {
600600 // TODO: Apply styles on legacy shadow root creation afterwards?
601601
602- const isShadowRoot = styleRoot instanceof ShadowRoot ;
603- const isIsolatedShadowRoot = isShadowRoot && ! allLegacyShadowRoots . has ( styleRoot as ShadowRoot ) ;
602+ const isShadowRoot = isShadowRootInstance ( styleRoot ) ;
603+ const isIsolatedShadowRoot = isShadowRoot && ! allLegacyShadowRoots . has ( styleRoot ) ;
604604 if ( isIsolatedShadowRoot ) {
605605 // For isolated shadow roots, we limit to the one usage.
606606 this . sharedStylesHost . addStyles ( styleRoot , this . styles , this . styleUrls ) ;
@@ -623,9 +623,8 @@ class NoneEncapsulationDomRenderer extends DefaultDomRenderer2 {
623623
624624 // TODO: Problematic?
625625 if ( allLeavingAnimations . size === 0 ) {
626- const isShadowRoot = styleRoot instanceof ShadowRoot ;
627- const isIsolatedShadowRoot =
628- isShadowRoot && ! allLegacyShadowRoots . has ( styleRoot as ShadowRoot ) ;
626+ const isShadowRoot = isShadowRootInstance ( styleRoot ) ;
627+ const isIsolatedShadowRoot = isShadowRoot && ! allLegacyShadowRoots . has ( styleRoot ) ;
629628 if ( isIsolatedShadowRoot ) {
630629 // For isolated shadow roots, we limit to the one usage.
631630 this . sharedStylesHost . removeStyles ( styleRoot , this . styles , this . styleUrls ) ;
@@ -688,3 +687,10 @@ class EmulatedEncapsulationDomRenderer2 extends NoneEncapsulationDomRenderer {
688687 return el ;
689688 }
690689}
690+
691+ /**
692+ * In some runtimes (e.g. server-side with Domino or node unit tests), ShadowRoot may not be defined.
693+ */
694+ function isShadowRootInstance ( obj : unknown ) : obj is ShadowRoot {
695+ return typeof ShadowRoot !== 'undefined' && obj instanceof ShadowRoot ;
696+ }
0 commit comments