Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/reconnect-thread-sync-invalidation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes React Query cache not being invalidated on DDP reconnection, causing open thread panels and infinite message lists to not refresh with missed messages after a reconnect.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { useConnectionStatus } from '@rocket.chat/ui-contexts';
import { useQueryClient } from '@tanstack/react-query';
import { useEffect, useRef } from 'react';

import { LegacyRoomManager, upsertMessage } from '../../../../app/ui-utils/client';
import { roomsQueryKeys } from '../../../lib/queryKeys';
import { callWithErrorHandling } from '../../../lib/utils/callWithErrorHandling';
import { Messages, Subscriptions } from '../../../stores';

Expand Down Expand Up @@ -41,17 +43,19 @@ const loadMissedMessages = async (rid: IRoom['_id']): Promise<void> => {
export const useLoadMissedMessages = (): void => {
const { connected } = useConnectionStatus();
const connectionWasOnlineRef = useRef(connected);
const queryClient = useQueryClient();

useEffect(() => {
if (connected === true && connectionWasOnlineRef.current === false && LegacyRoomManager.openedRooms) {
Object.keys(LegacyRoomManager.openedRooms).forEach((key) => {
const value = LegacyRoomManager.openedRooms[key];
if (value.rid) {
loadMissedMessages(value.rid);
queryClient.invalidateQueries({ queryKey: roomsQueryKeys.room(value.rid) });
}
});
}

connectionWasOnlineRef.current = connected;
}, [connected]);
}, [connected, queryClient]);
};