Skip to content

Commit d5791fb

Browse files
committed
fix
1 parent 084aabf commit d5791fb

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function proxy(value, immutable = true, parent = null) {
7474
? // @ts-expect-error
7575
new Set([current_component_context.function])
7676
: null
77-
: parent.owners;
77+
: new Set();
7878
}
7979

8080
return proxy;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
/** @type {{ shared: { count: number }, notshared: { count: number } }} */
3+
let { shared = $bindable(), notshared } = $props();
4+
</script>
5+
6+
<button onclick={() => shared.count += 1}>
7+
clicks: {shared.count}
8+
</button>
9+
10+
<button onclick={() => notshared.count += 1}>
11+
clicks: {notshared.count}
12+
</button>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
/** @type {typeof console.warn} */
5+
let warn;
6+
7+
/** @type {typeof console.trace} */
8+
let trace;
9+
10+
/** @type {any[]} */
11+
let warnings = [];
12+
13+
export default test({
14+
html: `<button>clicks: 0</button><button>clicks: 0</button>`,
15+
16+
compileOptions: {
17+
dev: true
18+
},
19+
20+
before_test: () => {
21+
warn = console.warn;
22+
trace = console.trace;
23+
24+
console.warn = (...args) => {
25+
warnings.push(...args);
26+
};
27+
28+
console.trace = () => {};
29+
},
30+
31+
after_test: () => {
32+
console.warn = warn;
33+
console.trace = trace;
34+
35+
warnings = [];
36+
},
37+
38+
async test({ assert, target }) {
39+
const [btn1, btn2] = target.querySelectorAll('button');
40+
41+
flushSync(() => btn1.click());
42+
assert.htmlEqual(target.innerHTML, `<button>clicks: 1</button><button>clicks: 0</button>`);
43+
44+
assert.deepEqual(warnings, []);
45+
46+
flushSync(() => btn2.click());
47+
assert.htmlEqual(target.innerHTML, `<button>clicks: 1</button><button>clicks: 1</button>`);
48+
49+
assert.deepEqual(warnings, [
50+
'.../samples/non-local-mutation-with-binding-3/Counter.svelte mutated a value owned by .../samples/non-local-mutation-with-binding-3/main.svelte. This is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead.'
51+
]);
52+
}
53+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
import Counter from './Counter.svelte';
3+
4+
let object = $state({
5+
shared: { count: 0 },
6+
notshared: { count: 0 }
7+
});
8+
</script>
9+
10+
<Counter
11+
bind:shared={object.shared}
12+
notshared={object.notshared}
13+
/>

0 commit comments

Comments
 (0)