Merge branch 'main' into transformers

pull/12780/head
Rich Harris 2 years ago
commit a74f66364d

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

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

@ -72,7 +72,9 @@ for (const generate of /** @type {const} */ (['client', 'server'])) {
output_js,
compiled.js.code + '\n//# sourceMappingURL=' + path.basename(output_map)
);
fs.writeFileSync(output_map, compiled.js.map.toString());
if (compiled.css) {
fs.writeFileSync(output_css, compiled.css.code);
}

Loading…
Cancel
Save