From 6202f9f69efa19492c263796331da753f0454e44 Mon Sep 17 00:00:00 2001 From: ashim-hq Date: Sun, 19 Apr 2026 21:20:01 +0800 Subject: [PATCH] fix: prevent progress bar from jumping backwards during install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- apps/web/src/stores/features-store.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/web/src/stores/features-store.ts b/apps/web/src/stores/features-store.ts index ce89a843..d3ce7487 100644 --- a/apps/web/src/stores/features-store.ts +++ b/apps/web/src/stores/features-store.ts @@ -68,7 +68,14 @@ export const useFeaturesStore = create((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((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 {}