Skip to content

Commit

Permalink
fix: prevent writable store value from becoming a proxy when reassign…
Browse files Browse the repository at this point in the history
…ing using $-prefix (#15283)

fixes #15281
  • Loading branch information
tomoam authored Feb 17, 2025
1 parent dde8603 commit 073f4d8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-chairs-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: prevent writable store value from becoming a proxy when reassigning using $-prefix
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from '../../test';

export default test({
async test({ target, assert }) {
assert.htmlEqual(target.innerHTML, `<p>bar</p>`);
}
});
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 073f4d8

Please sign in to comment.