Skip to content

Commit ec12b99

Browse files
committed
Fix for :global(...) styles in custom elements. Close #2969
1 parent 1ef7601 commit ec12b99

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/compiler/compile/render_dom/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ export default function dom(
442442
constructor(options) {
443443
super();
444444
445-
${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
445+
${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\').replace(/:global\(([-.\w]+)\)/g, '$1')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
446446
447447
@init(this, { target: this.shadowRoot }, ${definition}, ${has_create_fragment ? 'create_fragment': 'null'}, ${not_equal}, ${prop_indexes}, ${dirty});
448448
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<svelte:options tag="custom-element"/>
2+
3+
<style>
4+
:global(p.active) {
5+
color:rgb(128, 128, 128);
6+
}
7+
</style>
8+
9+
<p></p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as assert from 'assert';
2+
import CustomElement from './main.svelte';
3+
4+
export default function (target) {
5+
new CustomElement({
6+
target
7+
});
8+
9+
const style = target.querySelector('custom-element').shadowRoot.querySelector('style');
10+
11+
assert.equal(style.textContent, 'p.active{color:rgb(128, 128, 128)}');
12+
}

0 commit comments

Comments
 (0)