fix: do not proxify the value assigned to a derived (#16302)

pull/16306/head
7nik 2 months ago committed by GitHub
parent 432763a03e
commit c3348aea06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: do not proxify the value assigned to a derived

@ -137,6 +137,7 @@ function build_assignment(operator, left, right, context) {
binding.kind !== 'prop' && binding.kind !== 'prop' &&
binding.kind !== 'bindable_prop' && binding.kind !== 'bindable_prop' &&
binding.kind !== 'raw_state' && binding.kind !== 'raw_state' &&
binding.kind !== 'derived' &&
binding.kind !== 'store_sub' && binding.kind !== 'store_sub' &&
context.state.analysis.runes && context.state.analysis.runes &&
should_proxy(right, context.state.scope) && should_proxy(right, context.state.scope) &&

@ -0,0 +1,23 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
test({ assert, target }) {
const [btn1, btn2, btn3] = target.getElementsByTagName('button');
const [div] = target.getElementsByTagName('div');
flushSync(() => btn1.click());
assert.equal(div.textContent, '1');
flushSync(() => btn2.click());
assert.equal(div.textContent, '1');
flushSync(() => btn3.click());
assert.equal(div.textContent, '2');
flushSync(() => btn1.click());
assert.equal(div.textContent, '2');
flushSync(() => btn2.click());
assert.equal(div.textContent, '2');
flushSync(() => btn3.click());
assert.equal(div.textContent, '3');
}
});

@ -0,0 +1,9 @@
<script>
let count = $derived({ value: 1 });
</script>
<button onclick={() => count.value++}>mutate</button>
<button onclick={() => count = count}>assign self</button>
<button onclick={() => count = {...count} }>assign copy</button>
<div>{count.value}</div>
Loading…
Cancel
Save