Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep the chat list when a background refetch fails

Yudhi Armyndharis39d7717c9ad2
diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.ts
index 8e70210b5..f9717ef54 100644
--- a/dashboard/src/pages/Chats.test.ts
+++ b/dashboard/src/pages/Chats.test.ts
@@ -998,6 +998,30 @@ test('a chat list refetch lands while a newer one is out, and an older answer ne
assert.ok(!screen.queryByText('carol v2'), 'an older answer replaced the newer list');
});
+test('a failed background refetch keeps the chat list and raises no error', async () => {
+ const { screen } = rtl;
+ renderChats();
+ await screen.findByText('Alice');
+
+ chatsResponder = () => Promise.resolve(jsonResponse({ message: 'gateway timeout' }, 504));
+ const socket = lastSocket();
+ assert.ok(socket, 'expected the page to have opened a socket');
+ socket.receive('message', {
+ type: 'event',
+ timestamp: new Date(1_700_003_000_000).toISOString(),
+ payload: {
+ event: 'message.edited',
+ sessionId: SESSION.id,
+ data: { messageId: 'wamid.carol.1', chatId: CHAT_2.id, body: 'edited', timestamp: 1_700_003_000 },
+ },
+ });
+ await flush();
+ await flush();
+
+ assert.ok(screen.queryByText('Alice'), 'a failed background refetch emptied the chat list');
+ assert.ok(!screen.queryByText('Failed to load chats'), 'a failed background refetch raised an error toast');
+});
+
test('every message for a chat the sidebar does not list refetches the list, and the chat appears', async () => {
const { screen, waitFor } = rtl;
renderChats();
diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsx
index 4f30db393..a12bce6cb 100644
--- a/dashboard/src/pages/Chats.tsx
+++ b/dashboard/src/pages/Chats.tsx
@@ -330,7 +330,8 @@ export function Chats() {
const sorted = [...data].sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0));
setChats(sorted);
} catch (err) {
- if (stale()) return;
+ // A background refetch only refreshes summaries: keep the list it would have replaced.
+ if (stale() || background) return;
showLoadError('chats.errors.loadChats', err);
setChats([]);
} finally {