From ed5dad788fea7ff5ad2f4247bad68f7a5a396718 Mon Sep 17 00:00:00 2001 From: Wes Date: Mon, 27 Apr 2026 17:49:08 -0600 Subject: [PATCH] fix: close race window that dropped active channel messages (#410) Co-authored-by: Claude Opus 4.6 --- .../src/features/channels/useLiveChannelUpdates.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/desktop/src/features/channels/useLiveChannelUpdates.ts b/desktop/src/features/channels/useLiveChannelUpdates.ts index 40f23f90b..01ae9d20f 100644 --- a/desktop/src/features/channels/useLiveChannelUpdates.ts +++ b/desktop/src/features/channels/useLiveChannelUpdates.ts @@ -133,17 +133,18 @@ export function useLiveChannelUpdates( // when the user is already viewing the DM. handleDmEvent(event); - if (channelId === activeChannelId) { - return; - } - if (!liveChannelIds.has(channelId)) { - void queryClient.invalidateQueries({ queryKey: channelsQueryKey }); + if (channelId !== activeChannelId) { + void queryClient.invalidateQueries({ queryKey: channelsQueryKey }); + } return; } + // Always update the cache — even for the active channel. + // useChannelSubscription also writes to this cache, but there's a + // race window where it hasn't connected yet. Writes are idempotent + // (mergeTimelineCacheMessages deduplicates by event ID). const messageTimestamp = getMessageTimestamp(event); - updateChannelLastMessageAt(queryClient, channelId, messageTimestamp); queryClient.setQueryData( channelMessagesKey(channelId),