From 40457bd68a4044b2097b79252908ad7c5c26437b Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Thu, 8 Aug 2024 13:08:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20avoid=20unnecessary=20?= =?UTF-8?q?refetches=20of=20room's=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LiveKit access tokens are valid for 6 hours after generation. Without a `staleTime` set, room data becomes stale immediately (0 milliseconds), causing unnecessary refetches, particularly when users switch focus back to the call window. This issue led to an excessive number of "get room" events, as observed in the analytics. For example, during a meeting, if a user switches tabs and then returns, the room data would be refetched despite the access token still being valid. By adding a `staleTime` aligned with the token's validity, we avoid unnecessary network requests. --- src/frontend/src/features/rooms/components/Conference.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/frontend/src/features/rooms/components/Conference.tsx b/src/frontend/src/features/rooms/components/Conference.tsx index a1ec0dac..1efecd2c 100644 --- a/src/frontend/src/features/rooms/components/Conference.tsx +++ b/src/frontend/src/features/rooms/components/Conference.tsx @@ -49,6 +49,7 @@ export const Conference = ({ data, } = useQuery({ queryKey: fetchKey, + staleTime: 6 * 60 * 60 * 1000, // By default, LiveKit access tokens expire 6 hours after generation enabled: !initialRoomData, initialData: initialRoomData, queryFn: () =>