mirror of https://github.com/sveltejs/svelte
fix: untrack `$inspect.with` and add check for unsafe mutation (#16209)
Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/16219/head
parent
4db4ee5330
commit
c4b32c2bff
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: untrack `$inspect.with` and add check for unsafe mutation
|
@ -0,0 +1,9 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
error: 'state_unsafe_mutation'
|
||||||
|
});
|
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
let a = $state(0);
|
||||||
|
|
||||||
|
let b = $state(0);
|
||||||
|
|
||||||
|
$inspect(a).with((...args)=>{
|
||||||
|
console.log(...args);
|
||||||
|
b++;
|
||||||
|
});
|
||||||
|
</script>
|
@ -0,0 +1,20 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
async test({ assert, target, logs }) {
|
||||||
|
const [a, b] = target.querySelectorAll('button');
|
||||||
|
assert.deepEqual(logs, ['init', 0]);
|
||||||
|
flushSync(() => {
|
||||||
|
b?.click();
|
||||||
|
});
|
||||||
|
assert.deepEqual(logs, ['init', 0]);
|
||||||
|
flushSync(() => {
|
||||||
|
a?.click();
|
||||||
|
});
|
||||||
|
assert.deepEqual(logs, ['init', 0, 'update', 1]);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
let a = $state(0);
|
||||||
|
|
||||||
|
let b = $state(0);
|
||||||
|
|
||||||
|
$inspect(a).with((...args)=>{
|
||||||
|
console.log(...args);
|
||||||
|
b;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={()=>a++}></button>
|
||||||
|
<button onclick={()=>b++}></button>
|
Loading…
Reference in new issue