fix: keep effect in the graph if it has an abort controller (#16430)

pull/16435/head
Paolo Ricciuti 2 months ago committed by GitHub
parent 93a8a495d2
commit c2da1ebb85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: keep effect in the graph if it has an abort controller

@ -532,7 +532,9 @@ function flush_queued_effects(effects) {
// here (rather than in `update_effect`) allows us to skip the work for
// immediate effects.
if (effect.deps === null && effect.first === null && effect.nodes_start === null) {
if (effect.teardown === null) {
// if there's no teardown or abort controller we completely unlink
// the effect from the graph
if (effect.teardown === null && effect.ac === null) {
// remove this effect from the graph
unlink_effect(effect);
} else {

@ -0,0 +1,8 @@
<script>
import { getAbortSignal } from 'svelte';
$effect(() => {
const signal = getAbortSignal()
signal.addEventListener('abort', () => console.log('abort'))
})
</script>

@ -0,0 +1,12 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
async test({ assert, target, logs }) {
const btn = target.querySelector('button');
flushSync(() => {
btn?.click();
});
assert.deepEqual(logs, ['abort']);
}
});

@ -0,0 +1,10 @@
<script>
import Component from './Component.svelte'
let show = $state(true)
</script>
<button onclick={() => (show = !show)}>click</button>
{#if show}
<Component />
{/if}
Loading…
Cancel
Save