Skip to content

Commit

Permalink
Avoid uninitialized variable error in Duration component with Svelte 5
Browse files Browse the repository at this point in the history
  • Loading branch information
dimfeld committed Jul 31, 2024
1 parent e3bbb08 commit d766716
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-donuts-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': patch
---

Avoid uninitialized variable error in Duration component with Svelte 5
8 changes: 5 additions & 3 deletions packages/svelte-ux/src/lib/components/Duration.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
const settingsClasses = getComponentClasses('Duration');
function getDelay() {
const newDuration = getDuration(start, end ?? $timer, duration);
function getDelay(useTimer = true) {
const endTime = end ?? (useTimer ? $timer : null);
const newDuration = getDuration(start, endTime, duration);
const unitsMoreThanSeconds = [
newDuration?.years,
Expand All @@ -43,7 +44,8 @@
}
const timer = timerStore({
delay: getDelay(),
// Pass false to avoid referencing `timer` before it exists
delay: getDelay(false),
disabled: end != null,
onTick: () => {
// Update delay based on display duration
Expand Down

0 comments on commit d766716

Please sign in to comment.