fix: prevent progress bar from jumping backwards during install

The store set an initial 5% optimistically, then SSE sent real progress
starting from 0%, causing the bar to visibly drop. Now progress only
moves forward — both SSE and polling paths use Math.max to never
regress below the current value.
This commit is contained in:
ashim-hq
2026-04-19 21:20:01 +08:00
parent e4a73210ac
commit 6202f9f69e
+11 -2
View File
@@ -68,7 +68,14 @@ export const useFeaturesStore = create<FeaturesState>((set, get) => {
}
resolveCompletion(bundleId);
} else if (updated.progress) {
set({ installing: { ...get().installing, [bundleId]: updated.progress } });
const current = get().installing[bundleId];
const percent = Math.max(updated.progress.percent, current?.percent ?? 0);
set({
installing: {
...get().installing,
[bundleId]: { percent, stage: updated.progress.stage },
},
});
}
} catch {}
}, 3000);
@@ -106,10 +113,12 @@ export const useFeaturesStore = create<FeaturesState>((set, get) => {
resolveCompletion(bundleId);
return;
}
const current = get().installing[bundleId];
const percent = Math.max(data.percent, current?.percent ?? 0);
set({
installing: {
...get().installing,
[bundleId]: { percent: data.percent, stage: data.stage },
[bundleId]: { percent, stage: data.stage },
},
});
} catch {}