mirror of https://github.com/sveltejs/svelte
breaking: state mutations inside the template are no longer allowed (#13660)
* breaking: state mutations inside the template are no longer allowed * fix test * fix test * lint * update error message * fix testpull/13697/head
parent
966a6bda05
commit
ae10f4d37c
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
breaking: state mutations inside the template are no longer allowed
|
@ -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,6 @@
|
|||||||
|
<script>
|
||||||
|
let items = $state([]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => items.push(3, 2, 1)}>Add</button>
|
||||||
|
{JSON.stringify(items.sort())}
|
Loading…
Reference in new issue