diff options
| author | 2026-03-31 08:59:58 +0800 | |
|---|---|---|
| committer | 2026-03-31 08:59:58 +0800 | |
| commit | 7adcf5b548b2638032f36957889711cf78dbf851 (patch) | |
| tree | 4eb14fef39aa0eabdd25b9a63e12be75a2181cb8 | |
| parent | 5f93323760fb46f06d391996f17e87b7405769d4 (diff) | |
| download | DropOut-fix/download-progress-bugs.tar.gz DropOut-fix/download-progress-bugs.zip | |
fix: resolve cleanup and formatBytes bugs in download progressfix/download-progress-bugs
| -rw-r--r-- | packages/ui/src/components/download-monitor.tsx | 2 | ||||
| -rw-r--r-- | packages/ui/src/components/instance-creation-modal.tsx | 5 | ||||
| -rw-r--r-- | packages/ui/src/stores/download-store.ts | 13 |
3 files changed, 16 insertions, 4 deletions
diff --git a/packages/ui/src/components/download-monitor.tsx b/packages/ui/src/components/download-monitor.tsx index 6916ca5..c6b3442 100644 --- a/packages/ui/src/components/download-monitor.tsx +++ b/packages/ui/src/components/download-monitor.tsx @@ -3,7 +3,7 @@ import { useDownloadStore } from "@/stores/download-store"; function formatBytes(bytes: number): string { if (bytes === 0) return "0 B"; - const units = ["B", "KB", "MB", "GB"]; + const units = ["B", "KB", "MB", "GB", "TB", "PB"]; const i = Math.floor(Math.log(bytes) / Math.log(1024)); const value = bytes / 1024 ** i; return `${value.toFixed(value < 10 ? 1 : 0)} ${units[i]}`; diff --git a/packages/ui/src/components/instance-creation-modal.tsx b/packages/ui/src/components/instance-creation-modal.tsx index 5b50513..e3fbf23 100644 --- a/packages/ui/src/components/instance-creation-modal.tsx +++ b/packages/ui/src/components/instance-creation-modal.tsx @@ -129,9 +129,8 @@ export function InstanceCreationModal({ open, onOpenChange }: Props) { downloadStore.init(); } return () => { - if (!open) { - downloadStore.cleanup(); - } + // Always cleanup event listeners when effect re-runs or unmounts + downloadStore.cleanup(); }; }, [open, downloadStore.init, downloadStore.cleanup]); diff --git a/packages/ui/src/stores/download-store.ts b/packages/ui/src/stores/download-store.ts index a33d79d..ccaf75a 100644 --- a/packages/ui/src/stores/download-store.ts +++ b/packages/ui/src/stores/download-store.ts @@ -160,6 +160,19 @@ export const useDownloadStore = create<DownloadState>((set, get) => ({ } unlisteners = []; initialized = false; + // Reset state on cleanup to avoid residual state + set({ + phase: "idle", + totalFiles: 0, + completedFiles: 0, + currentFile: "", + currentFileStatus: "", + currentFileDownloaded: 0, + currentFileTotal: 0, + totalDownloadedBytes: 0, + errorMessage: null, + phaseLabel: "", + }); }, reset: () => { |