mirror of https://github.com/sveltejs/svelte
commit
e567368cc6
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: never mark a child effect root as inert
|
||||
@ -0,0 +1,14 @@
|
||||
<script>
|
||||
export function increment() {
|
||||
inc();
|
||||
}
|
||||
let inc;
|
||||
$effect.root(() => {
|
||||
let count = $state(0);
|
||||
let double = $derived(count * 2);
|
||||
inc = () => {
|
||||
count++;
|
||||
console.log('count', count, 'double', double);
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@ -0,0 +1,14 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
// Test that $effect.root continues to be operational after its parent effect has been destroyed
|
||||
export default test({
|
||||
test({ assert, target, logs }) {
|
||||
const [hide, increment] = target.querySelectorAll('button');
|
||||
|
||||
hide.click();
|
||||
flushSync();
|
||||
increment.click();
|
||||
assert.deepEqual(logs, ['count', 1, 'double', 2]);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,15 @@
|
||||
<script>
|
||||
import Child from "./Child.svelte";
|
||||
let show = $state(true);
|
||||
let child = $state();
|
||||
let increment;
|
||||
$effect(() => {
|
||||
if (child) increment = child.increment;
|
||||
});
|
||||
</script>
|
||||
|
||||
<button onclick={() => show = false}>hide</button>
|
||||
<button onclick={() => increment()}>increment</button>
|
||||
{#if show}
|
||||
<Child bind:this={child} />
|
||||
{/if}
|
||||
Loading…
Reference in new issue