Skip to content

Commit c3348ae

Browse files
authored
fix: do not proxify the value assigned to a derived (#16302)
1 parent 432763a commit c3348ae

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

.changeset/new-wolves-punch.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: do not proxify the value assigned to a derived

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function build_assignment(operator, left, right, context) {
137137
binding.kind !== 'prop' &&
138138
binding.kind !== 'bindable_prop' &&
139139
binding.kind !== 'raw_state' &&
140+
binding.kind !== 'derived' &&
140141
binding.kind !== 'store_sub' &&
141142
context.state.analysis.runes &&
142143
should_proxy(right, context.state.scope) &&
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ assert, target }) {
6+
const [btn1, btn2, btn3] = target.getElementsByTagName('button');
7+
const [div] = target.getElementsByTagName('div');
8+
9+
flushSync(() => btn1.click());
10+
assert.equal(div.textContent, '1');
11+
flushSync(() => btn2.click());
12+
assert.equal(div.textContent, '1');
13+
flushSync(() => btn3.click());
14+
assert.equal(div.textContent, '2');
15+
16+
flushSync(() => btn1.click());
17+
assert.equal(div.textContent, '2');
18+
flushSync(() => btn2.click());
19+
assert.equal(div.textContent, '2');
20+
flushSync(() => btn3.click());
21+
assert.equal(div.textContent, '3');
22+
}
23+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let count = $derived({ value: 1 });
3+
</script>
4+
5+
<button onclick={() => count.value++}>mutate</button>
6+
<button onclick={() => count = count}>assign self</button>
7+
<button onclick={() => count = {...count} }>assign copy</button>
8+
9+
<div>{count.value}</div>

0 commit comments

Comments
 (0)