ITADN

getAbortSignal() from $derived isn't aborted on component destruction

#18301Opengyzerok 创建于 2026-05-27
G
gyzerokcommented
### Describe the bug According to [docs](https://svelte.dev/docs/svelte/svelte#getAbortSignal): > Returns an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that aborts when the current [derived](https://svelte.dev/docs/svelte/$derived) or [effect](https://svelte.dev/docs/svelte/$effect) re-runs or is destroyed. However in the following code it doesn't seem to abort upon component destruction: ```svelte <script> import { getAbortSignal, untrack, onMount } from 'svelte' const { s1, s2 } = $props() onMount(() => { const signal = getAbortSignal() signal.addEventListener('abort', () => { console.log('abort inside onMount') // this logs }, { once: true }) }) const d1 = $derived.by(() => { s1; return untrack(() => { const signal = getAbortSignal() signal.addEventListener('abort', () => { console.log('abort inside untrack') // this does not }, { once: true }) return s2 * 2 }) }) const d2 = $derived.by(() => { s1; const signal = getAbortSignal() signal.addEventListener('abort', () => { console.log('abort outside untrack') // this does not }, { once: true }) return s2 * 2 }) </script> d1: {d1} d2: {d2} ``` I kinda feel like it was working at some point, but I couldn't find a version it would work for. Am I missing something obvious here? ### Reproduction [REPL](https://svelte.dev/playground/hello-world?version=5.55.9#H4sIAAAAAAAAE61UUW-bMBD-Kye2CVgRKTzSUKmaJu1he9rjsgeCTWTVsZF9pKuQ__vO4DRNRKNqmlCwc3ff5_u-izNGqtnzqIq-cSk1PGkjGSScCeQsjbKoE5LbqPo1Rvjc-zofoHhAPfR9bg9coo9tG8uX4q1WyBUSTbS2rRE93m_UBsW-1wbhi6ZVUR46o_cQ56uXSKCIfbX_SI7Q6oFKa_hosUGe3KZ3Z5leDtZnGTfiwFkyl99AkW7UenU6Xa23A6JWoFUrRftYj0kK9X2gv6mhcFOTU9JWME4J50lm4EQyfhBdgHyCEuq6hlvnYeuTKlvUAQy2DFvfpYMVcYwr0TnyCPkfjCo0A3fZG15f2nLu-EL2uu8j7Dg-bGn7U-xUIzOgxkzTPmbkyY9JkwsjuRgD8VqPt0VGkqiK_O6N7m2SelM2GPDJbOk44QLKTmcR4vzwI3KDc0HeMPb1QM1_F5Y0cJPEja-OMzgjnWm15LnUu1ADQlnB-FFFnM6lLqOWadq8Am8zuCk-v0-qWPHq15Nvn8812OLu2KfhOBh19CxZ6Oq6WPwXsdfkhk7iF_JlwdMT1qCBZvgZyuDSyZWTJ-U7PXmX6v8wYD3gkuQ3BatFse7yL4EVdM9ZQReYlX5XXlzM3_StEfJJKBZVXSMtd38Be68c-z8FAAA) ### Logs ```shell ``` ### System Info ```shell irrelevant ``` ### Severity annoyance
1 条评论