Skip to content

Commit

Permalink
feat: support HMR with custom elements (#12926)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored Aug 20, 2024
1 parent 4ce23bf commit 212b602
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/swift-queens-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

feat: support HMR with custom elements
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,15 @@ export function client_component(analysis, options) {

// If a tag name is provided, call `customElements.define`, otherwise leave to the user
if (typeof ce !== 'boolean' && typeof ce.tag === 'string') {
body.push(b.stmt(b.call('customElements.define', b.literal(ce.tag), create_ce)));
const define = b.stmt(b.call('customElements.define', b.literal(ce.tag), create_ce));

if (options.hmr) {
body.push(
b.if(b.binary('==', b.call('customElements.get', b.literal(ce.tag)), b.null), define)
);
} else {
body.push(define);
}
} else {
body.push(b.stmt(create_ce));
}
Expand Down

0 comments on commit 212b602

Please sign in to comment.