Skip to content

Commit 0896543

Browse files
authored
fix: further improvements to hmr component key generation (#11129)
1 parent 3f9f286 commit 0896543

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.changeset/breezy-rules-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: further improvements to hmr component key generation

packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,10 @@ export function client_component(source, analysis, options) {
422422
)
423423
];
424424

425-
if (options.hmr) {
425+
// In order for hmr to work correctly, we need associate each component with a unique key.
426+
// This is because bundlers might put many components into a the same module (usuaully as a chunk).
427+
// `import.meta.hot` will then be the same object for all components in that modules.
428+
if (options.hmr && options.filename) {
426429
body.push(
427430
b.export_default(
428431
b.conditional(
@@ -431,7 +434,7 @@ export function client_component(source, analysis, options) {
431434
'$.hmr',
432435
b.member(b.import_meta_hot(), b.id('data')),
433436
b.id(analysis.name),
434-
b.member(b.member(b.id('import'), b.id('meta')), b.id('url'))
437+
b.literal(options.filename)
435438
),
436439
b.id(analysis.name)
437440
)

0 commit comments

Comments
 (0)