feat: support HMR with custom elements (#12926)

closes https://github.com/sveltejs/svelte-hmr/issues/26
pull/12931/head
Simon H 3 months ago committed by GitHub
parent 4ce23bf07e
commit 212b60203f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
feat: support HMR with custom elements

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

Loading…
Cancel
Save