Skip to content

Avoid uninitialized variable error in Duration component with Svelte 5 #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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