fix: prevent writable store value from becoming a proxy when reassigning using $-prefix (#15283)

fixes #15281
pull/15319/head
tomoam 7 months ago committed by GitHub
parent dde8603872
commit 073f4d8911
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: prevent writable store value from becoming a proxy when reassigning using $-prefix

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

@ -0,0 +1,7 @@
import { test } from '../../test';
export default test({
async test({ target, assert }) {
assert.htmlEqual(target.innerHTML, `<p>bar</p>`);
}
});

@ -0,0 +1,11 @@
<script>
import { writable } from "svelte/store";
const obj = writable({ name: 'foo' });
$obj = { name: 'bar' };
const clone = structuredClone($obj);
</script>
<p>{clone.name}</p>
Loading…
Cancel
Save