diff --git a/.changeset/hip-goats-smoke.md b/.changeset/hip-goats-smoke.md new file mode 100644 index 0000000000..ce023460b7 --- /dev/null +++ b/.changeset/hip-goats-smoke.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure custom element styles append correctly during prod diff --git a/packages/svelte/src/compiler/phases/3-transform/client/transform-client.js b/packages/svelte/src/compiler/phases/3-transform/client/transform-client.js index 82d49f0ad7..6ebb77f2e9 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/transform-client.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/transform-client.js @@ -380,7 +380,9 @@ export function client_component(analysis, options) { state.hoisted.push(b.const('$$css', b.object([b.init('hash', hash), b.init('code', code)]))); component_block.body.unshift( - b.stmt(b.call('$.append_styles', b.id('$$anchor'), b.id('$$css'))) + b.stmt( + b.call('$.append_styles', b.id('$$anchor'), b.id('$$css'), options.customElement && b.true) + ) ); } diff --git a/packages/svelte/src/internal/client/dom/css.js b/packages/svelte/src/internal/client/dom/css.js index 1cccb42b3e..dbf862543f 100644 --- a/packages/svelte/src/internal/client/dom/css.js +++ b/packages/svelte/src/internal/client/dom/css.js @@ -6,10 +6,11 @@ var seen = new Set(); /** * @param {Node} anchor * @param {{ hash: string, code: string }} css + * @param {boolean} [is_custom_element] */ -export function append_styles(anchor, css) { +export function append_styles(anchor, css, is_custom_element = false) { // in dev, always check the DOM, so that styles can be replaced with HMR - if (!DEV) { + if (!DEV && !is_custom_element) { if (seen.has(css)) return; seen.add(css); }