Skip to content

Commit 6193772

Browse files
committed
fix: Improve test performance
1 parent d9f84d7 commit 6193772

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

packages/blockly/core/css.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function register(cssContent: string) {
1919
if (typeof window === 'undefined' || !window.CSSStyleSheet) return;
2020

2121
const sheet = new CSSStyleSheet();
22-
sheet.replaceSync(cssContent);
22+
sheet.replace(cssContent);
2323
registeredStyleSheets.push(sheet);
2424
}
2525

@@ -40,7 +40,7 @@ export function inject(
4040
hasCss: boolean,
4141
pathToMedia: string,
4242
) {
43-
if (!hasCss) {
43+
if (!hasCss || typeof window === 'undefined' || !window.CSSStyleSheet) {
4444
return;
4545
}
4646

@@ -54,7 +54,7 @@ export function inject(
5454
const cssContent = content.replace(/<<<PATH>>>/g, mediaPath);
5555

5656
const sheet = new CSSStyleSheet();
57-
sheet.replaceSync(cssContent);
57+
sheet.replace(cssContent);
5858
root.adoptedStyleSheets.push(sheet);
5959

6060
registeredStyleSheets.forEach((sheet) => root.adoptedStyleSheets.push(sheet));

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ export function isNotch(shape: Shape): shape is Notch {
116116
);
117117
}
118118

119+
const injectionSites = new WeakSet<Document | ShadowRoot>();
120+
119121
/**
120122
* An object that provides constants for rendering blocks.
121123
*/
@@ -1124,11 +1126,18 @@ export class ConstantProvider {
11241126
* @param selector The CSS selector to interpolate into the stylesheet.
11251127
*/
11261128
protected injectCSS_(root: Document | ShadowRoot, selector: string) {
1127-
if (typeof window === 'undefined' || !window.CSSStyleSheet) return;
1129+
if (
1130+
typeof window === 'undefined' ||
1131+
!window.CSSStyleSheet ||
1132+
injectionSites.has(root)
1133+
) {
1134+
return;
1135+
}
11281136

11291137
const sheet = new CSSStyleSheet();
1130-
sheet.replaceSync(this.getCSS_(selector).join('\n'));
1138+
sheet.replace(this.getCSS_(selector).join('\n'));
11311139
root.adoptedStyleSheets.push(sheet);
1140+
injectionSites.add(root);
11321141
}
11331142

11341143
/**

0 commit comments

Comments
 (0)