mirror of https://github.com/sveltejs/svelte
chore: verify that `$effect.root(...)` does not re-run (#11020)
parent
0a162924fb
commit
34748ba015
@ -0,0 +1,31 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
import { log } from './log.js';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
before_test() {
|
||||||
|
log.length = 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [b1, b2] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
b1.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(log, [0]);
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
b2.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(log, [0, 'cleanup']);
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
b1.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(log, [0, 'cleanup']);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,2 @@
|
|||||||
|
/** @type {any[]} */
|
||||||
|
export const log = [];
|
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
import { log } from './log.js';
|
||||||
|
|
||||||
|
let x = $state(0);
|
||||||
|
|
||||||
|
const cleanup = $effect.root(() => {
|
||||||
|
log.push(x);
|
||||||
|
return () => log.push('cleanup');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => x++}>{x}</button>
|
||||||
|
<button onclick={cleanup}>cleanup</button>
|
Loading…
Reference in new issue