Skip to content

Commit

Permalink
fix: correctly set filename on HMR wrappers (#12543)
Browse files Browse the repository at this point in the history
* fix: correctly set filename on HMR wrappers

* changeset
  • Loading branch information
Rich-Harris authored Jul 22, 2024
1 parent 346cf96 commit fd5cfd7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-suns-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: correctly set filename on HMR wrappers
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,16 @@ export function client_component(source, analysis, options) {

const hmr = b.block([
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.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,
// else we would call the HMR function two times
b.stmt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ function Hmr($$anchor) {

if (import.meta.hot) {
const s = $.source(Hmr);
const filename = Hmr.filename;
const $$filename = Hmr[$.FILENAME];
const $$original = Hmr;

Hmr = $.hmr(s);
Hmr.filename = filename;
Hmr[$.FILENAME] = $$filename;
Hmr[$.ORIGINAL] = $$original;

import.meta.hot.accept((module) => {
Expand Down

0 comments on commit fd5cfd7

Please sign in to comment.