refactor(app): replace providers-snapshot invalidate with refetchIfStale

invalidate() flagged the query stale and kicked off a refetch unconditionally,
causing a loading flash every time the model selector opened. Expose
refetchIfStale() instead so callers only refetch when data is actually stale.
This commit is contained in:
Mohamed Boudra
2026-04-18 16:03:13 +07:00
parent 5d76cc8840
commit 72e4476acc
4 changed files with 17 additions and 19 deletions
@@ -27,7 +27,7 @@ interface UseProvidersSnapshotResult {
error: string | null;
supportsSnapshot: boolean;
refresh: (providers?: AgentProvider[]) => Promise<void>;
invalidate: () => void;
refetchIfStale: () => void;
}
export function useProvidersSnapshot(
@@ -99,8 +99,8 @@ export function useProvidersSnapshot(
[refreshSnapshot],
);
const invalidate = useCallback(() => {
void queryClient.invalidateQueries({ queryKey });
const refetchIfStale = useCallback(() => {
void queryClient.refetchQueries({ queryKey, type: "active", stale: true });
}, [queryClient, queryKey]);
return {
@@ -111,7 +111,7 @@ export function useProvidersSnapshot(
error: snapshotQuery.error instanceof Error ? snapshotQuery.error.message : null,
supportsSnapshot,
refresh,
invalidate,
refetchIfStale,
};
}