Skip to content

Fix reconnecting dialog refreshing page repeatedly#61

Merged
JoshuaAFerguson merged 1 commit into
mainfrom
claude/fix-reconnect-dialog-refresh-01KBMnPyRvp8bv5Kv133W4k5
Nov 17, 2025
Merged

Fix reconnecting dialog refreshing page repeatedly#61
JoshuaAFerguson merged 1 commit into
mainfrom
claude/fix-reconnect-dialog-refresh-01KBMnPyRvp8bv5Kv133W4k5

Conversation

@JoshuaAFerguson

Copy link
Copy Markdown
Member

Fixed critical issue where WebSocket reconnection logic created a rapid reconnection loop, making the UI appear to "refresh every second" and become completely unusable.

Changes:

  • Fixed dependency loop in useWebSocket hook by using ref for reconnect attempts
  • Removed reconnectAttempts from connect() callback dependencies
  • Improved countdown timer in EnhancedWebSocketStatus to be more efficient
  • Made reconnect banner dismissal persistent across reconnection attempts
  • Reduced notification spam when banner is dismissed

Root cause: The connect() callback depended on reconnectAttempts state, which changed on every reconnection attempt. This triggered the useEffect to close and immediately reconnect, creating a loop.

Testing: Code review confirmed proper use of refs to break dependency cycle. The reconnection logic now only triggers on genuine WebSocket close events, not on state changes.

Fixed critical issue where WebSocket reconnection logic created a rapid
reconnection loop, making the UI appear to "refresh every second" and
become completely unusable.

Changes:
- Fixed dependency loop in useWebSocket hook by using ref for reconnect attempts
- Removed reconnectAttempts from connect() callback dependencies
- Improved countdown timer in EnhancedWebSocketStatus to be more efficient
- Made reconnect banner dismissal persistent across reconnection attempts
- Reduced notification spam when banner is dismissed

Root cause: The connect() callback depended on reconnectAttempts state,
which changed on every reconnection attempt. This triggered the useEffect
to close and immediately reconnect, creating a loop.

Testing: Code review confirmed proper use of refs to break dependency cycle.
The reconnection logic now only triggers on genuine WebSocket close events,
not on state changes.
@JoshuaAFerguson JoshuaAFerguson merged commit 31e7f99 into main Nov 17, 2025
9 of 23 checks passed
JoshuaAFerguson pushed a commit that referenced this pull request Nov 17, 2025
The WebSocket reconnection dialog was causing an infinite reconnection
loop that made the UI unusable. This was happening because:

1. WebSocket callback functions were being recreated on every render
2. When callbacks changed, the WebSocket hooks saw them as new dependencies
3. This triggered WebSocket disconnection and reconnection
4. State updates from reconnection triggered component re-renders
5. Back to step 1, creating an infinite loop

Fixed by:
- Using useRef to store WebSocket callbacks in both useWebSocket and
  useEnterpriseWebSocket hooks
- Updating refs when callbacks change instead of recreating connections
- Wrapping callbacks in useCallback in Dashboard, SessionViewer, and
  SharedSessions pages (defense in depth)
- Removing callback dependencies from WebSocket connect() functions

This ensures that callback changes don't trigger reconnection, breaking
the loop and making the UI stable again.

Fixes reconnection issues from PRs #60 and #61.
@JoshuaAFerguson JoshuaAFerguson deleted the claude/fix-reconnect-dialog-refresh-01KBMnPyRvp8bv5Kv133W4k5 branch November 17, 2025 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants