From ac973a4b2c2686ac4bfb58c290efd44f7fb72890 Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Mon, 24 Jul 2023 14:17:27 -0300 Subject: [PATCH] fix(site): fix error 'Reduce of empty array with no initial value' (#8700) --- 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 4ef0d8a4bd..5c5934acb4 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,