Skip to content

Commit 3c945dc

Browse files
committed
Wrap base styles in a @layer on supported browsers
1 parent 5a6e98e commit 3c945dc

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/engine.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,11 @@ class StyleElementController extends NodeController<HTMLStyleElement> {
646646

647647
class GlobalStyleElementController extends NodeController<HTMLStyleElement> {
648648
connected(): void {
649-
this.node.innerHTML = `* { ${CUSTOM_PROPERTY_TYPE}: cq-normal; ${CUSTOM_PROPERTY_NAME}: cq-none; }`;
649+
const style = `* { ${CUSTOM_PROPERTY_TYPE}: cq-normal; ${CUSTOM_PROPERTY_NAME}: cq-none; }`;
650+
this.node.innerHTML =
651+
typeof (window as any).CSSLayerBlockRule === 'undefined'
652+
? style
653+
: `@layer cq-polyfill-${PER_RUN_UID} { ${style} }`;
650654
}
651655
}
652656

tests/@layer.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
}
88

99
@layer test-layer {
10+
#a {
11+
container-type: inline-size;
12+
}
13+
1014
@container (width > 0) {
1115
h1 {
1216
font-size: 20px;
1317
}
1418
}
1519
}
16-
17-
#a {
18-
container-type: inline-size;
19-
}
2020
</style>
2121
<div id="a">
2222
<h1>Ohai</h1>

0 commit comments

Comments
 (0)