Skip to content

Commit

Permalink
Discard stale effect on RoomProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Jan 22, 2025
1 parent 95e28e1 commit 8040207
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
9 changes: 0 additions & 9 deletions apps/meteor/client/views/room/providers/RoomProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { useRouter } from '@rocket.chat/ui-contexts';
import type { ReactNode, ContextType, ReactElement } from 'react';
import { useMemo, memo, useEffect, useCallback } from 'react';

Expand Down Expand Up @@ -38,14 +37,6 @@ const RoomProvider = ({ rid, children }: RoomProviderProps): ReactElement => {

const resultFromLocal = useRoomQuery(rid);

// TODO: the following effect is a workaround while we don't have a general and definitive solution for it
const router = useRouter();
useEffect(() => {
if (resultFromLocal.isSuccess && !resultFromLocal.data) {
router.navigate('/home');
}
}, [resultFromLocal.data, resultFromLocal.isSuccess, resultFromServer, router]);

const subscriptionQuery = useReactiveQuery(subscriptionsQueryKeys.subscription(rid), () => Subscriptions.findOne({ rid }) ?? null);

useRedirectOnSettingsChanged(subscriptionQuery.data);
Expand Down
15 changes: 12 additions & 3 deletions apps/meteor/client/views/room/providers/hooks/useRoomQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ import { useQuery } from '@tanstack/react-query';
import { useEffect } from 'react';

import { Rooms } from '../../../../../app/models/client';
import { RoomNotFoundError } from '../../../../lib/errors/RoomNotFoundError';
import { queueMicrotask } from '../../../../lib/utils/queueMicrotask';

export function useRoomQuery(
rid: IRoom['_id'],
options?: UseQueryOptions<IRoom | null, Error, IRoom | null, readonly ['rooms', IRoom['_id']]>,
): UseQueryResult<IRoom | null, Error> {
options?: UseQueryOptions<IRoom, Error, IRoom, readonly ['rooms', IRoom['_id']]>,
): UseQueryResult<IRoom, Error> {
const queryKey = ['rooms', rid] as const;

const queryResult = useQuery({
queryKey,
queryFn: async (): Promise<IRoom | null> => Rooms.findOne({ _id: rid }, { reactive: false }) ?? null,
queryFn: async () => {
const room = Rooms.findOne({ _id: rid }, { reactive: false });

if (!room) {
throw new RoomNotFoundError(undefined, { rid });
}

return room;
},
staleTime: Infinity,
...options,
});
Expand Down

0 comments on commit 8040207

Please sign in to comment.