Skip to content

Commit 4b9c4e1

Browse files
committed
fix accessors in HMR
1 parent 30764db commit 4b9c4e1

File tree

1 file changed

+7
-10
lines changed
  • packages/svelte/src/internal/client

1 file changed

+7
-10
lines changed

packages/svelte/src/internal/client/hmr.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { source, set, get } from './runtime.js';
33

44
/**
55
* @template {any[]} ComponentArgs
6-
* @template {Record<string, any> | undefined} ComponentReturn
6+
* @template {Record<string | symbol, any> | undefined} ComponentReturn
77
* @template {(...args: ComponentArgs) => ComponentReturn} Component
88
*
99
* @param {{
@@ -20,31 +20,28 @@ export function hmr(hot_data, component) {
2020

2121
// @ts-ignore
2222
hot_data.proxy = function (target, ...args) {
23-
/** @type {ComponentReturn} */
24-
let current_accessors;
23+
const accessors = source(/** @type {ComponentReturn} */ ({}));
2524

2625
key(
2726
target,
2827
() => get(component_signal),
2928
($$anchor) => {
3029
const current_component = get(component_signal);
3130
// @ts-ignore
32-
current_accessors = current_component($$anchor, ...args);
31+
const new_accessors = current_component($$anchor, ...args);
32+
set(accessors, new_accessors);
3333
}
3434
);
3535

3636
return new Proxy(
3737
{},
3838
{
3939
get(_, p) {
40-
// we actually want to crash if no accessors, because no HMR code would crash
41-
// @ts-ignore
42-
return current_accessors[p];
40+
return get(accessors)?.[p];
4341
},
4442
set(_, p, value) {
45-
// we actually want to crash if no accessors, because no HMR code would crash
46-
// @ts-ignore
47-
current_accessors[p] = value;
43+
// @ts-ignore (we actually want to crash on undefined, like non HMR code would do)
44+
get(accessors)[p] = value;
4845
return true;
4946
}
5047
}

0 commit comments

Comments
 (0)