fix: remove listener on `bind_current_time` teardown (#15013)

Fixes #15008
pull/15015/head
Paolo Ricciuti 2 days ago committed by GitHub
parent dfa97a5e64
commit 360ee70dcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: remove listener on `bind_current_time` teardown

@ -52,7 +52,10 @@ export function bind_current_time(media, get, set = get) {
}
});
teardown(() => cancelAnimationFrame(raf_id));
teardown(() => {
cancelAnimationFrame(raf_id);
media.removeEventListener('timeupdate', callback);
});
}
/**

@ -0,0 +1,26 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
async test({ assert, target, logs }) {
const audio = target.querySelector('audio');
const btn = target.querySelector('button');
ok(audio);
flushSync(() => {
audio.currentTime = 10;
audio.dispatchEvent(new Event('timeupdate'));
});
assert.deepEqual(logs, ['event']);
flushSync(() => {
btn?.click();
});
flushSync(() => {
audio.currentTime = 20;
audio.dispatchEvent(new Event('timeupdate'));
});
assert.deepEqual(logs, ['event']);
}
});

@ -0,0 +1,12 @@
<script>
let show = $state(true);
let time = $state(0);
</script>
<button onclick={()=> show = false}></button>
{#if show}
<audio bind:currentTime={()=>time,(new_time)=>{
console.log("event");
time = new_time;
}}></audio>
{/if}
Loading…
Cancel
Save