fix: use acceptExports to support partial hmr (#11453)

* fix: use acceptExports to support partial hmr

* fix: add condition to only use acceptExports when it is available

* fix: update test snapshot

* fix: format
pull/11512/head
Dominik G 8 months ago committed by GitHub
parent 0cf6d56ffe
commit 28f3755e40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: use import.meta.hot.acceptExports when available to support partial hmr in vite

@ -429,6 +429,10 @@ export function client_component(source, analysis, options) {
);
if (options.hmr) {
const accept_fn = b.arrow(
[b.id('module')],
b.block([b.stmt(b.call('$.set', b.id('s'), b.member(b.id('module'), b.id('default'))))])
);
body.push(
component,
b.if(
@ -436,16 +440,12 @@ export function client_component(source, analysis, options) {
b.block([
b.const(b.id('s'), b.call('$.source', b.id(analysis.name))),
b.stmt(b.assignment('=', b.id(analysis.name), b.call('$.hmr', b.id('s')))),
b.stmt(
b.call(
'import.meta.hot.accept',
b.arrow(
[b.id('module')],
b.block([
b.stmt(b.call('$.set', b.id('s'), b.member(b.id('module'), b.id('default'))))
])
)
)
b.if(
b.id('import.meta.hot.acceptExports'),
b.stmt(
b.call('import.meta.hot.acceptExports', b.array([b.literal('default')]), accept_fn)
),
b.stmt(b.call('import.meta.hot.accept', accept_fn))
)
])
),

@ -14,9 +14,11 @@ if (import.meta.hot) {
Hmr = $.hmr(s);
import.meta.hot.accept((module) => {
if (import.meta.hot.acceptExports) import.meta.hot.acceptExports(["default"], (module) => {
$.set(s, module.default);
}); else import.meta.hot.accept((module) => {
$.set(s, module.default);
});
}
export default Hmr;
export default Hmr;

Loading…
Cancel
Save