Skip to content

Commit 536be64

Browse files
trueadmRich-Harris
andauthored
fix: ensure custom element styles append correctly during prod (#12777)
* fix: ensure custom element styles append correctly during prod * fix * fix * fix * feedback * only add third argument for custom elements --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 1a3dbda commit 536be64

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

.changeset/hip-goats-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure custom element styles append correctly during prod

packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ export function client_component(analysis, options) {
380380
state.hoisted.push(b.const('$$css', b.object([b.init('hash', hash), b.init('code', code)])));
381381

382382
component_block.body.unshift(
383-
b.stmt(b.call('$.append_styles', b.id('$$anchor'), b.id('$$css')))
383+
b.stmt(
384+
b.call('$.append_styles', b.id('$$anchor'), b.id('$$css'), options.customElement && b.true)
385+
)
384386
);
385387
}
386388

packages/svelte/src/internal/client/dom/css.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ var seen = new Set();
66
/**
77
* @param {Node} anchor
88
* @param {{ hash: string, code: string }} css
9+
* @param {boolean} [is_custom_element]
910
*/
10-
export function append_styles(anchor, css) {
11+
export function append_styles(anchor, css, is_custom_element = false) {
1112
// in dev, always check the DOM, so that styles can be replaced with HMR
12-
if (!DEV) {
13+
if (!DEV && !is_custom_element) {
1314
if (seen.has(css)) return;
1415
seen.add(css);
1516
}

0 commit comments

Comments
 (0)