Skip to content

Commit d766716

Browse files
committed
Avoid uninitialized variable error in Duration component with Svelte 5
1 parent e3bbb08 commit d766716

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.changeset/chilly-donuts-brush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-ux': patch
3+
---
4+
5+
Avoid uninitialized variable error in Duration component with Svelte 5

packages/svelte-ux/src/lib/components/Duration.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
2121
const settingsClasses = getComponentClasses('Duration');
2222
23-
function getDelay() {
24-
const newDuration = getDuration(start, end ?? $timer, duration);
23+
function getDelay(useTimer = true) {
24+
const endTime = end ?? (useTimer ? $timer : null);
25+
const newDuration = getDuration(start, endTime, duration);
2526
2627
const unitsMoreThanSeconds = [
2728
newDuration?.years,
@@ -43,7 +44,8 @@
4344
}
4445
4546
const timer = timerStore({
46-
delay: getDelay(),
47+
// Pass false to avoid referencing `timer` before it exists
48+
delay: getDelay(false),
4749
disabled: end != null,
4850
onTick: () => {
4951
// Update delay based on display duration

0 commit comments

Comments
 (0)