Bug: Server state not updating when switching servers #69

Closed
opened 2026-04-26 16:46:24 +00:00 by icub3d · 0 comments
Owner

Migrated from GitHub issue icub3d/decentcom#97
Original Author: @icub3d
Original Date: 2026-04-18T22:18:09Z


Overview

When a user clicks a different server in the sidebar, the application updates the UI to show the new server name but does not actually switch the connection or update the channels and messages to reflect the new server's state. The app remains connected to the previous server.

Background

The shouldAutoConnect logic in client/src/hooks/useAccountManager.ts was preventing new connections if the application was already in a connected state, even if the target server changed. Additionally, useServerStore.connect did not explicitly disconnect from the previous server when a new connection was requested.

Requirements

  • shouldAutoConnect should allow connection if the target server differs from the current address.
  • useServerStore.connect should disconnect from the current server before connecting to a new one if the address is different.
  • All server-specific state (channels, roles, members, messages) should be cleared upon switching servers.
  • The WebSocket gateway should be closed and re-opened for the new server.

Design

  • Modify client/src/hooks/useAccountManager.ts to include current address in comparison.
  • Update client/src/App.tsx to pass the address to the hook.
  • Update client/src/stores/serverStore.ts to call disconnect() at the start of connect() when switching addresses.

Task List

  • Update shouldAutoConnect logic to handle server switching.
  • Pass current address to shouldAutoConnect in App.tsx.
  • Update serverStore.connect to handle cleanup of previous connections.
  • Verify with tests.

Test List

  • Unit test for shouldAutoConnect with different server addresses.
  • Manual verification of server switching between Open, Private, and Strict test servers.
**Migrated from GitHub issue icub3d/decentcom#97** **Original Author:** @icub3d **Original Date:** 2026-04-18T22:18:09Z --- ## Overview When a user clicks a different server in the sidebar, the application updates the UI to show the new server name but does not actually switch the connection or update the channels and messages to reflect the new server's state. The app remains connected to the previous server. ## Background The `shouldAutoConnect` logic in `client/src/hooks/useAccountManager.ts` was preventing new connections if the application was already in a `connected` state, even if the target server changed. Additionally, `useServerStore.connect` did not explicitly disconnect from the previous server when a new connection was requested. ## Requirements - [x] `shouldAutoConnect` should allow connection if the target server differs from the current address. - [x] `useServerStore.connect` should disconnect from the current server before connecting to a new one if the address is different. - [x] All server-specific state (channels, roles, members, messages) should be cleared upon switching servers. - [x] The WebSocket gateway should be closed and re-opened for the new server. ## Design - Modify `client/src/hooks/useAccountManager.ts` to include current address in comparison. - Update `client/src/App.tsx` to pass the address to the hook. - Update `client/src/stores/serverStore.ts` to call `disconnect()` at the start of `connect()` when switching addresses. ## Task List - [x] Update `shouldAutoConnect` logic to handle server switching. - [x] Pass current address to `shouldAutoConnect` in `App.tsx`. - [x] Update `serverStore.connect` to handle cleanup of previous connections. - [x] Verify with tests. ## Test List - [x] Unit test for `shouldAutoConnect` with different server addresses. - [x] Manual verification of server switching between Open, Private, and Strict test servers.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
icub3d/decentcom#69
No description provided.