Problem
SocketProvider registers 'connect' and 'disconnect' listeners both in the initial useEffect (when autoConnect is true) and again in the connect() method. If connect() is invoked multiple times or the effect reruns, duplicate listeners accumulate.
Why it matters
Duplicate listeners cause duplicated side-effects (multiple state updates, duplicated logs), possible memory leaks, and make debugging connection behavior difficult.
Affected files
- src/components/providers/SocketProvider.tsx (useEffect and connect(), lines ~32-44 and ~53-61)
Suggested fix
- Ensure listeners are registered only once. Options:
- Move listener registration to SocketManager.connect() so provider doesn't add listeners on each connect.
- Track a "listenersRegistered" flag in provider or SocketManager and avoid re-registering.
- Remove existing handlers before adding (socket.off(...)).
Notes
Add tests or manual verification to ensure repeated connect calls don't add duplicate handlers.
Problem
SocketProvider registers 'connect' and 'disconnect' listeners both in the initial useEffect (when autoConnect is true) and again in the connect() method. If connect() is invoked multiple times or the effect reruns, duplicate listeners accumulate.
Why it matters
Duplicate listeners cause duplicated side-effects (multiple state updates, duplicated logs), possible memory leaks, and make debugging connection behavior difficult.
Affected files
Suggested fix
Notes
Add tests or manual verification to ensure repeated connect calls don't add duplicate handlers.