@@ -242,8 +242,8 @@ export class DomRendererFactory2 implements RendererFactory2, OnDestroy {
242242 ngZone ,
243243 platformIsServer ,
244244 tracingService ,
245- undefined ,
246245 this . styleScopeService ,
246+ undefined ,
247247 ) ;
248248 break ;
249249 }
@@ -503,7 +503,7 @@ function isTemplateNode(node: any): node is HTMLTemplateElement {
503503}
504504
505505class ShadowDomRenderer extends DefaultDomRenderer2 {
506- private shadowRoot : ShadowRoot | HTMLElement ;
506+ private shadowRoot : ShadowRoot ;
507507
508508 constructor (
509509 eventManager : EventManager ,
@@ -515,12 +515,12 @@ class ShadowDomRenderer extends DefaultDomRenderer2 {
515515 platformIsServer : boolean ,
516516 tracingService : TracingService < TracingSnapshot > | null ,
517517 private sharedStylesHost : SharedStylesHost ,
518- private styleScopeService ? : IsolatedStyleScopeService ,
518+ private styleScopeService : IsolatedStyleScopeService ,
519519 ) {
520520 super ( eventManager , doc , ngZone , platformIsServer , tracingService ) ;
521521
522522 // Only create shadow root in browser environments
523- if ( typeof ShadowRoot !== 'undefined' && ! platformIsServer ) {
523+ if ( ! platformIsServer ) {
524524 this . shadowRoot = ( hostEl as HTMLElement ) . attachShadow ( { mode : 'open' } ) ;
525525 } else {
526526 // In SSR or environments without shadow DOM support, throw
@@ -533,12 +533,7 @@ class ShadowDomRenderer extends DefaultDomRenderer2 {
533533 const isIsolated = component . encapsulation === ViewEncapsulation . IsolatedShadowDom ;
534534
535535 // Register shadow root with StyleScopeService for style targeting (only if service available and in browser)
536- if (
537- this . styleScopeService &&
538- typeof ShadowRoot !== 'undefined' &&
539- ! platformIsServer &&
540- this . shadowRoot instanceof ShadowRoot
541- ) {
536+ if ( this . styleScopeService ) {
542537 if ( isIsolated ) {
543538 this . styleScopeService . registerIsolatedShadowRoot ( this . shadowRoot ) ;
544539 this . sharedStylesHost . addShadowRoot ( this . shadowRoot ) ;
@@ -555,13 +550,7 @@ class ShadowDomRenderer extends DefaultDomRenderer2 {
555550 styles = addBaseHrefToCssSourceMap ( baseHref , styles ) ;
556551 }
557552
558- if (
559- isIsolated &&
560- this . styleScopeService &&
561- typeof ShadowRoot !== 'undefined' &&
562- ! platformIsServer &&
563- this . shadowRoot instanceof ShadowRoot
564- ) {
553+ if ( isIsolated && ! platformIsServer ) {
565554 // For IsolatedShadowDom, use SharedStylesHost with shadowRoot targeting
566555 this . sharedStylesHost . addStyles ( styles , component . getExternalStyles ?.( ) , this . shadowRoot ) ;
567556 } else {
@@ -620,12 +609,7 @@ class ShadowDomRenderer extends DefaultDomRenderer2 {
620609
621610 override destroy ( ) {
622611 // Query the service to determine what type this shadow root is (only if service available and in browser)
623- if (
624- ! this . platformIsServer &&
625- this . styleScopeService &&
626- typeof ShadowRoot !== 'undefined' &&
627- this . shadowRoot instanceof ShadowRoot
628- ) {
612+ if ( ! this . platformIsServer ) {
629613 if ( this . styleScopeService . isIsolatedShadowRoot ( this . shadowRoot ) ) {
630614 this . styleScopeService . deregisterIsolatedShadowRoot ( this . shadowRoot ) ;
631615 this . sharedStylesHost . removeShadowRoot ( this . shadowRoot ) ;
@@ -650,8 +634,8 @@ class NoneEncapsulationDomRenderer extends DefaultDomRenderer2 {
650634 ngZone : NgZone ,
651635 platformIsServer : boolean ,
652636 tracingService : TracingService < TracingSnapshot > | null ,
637+ protected styleScopeService : IsolatedStyleScopeService ,
653638 compId ?: string ,
654- protected styleScopeService ?: IsolatedStyleScopeService ,
655639 ) {
656640 super ( eventManager , doc , ngZone , platformIsServer , tracingService ) ;
657641 let styles = component . styles ;
@@ -665,9 +649,9 @@ class NoneEncapsulationDomRenderer extends DefaultDomRenderer2 {
665649 this . styleUrls = component . getExternalStyles ?.( compId ) ;
666650 }
667651
668- applyStyles ( element ? : HTMLElement ) : void {
652+ applyStyles ( element : HTMLElement ) : void {
669653 // Check if we should target specific shadow roots (only if service and element available)
670- if ( element && this . styleScopeService && ! this . platformIsServer ) {
654+ if ( element && ! this . platformIsServer ) {
671655 const targetShadowRoots = this . styleScopeService . determineStyleTargets ( element ) ;
672656 if ( targetShadowRoots . length > 0 ) {
673657 for ( const shadowRoot of targetShadowRoots ) {
@@ -705,7 +689,7 @@ class EmulatedEncapsulationDomRenderer2 extends NoneEncapsulationDomRenderer {
705689 ngZone : NgZone ,
706690 platformIsServer : boolean ,
707691 tracingService : TracingService < TracingSnapshot > | null ,
708- styleScopeService ? : IsolatedStyleScopeService ,
692+ styleScopeService : IsolatedStyleScopeService ,
709693 ) {
710694 const compId = appId + '-' + component . id ;
711695 super (
@@ -717,19 +701,17 @@ class EmulatedEncapsulationDomRenderer2 extends NoneEncapsulationDomRenderer {
717701 ngZone ,
718702 platformIsServer ,
719703 tracingService ,
720- compId ,
721704 styleScopeService ,
705+ compId ,
722706 ) ;
723707 this . contentAttr = shimContentAttribute ( compId ) ;
724708 this . hostAttr = shimHostAttribute ( compId ) ;
725709 }
726710
727711 applyToHost ( element : HTMLElement ) : void {
728- // Set host attribute first
729- this . setAttribute ( element , this . hostAttr , '' ) ;
730-
731712 // Use inherited applyStyles method to handle shadow root targeting and fallback
732713 this . applyStyles ( element ) ;
714+ this . setAttribute ( element , this . hostAttr , '' ) ;
733715 }
734716
735717 override createElement ( parent : any , name : string ) : Element {
0 commit comments