Skip to content

Commit 1a73393

Browse files
authored
fix: Make ShadowRoot checks more robust (#9988)
1 parent ba0c27c commit 1a73393

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

packages/blockly/core/css.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ export function inject(
5555
// stylesheet declared later wins by document order. Style elements appended
5656
// to the light DOM don't apply inside shadow roots, so for the shadow DOM
5757
// case we prepend the style element to the shadow root itself.
58-
(root instanceof ShadowRoot ? root : document.head).prepend(styleEl);
58+
(typeof globalThis.ShadowRoot !== 'undefined' && root instanceof ShadowRoot
59+
? root
60+
: document.head
61+
).prepend(styleEl);
5962
}
6063

6164
/**

packages/blockly/core/renderers/common/constants.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,10 @@ export class ConstantProvider {
11341134
styleEl.textContent = this.getCSS_(selector).join('\n');
11351135
// See css.ts inject() for the rationale on prepending and shadow root
11361136
// handling.
1137-
(root instanceof ShadowRoot ? root : document.head).prepend(styleEl);
1137+
(typeof globalThis.ShadowRoot !== 'undefined' && root instanceof ShadowRoot
1138+
? root
1139+
: document.head
1140+
).prepend(styleEl);
11381141

11391142
const sitesForSelector =
11401143
injectionSites.get(selector) ?? new WeakSet<Document | ShadowRoot>();

0 commit comments

Comments
 (0)