Skip to content

Commit c47cec6

Browse files
authoredJul 5, 2022
fix(styles): ensure styles are applied before paint (#3452)
this commit fixes a bug where styles from a stencil component would not be applied prior to render. the issue involved stylesheet construction & application not blocking render, causing the component to be created without styles applied. this commit moves from the `replace` function to the `replaceSync` function to properly await the call STENCIL-433: Stabilize Browserstack CI Tests
1 parent a6e0141 commit c47cec6

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed
 

‎src/client/client-window.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ export const supportsListenerOptions = /*@__PURE__*/ (() => {
5252

5353
export const promiseResolve = (v?: any) => Promise.resolve(v);
5454

55-
export const supportsConstructibleStylesheets = BUILD.constructableCSS
55+
export const supportsConstructableStylesheets = BUILD.constructableCSS
5656
? /*@__PURE__*/ (() => {
5757
try {
5858
new CSSStyleSheet();
59-
return typeof new CSSStyleSheet().replace === 'function';
59+
return typeof new CSSStyleSheet().replaceSync === 'function';
6060
} catch (e) {}
6161
return false;
6262
})()

‎src/hydrate/platform/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const supportsShadow = false;
121121

122122
export const supportsListenerOptions = false;
123123

124-
export const supportsConstructibleStylesheets = false;
124+
export const supportsConstructableStylesheets = false;
125125

126126
const hostRefs: WeakMap<d.RuntimeRef, d.HostRef> = new WeakMap();
127127

‎src/runtime/styles.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import type * as d from '../declarations';
22
import { BUILD } from '@app-data';
33
import { CMP_FLAGS } from '@utils';
4-
import { doc, plt, styles, supportsConstructibleStylesheets, supportsShadow } from '@platform';
4+
import { doc, plt, styles, supportsConstructableStylesheets, supportsShadow } from '@platform';
55
import { HYDRATED_STYLE_ID, NODE_TYPE } from './runtime-constants';
66
import { createTime } from './profile';
77

88
const rootAppliedStyles: d.RootAppliedStyleMap = /*@__PURE__*/ new WeakMap();
99

1010
export const registerStyle = (scopeId: string, cssText: string, allowCS: boolean) => {
1111
let style = styles.get(scopeId);
12-
if (supportsConstructibleStylesheets && allowCS) {
12+
if (supportsConstructableStylesheets && allowCS) {
1313
style = (style || new CSSStyleSheet()) as CSSStyleSheet;
14-
style.replace(cssText);
14+
if (typeof style === 'string') {
15+
style = cssText;
16+
} else {
17+
style.replaceSync(cssText);
18+
}
1519
} else {
1620
style = cssText;
1721
}

‎src/testing/platform/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export {
1313
resetPlatform,
1414
startAutoApplyChanges,
1515
stopAutoApplyChanges,
16-
supportsConstructibleStylesheets,
16+
supportsConstructableStylesheets,
1717
supportsListenerOptions,
1818
setSupportsShadowDom,
1919
} from './testing-platform';

‎src/testing/platform/testing-platform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const setPlatformHelpers = (helpers: {
2727

2828
export const cssVarShim: d.CssVarShim = false as any;
2929
export const supportsListenerOptions = true;
30-
export const supportsConstructibleStylesheets = false;
30+
export const supportsConstructableStylesheets = false;
3131
export const Context: any = {};
3232

3333
export const setSupportsShadowDom = (supports: boolean) => {

0 commit comments

Comments
 (0)
Please sign in to comment.