Skip to content

Commit b3f54bd

Browse files
authored
fix store direct property assignment (#5416)
1 parent aef5671 commit b3f54bd

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
* Support `_` as numeric separator ([#5407](https://github.com/sveltejs/svelte/issues/5407))
6+
* Fix assignments to properties on store values ([#5412](https://github.com/sveltejs/svelte/issues/5412))
67
* Support `import.meta` in template expressions ([#5422](https://github.com/sveltejs/svelte/issues/5422))
78

89
## 3.25.1

src/compiler/compile/render_dom/invalidate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function invalidate(renderer: Renderer, scope: Scope, node: Node, names:
6262
}
6363

6464
let invalidate = is_store_value
65-
? x`@set_store_value(${head.name.slice(1)}, ${node}, ${extra_args})`
65+
? x`@set_store_value(${head.name.slice(1)}, ${node}, ${head.name})`
6666
: !main_execution_context
6767
? x`$$invalidate(${renderer.context_lookup.get(head.name).index}, ${node}, ${extra_args})`
6868
: extra_args.length
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export default {
2+
html: `
3+
<p>a: {"foo":3,"bar":2}</p>
4+
<p>b: {"foo":3}</p>
5+
<button></button>
6+
<button></button>
7+
`,
8+
skip_if_ssr: true,
9+
10+
async test({ assert, component, target, window }) {
11+
const [btn1, btn2] = target.querySelectorAll('button');
12+
const click = new window.MouseEvent('click');
13+
14+
await btn1.dispatchEvent(click);
15+
16+
assert.htmlEqual(target.innerHTML, `
17+
<p>a: {"foo":4,"bar":2}</p>
18+
<p>b: {"foo":4,"baz":0}</p>
19+
<button></button>
20+
<button></button>
21+
`);
22+
23+
await btn2.dispatchEvent(click);
24+
25+
assert.htmlEqual(target.innerHTML, `
26+
<p>a: {"foo":5,"bar":2}</p>
27+
<p>b: {"foo":5,"qux":0}</p>
28+
<button></button>
29+
<button></button>
30+
`);
31+
}
32+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script>
2+
import { writable } from '../../../../store';
3+
4+
const a = writable({ foo: 1, bar: 2 });
5+
$a.foo = 3;
6+
7+
const b = writable({ foo: 1, bar: 2 });
8+
$b = { foo: 3 };
9+
10+
function update() {
11+
$a.foo = $a.foo + 1;
12+
$b = { foo: $b.foo + 1, qux: 0 };
13+
}
14+
</script>
15+
16+
<p>a: {JSON.stringify($a)}</p>
17+
<p>b: {JSON.stringify($b)}</p>
18+
19+
<button on:click={() => {
20+
$a.foo = $a.foo + 1;
21+
$b = { foo: $b.foo + 1, baz: 0 };
22+
}} />
23+
24+
<button on:click={update} />

0 commit comments

Comments
 (0)