From c5efc1ee9fc59bf91425b26e27fdc3a3c88f420b Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Mon, 24 Jul 2023 17:13:10 +0000 Subject: [PATCH] fix(site): fix error 'Reduce of empty array with no initial value' --- site/src/contexts/useProxyLatency.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/site/src/contexts/useProxyLatency.ts b/site/src/contexts/useProxyLatency.ts index 4ef0d8a4bdea7..5c5934acb4851 100644 --- a/site/src/contexts/useProxyLatency.ts +++ b/site/src/contexts/useProxyLatency.ts @@ -98,7 +98,11 @@ export const useProxyLatency = ( // This prevents fetching latencies too often. // 1. Fetch the latest stored latency for the given proxy. // 2. If the latest latency is after the latestFetchRequest, then skip the latency check. - if (storedLatencies && storedLatencies[proxy.id]) { + if ( + storedLatencies && + storedLatencies[proxy.id] && + storedLatencies[proxy.id].length > 0 + ) { const fetchRequestDate = new Date(latestFetchRequest) const latest = storedLatencies[proxy.id].reduce((prev, next) => prev.at > next.at ? prev : next,