@@ -188,6 +188,7 @@ const ProxyMenu: FC<{ proxyContextValue: ProxyContextValue }> = ({
188188} ) => {
189189 const buttonRef = useRef < HTMLButtonElement > ( null )
190190 const [ isOpen , setIsOpen ] = useState ( false )
191+ const [ refetchDate , setRefetchDate ] = useState < Date > ( )
191192 const selectedProxy = proxyContextValue . proxy . proxy
192193 const refreshLatencies = proxyContextValue . refetchProxyLatencies
193194 const closeMenu = ( ) => setIsOpen ( false )
@@ -196,6 +197,26 @@ const ProxyMenu: FC<{ proxyContextValue: ProxyContextValue }> = ({
196197 const isLoadingLatencies = Object . keys ( latencies ) . length === 0
197198 const isLoading = proxyContextValue . isLoading || isLoadingLatencies
198199 const permissions = usePermissions ( )
200+ const proxyLatencyLoading = ( proxy : TypesGen . Region ) : boolean => {
201+ if ( ! refetchDate ) {
202+ // Only show loading if the user manually requested a refetch
203+ return false
204+ }
205+
206+ const latency = latencies ?. [ proxy . id ]
207+ // Only show a loading spinner if:
208+ // - A latency exists. This means the latency was fetched at some point, so the
209+ // loader *should* be resolved.
210+ // - The proxy is healthy. If it is not, the loader might never resolve.
211+ // - The latency reported is older than the refetch date. This means the latency
212+ // is stale and we should show a loading spinner until the new latency is
213+ // fetched.
214+ if ( proxy . healthy && latency && latency . at < refetchDate ) {
215+ return true
216+ }
217+
218+ return false
219+ }
199220
200221 if ( isLoading ) {
201222 return (
@@ -234,6 +255,7 @@ const ProxyMenu: FC<{ proxyContextValue: ProxyContextValue }> = ({
234255 { selectedProxy . display_name }
235256 < ProxyStatusLatency
236257 latency = { latencies ?. [ selectedProxy . id ] ?. latencyMS }
258+ isLoading = { proxyLatencyLoading ( selectedProxy ) }
237259 />
238260 </ Box >
239261 ) : (
@@ -277,7 +299,10 @@ const ProxyMenu: FC<{ proxyContextValue: ProxyContextValue }> = ({
277299 />
278300 </ Box >
279301 { proxy . display_name }
280- < ProxyStatusLatency latency = { latencies ?. [ proxy . id ] ?. latencyMS } />
302+ < ProxyStatusLatency
303+ latency = { latencies ?. [ proxy . id ] ?. latencyMS }
304+ isLoading = { proxyLatencyLoading ( proxy ) }
305+ />
281306 </ Box >
282307 </ MenuItem >
283308 ) ) }
@@ -298,7 +323,8 @@ const ProxyMenu: FC<{ proxyContextValue: ProxyContextValue }> = ({
298323 // Stop the menu from closing
299324 e . stopPropagation ( )
300325 // Refresh the latencies.
301- refreshLatencies ( )
326+ const refetchDate = refreshLatencies ( )
327+ setRefetchDate ( refetchDate )
302328 } }
303329 >
304330 Refresh Latencies
0 commit comments