From ba33790d363a28452937042796f8587c76d1d172 Mon Sep 17 00:00:00 2001 From: master <> Date: Sun, 29 Mar 2026 01:03:43 +0200 Subject: [PATCH] Fix pack store: don't cache empty fallback results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs caused the empty packs page: 1. When the API failed, catchError returned [] and writeCache() stored it in sessionStorage. On next visit, readCache() returned [] (truthy), so the store never re-fetched from the API — stuck on empty forever. 2. Fix: only cache successful non-empty API responses. Treat empty cached arrays as cache misses so the store always re-fetches. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../features/policy-studio/services/policy-pack.store.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Web/StellaOps.Web/src/app/features/policy-studio/services/policy-pack.store.ts b/src/Web/StellaOps.Web/src/app/features/policy-studio/services/policy-pack.store.ts index bfc838923..a2f2d9816 100644 --- a/src/Web/StellaOps.Web/src/app/features/policy-studio/services/policy-pack.store.ts +++ b/src/Web/StellaOps.Web/src/app/features/policy-studio/services/policy-pack.store.ts @@ -74,7 +74,9 @@ export class PolicyPackStore { .subscribe((packs) => { this.usingFallback = fetchedFromFallback; this.packs$.next(packs); - this.writeCache(packs); + if (!fetchedFromFallback && packs.length > 0) { + this.writeCache(packs); + } }); } @@ -95,7 +97,8 @@ export class PolicyPackStore { try { const raw = sessionStorage.getItem(this.cacheKey); if (!raw) return null; - return JSON.parse(raw) as PolicyPackSummary[]; + const parsed = JSON.parse(raw) as PolicyPackSummary[]; + return Array.isArray(parsed) && parsed.length > 0 ? parsed : null; } catch { return null; }