Skip to content

Commit 073f4d8

Browse files
authored
fix: prevent writable store value from becoming a proxy when reassigning using $-prefix (#15283)
fixes #15281
1 parent dde8603 commit 073f4d8

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

.changeset/lovely-chairs-compete.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: prevent writable store value from becoming a proxy when reassigning using $-prefix

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
@@ -118,6 +118,7 @@ function build_assignment(operator, left, right, context) {
118118
binding.kind !== 'prop' &&
119119
binding.kind !== 'bindable_prop' &&
120120
binding.kind !== 'raw_state' &&
121+
binding.kind !== 'store_sub' &&
121122
context.state.analysis.runes &&
122123
should_proxy(right, context.state.scope) &&
123124
is_non_coercive_operator(operator)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
async test({ target, assert }) {
5+
assert.htmlEqual(target.innerHTML, `<p>bar</p>`);
6+
}
7+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import { writable } from "svelte/store";
3+
4+
const obj = writable({ name: 'foo' });
5+
6+
$obj = { name: 'bar' };
7+
8+
const clone = structuredClone($obj);
9+
</script>
10+
11+
<p>{clone.name}</p>

0 commit comments

Comments
 (0)