Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): re-read the chat page's sessions when it is shown

Yudhi Armyndharisa2d9866ed8f5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e306e77c3..4c24e2ec5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Answer `400` to a NUL character in `q` on `GET /api/search`, which failed with `500` on PostgreSQL.
- Make the deleted-message and omitted-media labels in outgoing dashboard chat bubbles readable in dark mode.
- Match the dashboard New chat search against contact numbers only when the query reads as a phone number, so a name with a digit no longer lists every contact whose number holds that digit.
+- Read the dashboard Chats page's session list again when the page is shown, so a session deleted elsewhere no longer stays open.
## [0.26.0] - 2026-10-28
diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.ts
index 13479b0ac..e2ab99d2b 100644
--- a/dashboard/src/pages/Chats.features.test.ts
+++ b/dashboard/src/pages/Chats.features.test.ts
@@ -1251,6 +1251,31 @@ test('an open session deleted on the server with no other one ready leaves none
assert.equal(container.querySelector('.session-switcher') === null, true);
});
+test('an open session deleted with no status frame gives way once the page is shown again', async () => {
+ const { screen, fireEvent, waitFor, act } = rtl;
+ listSecond = true;
+ const { container } = renderPage();
+ fireEvent.click(await screen.findByText('Alice'));
+ await waitFor(() => assert.ok(container.querySelector('.room-header'), 'the room did not open'));
+ const sessionReads = () => fetchCalls.filter(c => c.method === 'GET' && c.path === '/api/sessions').length;
+ const reads = sessionReads();
+ const visibilityChanged = () => act(() => void document.dispatchEvent(new window.Event('visibilitychange')));
+
+ // Deleted from another tab while this one was hidden: a session that was not running sends no frame at all.
+ setTabHidden(true);
+ try {
+ visibilityChanged();
+ mainDeleted = true;
+ assert.equal(sessionReads(), reads, 'a hidden page read the session list');
+ } finally {
+ setTabHidden(false);
+ }
+ visibilityChanged();
+ await waitFor(() => assert.equal(selectedSessionName(container), SECOND_SESSION.name));
+ assert.equal(sessionReads(), reads + 1, 'showing the page did not read the session list once');
+ assert.equal(container.querySelector('.room-header') === null, true, "the deleted session's chat stayed open");
+});
+
test('the session list read at load does not undo a newer list a status frame read before it answered', async () => {
const { screen, fireEvent, waitFor } = rtl;
listOffline = true;
diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsx
index 3fdbad2b0..e6a812e4f 100644
--- a/dashboard/src/pages/Chats.tsx
+++ b/dashboard/src/pages/Chats.tsx
@@ -1004,11 +1004,21 @@ export function Chats() {
await readSessions();
} while (relist.again);
} catch {
- // The next status event, or a search hit in that session, reads the list again.
+ // The next status event, the page being shown again, or a search hit in that session, reads the list again.
} finally {
relist.running = false;
}
}, [readSessions]);
+ // A deleted session sends no frame of its own: a running one reports disconnected while its row still exists, and
+ // one that was not running reports nothing. Coming back to the page reads the list again, so a session deleted
+ // from another tab or by another client is not kept open.
+ useEffect(() => {
+ const relistWhenShown = () => {
+ if (document.visibilityState !== 'hidden') void relistSessions();
+ };
+ document.addEventListener('visibilitychange', relistWhenShown);
+ return () => document.removeEventListener('visibilitychange', relistWhenShown);
+ }, [relistSessions]);
const handleSessionStatus = useCallback(
(event: { sessionId: string; status: string }) => {
if (!listedSessionsRef.current.some(session => session.id === event.sessionId)) {