From 5c58fb92acabfd043b7f8b5d4a6efc48df9a18c6 Mon Sep 17 00:00:00 2001 From: shrimbly Date: Mon, 2 Mar 2026 21:05:27 +1300 Subject: [PATCH] fix: cache availableProviders so filter icons show on cached responses The server-reported availableProviders were only set on fresh API calls. When models were served from localStorage cache, the provider filter icons reverted to only showing Gemini/fal.ai. Now availableProviders is stored in and restored from the model cache. Co-Authored-By: Claude Opus 4.6 --- src/components/modals/ModelSearchDialog.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/modals/ModelSearchDialog.tsx b/src/components/modals/ModelSearchDialog.tsx index b2b808db..70a9c666 100644 --- a/src/components/modals/ModelSearchDialog.tsx +++ b/src/components/modals/ModelSearchDialog.tsx @@ -14,6 +14,7 @@ const MODELS_CACHE_TTL = 48 * 60 * 60 * 1000; // 48 hours interface ModelsCacheEntry { models: ProviderModel[]; + availableProviders?: string[]; timestamp: number; } @@ -30,10 +31,10 @@ function getCachedModels(cacheKey: string): ModelsCacheEntry | null { return null; } -function setCachedModels(cacheKey: string, models: ProviderModel[]) { +function setCachedModels(cacheKey: string, models: ProviderModel[], availableProviders?: string[]) { try { const cache = JSON.parse(localStorage.getItem(MODELS_CACHE_KEY) || "{}"); - cache[cacheKey] = { models, timestamp: Date.now() }; + cache[cacheKey] = { models, availableProviders, timestamp: Date.now() }; localStorage.setItem(MODELS_CACHE_KEY, JSON.stringify(cache)); } catch { // Ignore cache errors @@ -183,6 +184,9 @@ export function ModelSearchDialog({ const cached = getCachedModels(cacheKey); if (cached) { setModels(cached.models); + if (cached.availableProviders) { + setServerAvailableProviders(cached.availableProviders); + } return; } } @@ -242,8 +246,8 @@ export function ModelSearchDialog({ if (data.success && data.models) { setModels(data.models); - // Cache the successful result - setCachedModels(cacheKey, data.models); + // Cache the successful result (including available providers) + setCachedModels(cacheKey, data.models, data.availableProviders); // Update server-reported available providers if (data.availableProviders) { setServerAvailableProviders(data.availableProviders);