mirror of https://github.com/sveltejs/svelte
fix: abort deriveds own AbortSignal when it disconnects (#18400)
Fixes https://github.com/sveltejs/svelte/issues/18301 --------- Co-authored-by: Fedor Nezhivoi <f.nezhivoi@corp.vk.com> Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>pull/18497/head
parent
4da9f74cd9
commit
a91b068786
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: abort deriveds own AbortSignal when it disconnects
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { getAbortSignal } from "svelte";
|
||||||
|
|
||||||
|
let { count, aborted = $bindable() } = $props()
|
||||||
|
|
||||||
|
let der = $derived.by(()=>{
|
||||||
|
const signal = getAbortSignal();
|
||||||
|
|
||||||
|
signal.addEventListener("abort", () => {
|
||||||
|
try {
|
||||||
|
aborted++;
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{der}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
import { ok, test } from '../../test';
|
||||||
|
import { flushSync } from 'svelte';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target, errors }) {
|
||||||
|
const btn = target.querySelector('button');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
btn?.click();
|
||||||
|
});
|
||||||
|
assert.htmlEqual(target.innerHTML, '1 <button>increment</button>');
|
||||||
|
assert.deepEqual(errors, []);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import Child from './Child.svelte'
|
||||||
|
|
||||||
|
let count = $state(0);
|
||||||
|
let aborted = $state(0)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{aborted}
|
||||||
|
|
||||||
|
<button onclick={() => count++}>increment</button>
|
||||||
|
|
||||||
|
{#if count % 2 === 0}
|
||||||
|
<Child {count} bind:aborted={aborted} />
|
||||||
|
{/if}
|
||||||
Loading…
Reference in new issue