Skip to content

Commit

Permalink
Fix issue where a navigation cancellation leaves the progress-bar han…
Browse files Browse the repository at this point in the history
…ging

Should fix Having navigation fail/cancel leaves progressbar hanging #5.
  • Loading branch information
allezxandre committed Nov 12, 2024
1 parent 8d6aa7d commit 8122290
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"homepage": "https://github.com/prgm-dev/sveltekit-progress-bar#readme",
"license": "MIT",
"version": "3.0.0",
"version": "3.0.1-next.1",
"repository": {
"type": "git",
"url": "git+https://github.com/prgm-dev/sveltekit-progress-bar.git"
Expand Down
21 changes: 10 additions & 11 deletions src/lib/ProgressBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<svelte:options runes={true} />

<script lang="ts">
import { afterNavigate, beforeNavigate } from "$app/navigation";
import { beforeNavigate } from "$app/navigation";
// This component is a modified version of the component from the following repo:
// https://github.com/saibotsivad/svelte-progress-bar
Expand Down Expand Up @@ -245,9 +245,8 @@
`view-transition-name: ${viewTransitionName}-leader;`,
);
let progressBarStartTimeout = $state<ReturnType<typeof setTimeout> | null>(
null,
);
let progressBarStartTimeout: ReturnType<typeof setTimeout> | null = null;
beforeNavigate((nav) => {
if (progressBarStartTimeout) {
clearTimeout(progressBarStartTimeout);
Expand All @@ -265,15 +264,15 @@
displayThresholdMs,
);
} else start();
}
});
afterNavigate(() => {
if (progressBarStartTimeout) {
clearTimeout(progressBarStartTimeout);
progressBarStartTimeout = null;
nav.complete.catch().finally(() => {
if (progressBarStartTimeout) {
clearTimeout(progressBarStartTimeout);
progressBarStartTimeout = null;
}
complete();
});
}
complete();
});
</script>

Expand Down

0 comments on commit 8122290

Please sign in to comment.