Skip to content

Commit 0a21f13

Browse files
committed
feat: support HMR with custom elements
closes sveltejs/svelte-hmr#26
1 parent 9d9ed33 commit 0a21f13

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.changeset/swift-queens-begin.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+
feat: support HMR with custom elements

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,15 @@ export function client_component(analysis, options) {
593593

594594
// If a tag name is provided, call `customElements.define`, otherwise leave to the user
595595
if (typeof ce !== 'boolean' && typeof ce.tag === 'string') {
596-
body.push(b.stmt(b.call('customElements.define', b.literal(ce.tag), create_ce)));
596+
const define = b.stmt(b.call('customElements.define', b.literal(ce.tag), create_ce));
597+
598+
if (options.hmr) {
599+
body.push(
600+
b.if(b.binary('==', b.call('customElements.get', b.literal(ce.tag)), b.null), define)
601+
);
602+
} else {
603+
body.push(define);
604+
}
597605
} else {
598606
body.push(b.stmt(create_ce));
599607
}

0 commit comments

Comments
 (0)