Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit d7d71ce

Browse files
authored
fix: cleanup timeout to prevent leak (#252)
1 parent 0a700a2 commit d7d71ce

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

.changeset/wicked-pots-whisper.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/site-kit': patch
3+
---
4+
5+
fix: cleanup timeout to prevent leak

packages/site-kit/src/lib/nav/PreloadingIndicator.svelte

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
let visible = false;
1111
1212
onMount(() => {
13+
/** @type {any} */
14+
let timeout;
15+
1316
function next() {
1417
visible = true;
1518
@@ -19,10 +22,14 @@
1922
duration: remaining + 0.1 > 0.15 ? 250 : 500 / remaining
2023
});
2124
22-
if (remaining > 0.15) setTimeout(next, 500 / remaining);
25+
if (remaining > 0.15) {
26+
timeout = setTimeout(next, 500 / remaining);
27+
}
2328
}
2429
25-
setTimeout(next, 250);
30+
timeout = setTimeout(next, 250);
31+
32+
return () => clearTimeout(timeout);
2633
});
2734
</script>
2835

0 commit comments

Comments
 (0)