Skip to content

Commit 2cfd08e

Browse files
committed
fix: make ownership validation work with HMR
1 parent f90639d commit 2cfd08e

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

.changeset/calm-pandas-vanish.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: make ownership validation work correctly with HMR

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ export function client_component(source, analysis, options) {
464464
);
465465
}
466466

467-
body.unshift(b.stmt(b.call(b.id('$.mark_module_start'), b.id(analysis.name))));
468-
body.push(b.stmt(b.call(b.id('$.mark_module_end'))));
467+
body.unshift(b.stmt(b.call(b.id('$.mark_module_start'))));
468+
body.push(b.stmt(b.call(b.id('$.mark_module_end'), b.id(analysis.name))));
469469
}
470470

471471
if (options.discloseVersion) {

packages/svelte/src/internal/client/dev/ownership.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,33 @@ function get_component() {
6767
* Together with `mark_module_end`, this function establishes the boundaries of a `.svelte` file,
6868
* such that subsequent calls to `get_component` can tell us which component is responsible
6969
* for a given state change
70-
* @param {Function} component
7170
*/
72-
export function mark_module_start(component) {
71+
export function mark_module_start() {
7372
const start = get_stack()?.[2];
7473

7574
if (start) {
7675
(boundaries[start.file] ??= []).push({
7776
start,
7877
// @ts-expect-error
7978
end: null,
80-
component
79+
// @ts-expect-error we add the component at the end, since HMR will overwrite the function
80+
component: null
8181
});
8282
}
8383
}
8484

85-
export function mark_module_end() {
85+
/**
86+
* @param {Function} component
87+
*/
88+
export function mark_module_end(component) {
8689
const end = get_stack()?.[2];
8790

8891
if (end) {
8992
const boundaries_file = boundaries[end.file];
90-
boundaries_file[boundaries_file.length - 1].end = end;
93+
const boundary = boundaries_file[boundaries_file.length - 1];
94+
95+
boundary.end = end;
96+
boundary.component = component;
9197
}
9298
}
9399

0 commit comments

Comments
 (0)