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 <rich.harris@vercel.com>
pull/12794/head
Dominic Gannaway 5 months ago committed by GitHub
parent 1a3dbda20c
commit 536be645fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure custom element styles append correctly during prod

@ -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)
)
);
}

@ -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);
}

Loading…
Cancel
Save