diff --git a/packages/platform-browser/src/dom/shared_styles_host.ts b/packages/platform-browser/src/dom/shared_styles_host.ts index 73e5e5cf37c3a..d31f905c43a03 100644 --- a/packages/platform-browser/src/dom/shared_styles_host.ts +++ b/packages/platform-browser/src/dom/shared_styles_host.ts @@ -139,6 +139,7 @@ export class SharedStylesHost implements OnDestroy { if (existingStyleElement) { return existingStyleElement; } + const styleNodesInDOM = this.styleNodesInDOM; const styleEl = styleNodesInDOM?.get(style); if (styleEl?.parentNode === host) { @@ -166,6 +167,8 @@ export class SharedStylesHost implements OnDestroy { styleEl.setAttribute(APP_ID_ATTRIBUTE_NAME, this.appId); } + host.appendChild(styleEl); + return styleEl; } } @@ -175,8 +178,6 @@ export class SharedStylesHost implements OnDestroy { const styleResult = styleRef.get(style)!; // This will always be defined in `changeUsageCount` const styleEl = this.getStyleElement(host, style, styleResult.elements); - host.appendChild(styleEl); - if (styleResult.usage === 0) { disableStylesheet(styleEl); } else {