mirror of https://github.com/sveltejs/svelte
breaking: disallow state mutations in logic block expression (#13625)
parent
7429854383
commit
2070c8a166
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
breaking: disallow state mutations in logic block expression
|
@ -0,0 +1,17 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
|
||||||
|
test({ assert, target }) {
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
|
||||||
|
assert.throws(() => {
|
||||||
|
button?.click();
|
||||||
|
flushSync();
|
||||||
|
}, /state_unsafe_mutation/);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
let items = $state([]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => items.push(3, 2, 1)}>Add</button>
|
||||||
|
{#each items.sort() as item (item)}
|
||||||
|
<p>{item}</p>
|
||||||
|
{/each}
|
||||||
|
|
Loading…
Reference in new issue