Skip to content

Commit ddb968c

Browse files
authored
fix: ensure proxy owner set always has 1 or more members (#10577)
* fix missing owners * regression test --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 88389ad commit ddb968c

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

.changeset/sour-bags-fail.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: inherit ownerlessness when creating child proxies

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function proxy(value, immutable = true, owners) {
8484
? // @ts-expect-error
8585
new Set([current_component_context.function])
8686
: null
87-
: new Set(owners);
87+
: owners && new Set(owners);
8888
}
8989

9090
return proxy;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { test } from '../../test';
2+
3+
/** @type {typeof console.warn} */
4+
let warn;
5+
6+
/** @type {any[]} */
7+
let warnings = [];
8+
9+
export default test({
10+
html: `<button>clicks: 0</button>`,
11+
12+
compileOptions: {
13+
dev: true
14+
},
15+
16+
before_test: () => {
17+
warn = console.warn;
18+
19+
console.warn = (...args) => {
20+
warnings.push(...args);
21+
};
22+
},
23+
24+
after_test: () => {
25+
console.warn = warn;
26+
warnings = [];
27+
},
28+
29+
async test({ assert, target }) {
30+
const btn = target.querySelector('button');
31+
await btn?.click();
32+
33+
assert.htmlEqual(target.innerHTML, `<button>clicks: 1</button>`);
34+
35+
assert.deepEqual(warnings, []);
36+
}
37+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
import { global } from './state.svelte.js';
3+
4+
global.a = { b: 0 };
5+
</script>
6+
7+
<button onclick={() => global.a.b += 1}>
8+
clicks: {global.a.b}
9+
</button>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export let global = $state({});

0 commit comments

Comments
 (0)