Fix pack store: don't cache empty fallback results
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user