fix: close race window that dropped active channel messages (#410)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Wes
2026-04-27 16:49:08 -07:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 5a93403858
commit ed5dad788f
@@ -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<RelayEvent[]>(
channelMessagesKey(channelId),