Skip to content

Commit 232cf4a

Browse files
committed
feedback
1 parent 45e87b1 commit 232cf4a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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'), b.literal(options.customElement))
385+
)
384386
);
385387
}
386388

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
import { DEV } from 'esm-env';
12
import { queue_micro_task } from './task.js';
23

4+
var seen = new Set();
5+
36
/**
47
* @param {Node} anchor
58
* @param {{ hash: string, code: string }} css
9+
* @param {boolean} is_custom_element
610
*/
7-
export function append_styles(anchor, css) {
11+
export function append_styles(anchor, css, is_custom_element) {
12+
// in dev, always check the DOM, so that styles can be replaced with HMR
13+
if (!DEV && !is_custom_element) {
14+
if (seen.has(css)) return;
15+
seen.add(css);
16+
}
17+
818
// Use `queue_micro_task` to ensure `anchor` is in the DOM, otherwise getRootNode() will yield wrong results
919
queue_micro_task(() => {
1020
var root = anchor.getRootNode();

0 commit comments

Comments
 (0)