fix: correctly set filename on HMR wrappers (#12543)

* fix: correctly set filename on HMR wrappers

* changeset
pull/12536/head
Rich Harris 5 months ago committed by GitHub
parent 346cf96599
commit fd5cfd77d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly set filename on HMR wrappers

@ -439,10 +439,16 @@ export function client_component(source, analysis, options) {
const hmr = b.block([ const hmr = b.block([
b.const(b.id('s'), b.call('$.source', b.id(analysis.name))), b.const(b.id('s'), b.call('$.source', b.id(analysis.name))),
b.const(b.id('filename'), b.member(b.id(analysis.name), b.id('filename'))), b.const(b.id('$$filename'), b.member(b.id(analysis.name), b.id('$.FILENAME'), true)),
b.const(b.id('$$original'), b.id(analysis.name)), b.const(b.id('$$original'), b.id(analysis.name)),
b.stmt(b.assignment('=', b.id(analysis.name), b.call('$.hmr', b.id('s')))), b.stmt(b.assignment('=', b.id(analysis.name), b.call('$.hmr', b.id('s')))),
b.stmt(b.assignment('=', b.member(b.id(analysis.name), b.id('filename')), b.id('filename'))), b.stmt(
b.assignment(
'=',
b.member(b.id(analysis.name), b.id('$.FILENAME'), true),
b.id('$$filename')
)
),
// Assign the original component to the wrapper so we can use it on hot reload patching, // Assign the original component to the wrapper so we can use it on hot reload patching,
// else we would call the HMR function two times // else we would call the HMR function two times
b.stmt( b.stmt(

@ -11,11 +11,11 @@ function Hmr($$anchor) {
if (import.meta.hot) { if (import.meta.hot) {
const s = $.source(Hmr); const s = $.source(Hmr);
const filename = Hmr.filename; const $$filename = Hmr[$.FILENAME];
const $$original = Hmr; const $$original = Hmr;
Hmr = $.hmr(s); Hmr = $.hmr(s);
Hmr.filename = filename; Hmr[$.FILENAME] = $$filename;
Hmr[$.ORIGINAL] = $$original; Hmr[$.ORIGINAL] = $$original;
import.meta.hot.accept((module) => { import.meta.hot.accept((module) => {

Loading…
Cancel
Save