Skip to content

Commit f4f815f

Browse files
fix(runtime): conditionally apply global styles using flag
1 parent fa2fd65 commit f4f815f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/utils/shadow-root.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BUILD } from '@app-data';
22
import { globalStyles } from '@app-globals';
3+
import { supportsConstructableStylesheets } from '@platform';
34
import { CMP_FLAGS } from '@utils';
45

56
import type * as d from '../declarations';
@@ -12,7 +13,13 @@ export function createShadowRoot(this: HTMLElement, cmpMeta: d.ComponentRuntimeM
1213
})
1314
: this.attachShadow({ mode: 'open' });
1415

15-
const sheet = new CSSStyleSheet();
16-
sheet.replaceSync(globalStyles);
17-
shadowRoot.adoptedStyleSheets.push(sheet);
16+
/**
17+
* If constructable stylesheets are supported, we can use them to
18+
* add the global styles to the shadow root.
19+
*/
20+
if (supportsConstructableStylesheets) {
21+
const sheet = new CSSStyleSheet();
22+
sheet.replaceSync(globalStyles);
23+
shadowRoot.adoptedStyleSheets.push(sheet);
24+
}
1825
}

0 commit comments

Comments
 (0)