diff --git a/lib/core/providers/app_providers.dart b/lib/core/providers/app_providers.dart index 0714794..b81f6bc 100644 --- a/lib/core/providers/app_providers.dart +++ b/lib/core/providers/app_providers.dart @@ -239,7 +239,10 @@ class SocketServiceManager extends _$SocketServiceManager { appSettingsProvider.select((settings) => settings.socketTransportMode), ); final websocketOnly = transportMode == 'ws'; - final token = ref.watch(authTokenProvider3); + + // Don't watch authTokenProvider3 here to avoid rebuilding on token changes + // Token updates are handled via the subscription below + final token = ref.read(authTokenProvider3); final requiresNewService = _service == null || diff --git a/lib/core/services/socket_service.dart b/lib/core/services/socket_service.dart index 089bd40..1a8eced 100644 --- a/lib/core/services/socket_service.dart +++ b/lib/core/services/socket_service.dart @@ -222,7 +222,9 @@ class SocketService with WidgetsBindingObserver { if (socket == null) return; socket + ..off('events', _handleChatEvent) ..off('chat-events', _handleChatEvent) + ..off('events:channel', _handleChannelEvent) ..off('channel-events', _handleChannelEvent) ..off('connect', _handleConnect) ..off('connect_error', _handleConnectError) @@ -232,7 +234,9 @@ class SocketService with WidgetsBindingObserver { ..off('disconnect', _handleDisconnect); socket + ..on('events', _handleChatEvent) ..on('chat-events', _handleChatEvent) + ..on('events:channel', _handleChannelEvent) ..on('channel-events', _handleChannelEvent) ..on('connect', _handleConnect) ..on('connect_error', _handleConnectError)