revert this too make PR easier.

This commit is contained in:
Steven T. Cramer 2025-06-13 16:23:26 +07:00
parent a25adf8bbe
commit 814d07dcca

View file

@ -70,20 +70,12 @@ export function useEventSource({ url, withCredentials, onMessage }: UseEventSour
// Clean up current connection.
cleanup()
// Attempt to reconnect after a delay with a simple backoff, with a maximum retry limit.
if (!sourceRef.current) {
return;
}
const retryCount = (sourceRef.current.retryCount || 0) + 1;
sourceRef.current.retryCount = retryCount;
if (retryCount > 5) {
return;
}
// Attempt to reconnect after a delay.
reconnectTimeoutRef.current = setTimeout(() => {
if (!isUnmountedRef.current) {
createEventSource()
}
}, 1000 * retryCount) // Exponential backoff: 1s, 2s, 3s, etc.
}, 1000)
}
}, [url, withCredentials, handleMessage, cleanup])