From cbb22b18506bb831ddbe00acac22e73826ee078a Mon Sep 17 00:00:00 2001 From: gustrb Date: Mon, 30 Dec 2024 14:13:56 -0300 Subject: [PATCH 1/7] fix: invalidate the cache when we disconnect the socket --- .../client/hooks/useAppActionButtons.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/apps/meteor/client/hooks/useAppActionButtons.ts b/apps/meteor/client/hooks/useAppActionButtons.ts index b5796965b062..dd5d6b4f71c7 100644 --- a/apps/meteor/client/hooks/useAppActionButtons.ts +++ b/apps/meteor/client/hooks/useAppActionButtons.ts @@ -36,6 +36,26 @@ export const useAppActionButtons = [], ); + useEffect(() => { + if (!uid) { + return; + } + + // Setup Tracker to listen to Meteor's status changes + const statusTracker = Tracker.autorun(() => { + const isOffline = !Meteor.status().connected; + if (isOffline) { + // Invalidate cache when the user goes offline + invalidate(); + } + }); + + // Cleanup on unmount + return () => { + statusTracker.stop(); + }; + }, [uid, invalidate]); + useEffect(() => { if (!uid) { return; From 187a0885dc92e7e068cefc019c08025b6c870bed Mon Sep 17 00:00:00 2001 From: Gustavo Reis Bauer Date: Mon, 30 Dec 2024 14:22:36 -0300 Subject: [PATCH 2/7] Create eleven-pugs-help.md --- .changeset/eleven-pugs-help.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eleven-pugs-help.md diff --git a/.changeset/eleven-pugs-help.md b/.changeset/eleven-pugs-help.md new file mode 100644 index 000000000000..3179fbca2d76 --- /dev/null +++ b/.changeset/eleven-pugs-help.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +fixes an issue where inactive client would not be able to see app's action buttons that were added while they were disconnected. From 04d62fff09176c7000dc4f5287e1db1d872c57cc Mon Sep 17 00:00:00 2001 From: gustrb Date: Mon, 30 Dec 2024 14:30:50 -0300 Subject: [PATCH 3/7] chore: add import --- apps/meteor/client/hooks/useAppActionButtons.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/meteor/client/hooks/useAppActionButtons.ts b/apps/meteor/client/hooks/useAppActionButtons.ts index dd5d6b4f71c7..a9336be2cfa8 100644 --- a/apps/meteor/client/hooks/useAppActionButtons.ts +++ b/apps/meteor/client/hooks/useAppActionButtons.ts @@ -2,6 +2,7 @@ import { type IUIActionButton, type UIActionButtonContext } from '@rocket.chat/a import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks'; import { useEndpoint, useStream, useUserId } from '@rocket.chat/ui-contexts'; import { useQuery, useQueryClient } from '@tanstack/react-query'; +import { Tracker } from 'meteor/tracker'; import { useEffect } from 'react'; export const getIdForActionButton = ({ appId, actionId }: IUIActionButton): string => `${appId}/${actionId}`; From e6795fc6e68fc83d0090baf65e7944dec52c0c3a Mon Sep 17 00:00:00 2001 From: gustrb Date: Mon, 30 Dec 2024 15:53:29 -0300 Subject: [PATCH 4/7] chore: remove odd commend --- apps/meteor/client/hooks/useAppActionButtons.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/meteor/client/hooks/useAppActionButtons.ts b/apps/meteor/client/hooks/useAppActionButtons.ts index a9336be2cfa8..f490ac9c94f2 100644 --- a/apps/meteor/client/hooks/useAppActionButtons.ts +++ b/apps/meteor/client/hooks/useAppActionButtons.ts @@ -42,16 +42,14 @@ export const useAppActionButtons = return; } - // Setup Tracker to listen to Meteor's status changes + // Setup Tracker to listen to Meteor's status changes, so we can invalidate the query when the connection is lost const statusTracker = Tracker.autorun(() => { const isOffline = !Meteor.status().connected; if (isOffline) { - // Invalidate cache when the user goes offline invalidate(); } }); - // Cleanup on unmount return () => { statusTracker.stop(); }; From f7fb2c321f86e6e36ab6547fe19facd6019be381 Mon Sep 17 00:00:00 2001 From: gustrb Date: Thu, 9 Jan 2025 10:46:08 -0300 Subject: [PATCH 5/7] chore: use already existing hook --- .../client/hooks/useAppActionButtons.ts | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/apps/meteor/client/hooks/useAppActionButtons.ts b/apps/meteor/client/hooks/useAppActionButtons.ts index fd895ecb389b..8e1caf8d7769 100644 --- a/apps/meteor/client/hooks/useAppActionButtons.ts +++ b/apps/meteor/client/hooks/useAppActionButtons.ts @@ -1,15 +1,13 @@ import { type IUIActionButton, type UIActionButtonContext } from '@rocket.chat/apps-engine/definition/ui'; import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks'; -import { useEndpoint, useStream, useUserId } from '@rocket.chat/ui-contexts'; +import { useConnectionStatus, useEndpoint, useStream, useUserId } from '@rocket.chat/ui-contexts'; import { useQuery, useQueryClient } from '@tanstack/react-query'; -import { Tracker } from 'meteor/tracker'; import { useEffect } from 'react'; export const getIdForActionButton = ({ appId, actionId }: IUIActionButton): string => `${appId}/${actionId}`; export const useAppActionButtons = (context?: TContext) => { const queryClient = useQueryClient(); - const apps = useStream('apps'); const uid = useUserId(); @@ -43,23 +41,12 @@ export const useAppActionButtons = [], ); + const { status } = useConnectionStatus(); useEffect(() => { - if (!uid) { - return; + if (status !== 'connected') { + invalidate(); } - - // Setup Tracker to listen to Meteor's status changes, so we can invalidate the query when the connection is lost - const statusTracker = Tracker.autorun(() => { - const isOffline = !Meteor.status().connected; - if (isOffline) { - invalidate(); - } - }); - - return () => { - statusTracker.stop(); - }; - }, [uid, invalidate]); + }, [status, invalidate]); useEffect(() => { if (!uid) { From 37ba13d20ae401cd591e8c88ba60a193f7fdc163 Mon Sep 17 00:00:00 2001 From: gustrb Date: Thu, 9 Jan 2025 11:33:00 -0300 Subject: [PATCH 6/7] feat: use react-query props --- apps/meteor/client/hooks/useAppActionButtons.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/apps/meteor/client/hooks/useAppActionButtons.ts b/apps/meteor/client/hooks/useAppActionButtons.ts index 8e1caf8d7769..58173987308a 100644 --- a/apps/meteor/client/hooks/useAppActionButtons.ts +++ b/apps/meteor/client/hooks/useAppActionButtons.ts @@ -10,11 +10,13 @@ export const useAppActionButtons = const queryClient = useQueryClient(); const apps = useStream('apps'); const uid = useUserId(); + const { status } = useConnectionStatus(); const getActionButtons = useEndpoint('GET', '/apps/actionButtons'); const result = useQuery({ - queryKey: ['apps', 'actionButtons'], + queryKey: ['apps', 'actionButtons', status], + enabled: status === 'connected', queryFn: () => getActionButtons(), ...(context && { @@ -41,13 +43,6 @@ export const useAppActionButtons = [], ); - const { status } = useConnectionStatus(); - useEffect(() => { - if (status !== 'connected') { - invalidate(); - } - }, [status, invalidate]); - useEffect(() => { if (!uid) { return; From b6fef0eff3df098167be71c7758b4ef62ec0b235 Mon Sep 17 00:00:00 2001 From: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Thu, 9 Jan 2025 12:05:41 -0300 Subject: [PATCH 7/7] Update eleven-pugs-help.md --- .changeset/eleven-pugs-help.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/eleven-pugs-help.md b/.changeset/eleven-pugs-help.md index 3179fbca2d76..61acd79f600b 100644 --- a/.changeset/eleven-pugs-help.md +++ b/.changeset/eleven-pugs-help.md @@ -2,4 +2,4 @@ "@rocket.chat/meteor": patch --- -fixes an issue where inactive client would not be able to see app's action buttons that were added while they were disconnected. +Fixes an issue where losing connection could break app's action buttons