Skip to content

Commit 1eeaba9

Browse files
committed
fixup! fix(core): apply and remove stylesheets based on containing StyleRoot
1 parent 1365171 commit 1eeaba9

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

packages/core/test/acceptance/hmr_spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ import {compileComponent} from '../../src/render3/jit/directive';
3838
import {angularCoreEnv} from '../../src/render3/jit/environment';
3939
import {clearTranslations, loadTranslations} from '@angular/localize';
4040
import {computeMsgId} from '@angular/compiler';
41-
import {EVENT_MANAGER_PLUGINS} from '@angular/platform-browser';
41+
import {
42+
EVENT_MANAGER_PLUGINS,
43+
ɵSharedStylesHost as SharedStylesHost,
44+
} from '@angular/platform-browser';
4245
import {ComponentType} from '../../src/render3';
43-
import {ɵSharedStylesHost as SharedStylesHost} from '@angular/platform-browser';
4446
import {isNode} from '@angular/private/testing';
4547

4648
describe('hot module replacement', () => {

packages/core/test/render3/util/view_traversal_util_spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*!
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
19
import {NgComponentOutlet} from '@angular/common';
210
import {By} from '@angular/platform-browser';
311
import {Component} from '../../../src/core';

packages/platform-browser/src/dom/dom_renderer.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)