Skip to content

Commit

Permalink
fix: cleanup timeout to prevent leak (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored Oct 31, 2023
1 parent 0a700a2 commit d7d71ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-pots-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/site-kit': patch
---

fix: cleanup timeout to prevent leak
11 changes: 9 additions & 2 deletions packages/site-kit/src/lib/nav/PreloadingIndicator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
let visible = false;
onMount(() => {
/** @type {any} */
let timeout;
function next() {
visible = true;
Expand All @@ -19,10 +22,14 @@
duration: remaining + 0.1 > 0.15 ? 250 : 500 / remaining
});
if (remaining > 0.15) setTimeout(next, 500 / remaining);
if (remaining > 0.15) {
timeout = setTimeout(next, 500 / remaining);
}
}
setTimeout(next, 250);
timeout = setTimeout(next, 250);
return () => clearTimeout(timeout);
});
</script>

Expand Down

0 comments on commit d7d71ce

Please sign in to comment.