refactor(useDraftSocket): clean up reconnect event handling

- Remove redundant reconnect_attempt listener: connect_error already
  sets isReconnecting(true), and connectionError is never set before
  reconnect_attempt fires, making that handler a no-op
- Wrap reconnect_failed in an Error object so Sentry receives a proper
  exception with stack trace instead of a plain captureMessage string
- Store handleReconnectFailed as a named reference so socket.io.off()
  removes only this listener rather than all reconnect_failed listeners

https://claude.ai/code/session_01TpZ9W111Trkv2g4CkCWFpB
This commit is contained in:
Claude 2026-05-19 22:19:10 +00:00
parent 28b89b3444
commit 5742b780fe
No known key found for this signature in database

View file

@ -72,17 +72,13 @@ export function useDraftSocket(seasonId: string, teamId?: string): UseDraftSocke
setIsReconnecting(true); setIsReconnecting(true);
}); });
socket.io.on("reconnect_attempt", () => { const handleReconnectFailed = () => {
logger.log("Attempting to reconnect..."); logger.error(new Error("Socket.IO reconnection failed after max attempts"));
setIsReconnecting(true);
setConnectionError(null);
});
socket.io.on("reconnect_failed", () => {
logger.error("Reconnection failed");
setConnectionError("Failed to reconnect. Please refresh the page."); setConnectionError("Failed to reconnect. Please refresh the page.");
setIsReconnecting(false); setIsReconnecting(false);
}); };
socket.io.on("reconnect_failed", handleReconnectFailed);
const handleOffline = () => { const handleOffline = () => {
// Mark as reconnecting immediately — the OS fires this before Socket.IO's // Mark as reconnecting immediately — the OS fires this before Socket.IO's
@ -119,8 +115,7 @@ export function useDraftSocket(seasonId: string, teamId?: string): UseDraftSocke
document.addEventListener("visibilitychange", handleVisibilityChange); document.addEventListener("visibilitychange", handleVisibilityChange);
return () => { return () => {
socket.io.off("reconnect_attempt"); socket.io.off("reconnect_failed", handleReconnectFailed);
socket.io.off("reconnect_failed");
window.removeEventListener("offline", handleOffline); window.removeEventListener("offline", handleOffline);
window.removeEventListener("online", handleReturn); window.removeEventListener("online", handleReturn);
document.removeEventListener("visibilitychange", handleVisibilityChange); document.removeEventListener("visibilitychange", handleVisibilityChange);