Skip to content

fix: improve state store mutation compiler output #10561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/witty-years-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: improve state store mutation compiler output
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export function serialize_set_binding(node, context, fallback, options) {
return {
...node,
object: visit_node(/** @type {import("estree").Expression} */ (node.object)),
property: /** @type {import("estree").Expression} */ (visit(node.property))
property: /** @type {import("estree").MemberExpression} */ (visit(node)).property
};
}
if (node.type === 'Identifier') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script>
import { writable } from 'svelte/store';

let { data } = $props();
let form = writable(data.form);

function addTag() {
$form.data.tags['third'] = 3;
}
</script>

<pre>{JSON.stringify($form, null, 2)}</pre>

<button on:click={addTag}>add</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { flushSync } from '../../../../src/main/main-client';
import { test } from '../../test';

export default test({
async test({ assert, target }) {
const btn = target.querySelector('button');

flushSync(() => {
btn?.click();
});

assert.htmlEqual(
target.innerHTML,
`<pre>{\n"data": { "tags": { "first": 1, "second": 2, "third": 3 } } }</pre><button>add</button>`
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
import Page from './Component.svelte';

let data = $state({ form: { data: { tags: { first: 1, second: 2 }}}});
</script>
<Page {data} />