Skip to content

Commit 2cefd78

Browse files
authored
fix: make ownership validation work with HMR (#11171)
* fix: make ownership validation work with HMR * bump vite-plugin-svelte in playground * missed a spot
1 parent a092899 commit 2cefd78

File tree

7 files changed

+66
-49
lines changed

7 files changed

+66
-49
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

playgrounds/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"preview": "vite preview"
1212
},
1313
"devDependencies": {
14-
"@sveltejs/vite-plugin-svelte": "^3.0.1",
14+
"@sveltejs/vite-plugin-svelte": "^3.1.0",
1515
"express": "^4.19.2",
1616
"nodemon": "^3.0.3",
1717
"svelte": "workspace:*",

pnpm-lock.yaml

Lines changed: 45 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sites/svelte-5-preview/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@sveltejs/adapter-vercel": "^5.0.0",
1818
"@sveltejs/kit": "^2.5.0",
1919
"@sveltejs/site-kit": "6.0.0-next.59",
20-
"@sveltejs/vite-plugin-svelte": "^3.0.0",
20+
"@sveltejs/vite-plugin-svelte": "^3.1.0",
2121
"@types/marked": "^6.0.0",
2222
"esrap": "^1.2.1",
2323
"marked": "^9.0.0",

sites/svelte.dev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@sveltejs/adapter-vercel": "^4.0.0",
3232
"@sveltejs/kit": "^2.4.3",
3333
"@sveltejs/site-kit": "6.0.0-next.59",
34-
"@sveltejs/vite-plugin-svelte": "^3.0.1",
34+
"@sveltejs/vite-plugin-svelte": "^3.1.0",
3535
"@types/cookie": "^0.6.0",
3636
"@types/node": "^20.11.5",
3737
"browserslist": "^4.22.2",

0 commit comments

Comments
 (0)