Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): send one delete or force-kill per confirm

Yudhi Armyndharisf5d446bf7452
diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.ts
index 7d0025187..1ee333350 100644
--- a/dashboard/src/pages/Sessions.test.ts
+++ b/dashboard/src/pages/Sessions.test.ts
@@ -103,6 +103,7 @@ function resetFetchCalls(): void {
createFailure = null;
stopFailure = null;
forceKillFailure = null;
+ confirmGate = null;
qrGate = null;
listGate = null;
pairingGate = null;
@@ -139,6 +140,8 @@ let createFailure: { status: number; message: string } | null = null;
let stopFailure: { status: number; message: string } | null = null;
// When set, POST .../force-kill answers with this status and body.
let forceKillFailure: { status: number; body: Record<string, unknown> } | null = null;
+// When set, DELETE /api/sessions/:id and POST .../force-kill answer only once this settles.
+let confirmGate: Promise<void> | null = null;
// When set, POST .../start answers, whichever way it answers, only once this settles.
let startGate: Promise<void> | null = null;
// When set, GET .../qr for that one session answers only once `until` settles.
@@ -224,7 +227,7 @@ function installFetchStub(): void {
}
if (method === 'DELETE' && sessionIdMatch) {
if (afterMutation) setImmediate(afterMutation);
- return Promise.resolve(new Response(null, { status: 204 }));
+ return (confirmGate ?? Promise.resolve()).then(() => new Response(null, { status: 204 }));
}
const configMatch = path.match(/^\/api\/sessions\/([^/]+)\/config$/);
@@ -305,6 +308,7 @@ function installFetchStub(): void {
return jsonResponse({ ...base, status: 'disconnected', engineLoaded: false });
};
if (isStart && startGate) return startGate.then(answer);
+ if (lifecycleMatch[2] === 'force-kill' && confirmGate) return confirmGate.then(answer);
return Promise.resolve(answer());
}
@@ -1950,3 +1954,33 @@ for (const [label, body, shown] of [
within(alert).getByText(shown);
});
}
+
+// The confirm modal closes only once its request answers, so a second click on its button in that
+// window must not send the request again.
+for (const [label, cardButton, confirmButton, method, path] of [
+ ['a double-clicked Delete sends one delete', 'Delete', 'Delete', 'DELETE', '/api/sessions/sess-stale-1'],
+ [
+ 'a double-clicked Kill Session sends one force-kill',
+ 'Kill Stuck',
+ 'Kill Session',
+ 'POST',
+ '/api/sessions/sess-stale-1/force-kill',
+ ],
+] as const) {
+ test(label, async () => {
+ const { screen, fireEvent, within, waitFor } = rtl;
+ resetFetchCalls();
+ let release!: () => void;
+ confirmGate = new Promise<void>(resolve => (release = resolve));
+ renderSessions();
+
+ const card = (await screen.findByText('stale-engine')).closest('.session-card') as HTMLElement;
+ fireEvent.click(within(card).getByRole('button', { name: cardButton }));
+ const confirm = within(await screen.findByRole('dialog')).getByRole('button', { name: confirmButton });
+ fireEvent.click(confirm);
+ fireEvent.click(confirm);
+ release();
+ await waitFor(() => assert.ok(!screen.queryByRole('dialog'), 'the confirm modal did not close'));
+ assert.equal(fetchCalls.filter(c => c.method === method && c.path === path).length, 1);
+ });
+}
diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsx
index 826399493..172d49773 100644
--- a/dashboard/src/pages/Sessions.tsx
+++ b/dashboard/src/pages/Sessions.tsx
@@ -87,6 +87,8 @@ export function Sessions() {
const [killConfirmId, setKillConfirmId] = useState<string | null>(null);
const [unlinkConfirmId, setUnlinkConfirmId] = useState<string | null>(null);
const [unlinkingId, setUnlinkingId] = useState<string | null>(null);
+ const [deletingId, setDeletingId] = useState<string | null>(null);
+ const [killingId, setKillingId] = useState<string | null>(null);
// Sessions whose Start or Reconnect click is still being handled. A start can wait seconds before its
// engine exists, and a second click in that window is refused as "already starting" while the first
// one proceeds.
@@ -356,6 +358,10 @@ export function Sessions() {
}, [isConnected, error, fetchSessions]);
const handleDelete = async (id: string) => {
+ // The confirm modal stays open until the request answers, so a double-click would delete twice and
+ // report the second, failed delete after the first one's success.
+ if (deletingId) return;
+ setDeletingId(id);
const session = sessions.find(s => s.id === id);
try {
await sessionApi.delete(id);
@@ -374,6 +380,7 @@ export function Sessions() {
console.error('Failed to delete:', err);
toast.error(t('sessions.delete.errorTitle'), msg);
} finally {
+ setDeletingId(null);
setDeleteConfirmId(null);
}
};
@@ -574,6 +581,9 @@ export function Sessions() {
};
const handleForceKill = async (id: string) => {
+ // Same double-click guard as handleDelete.
+ if (killingId) return;
+ setKillingId(id);
try {
const updated = await sessionApi.forceKill(id);
await applySessionResponse(updated);
@@ -590,6 +600,7 @@ export function Sessions() {
);
await fetchSessions();
} finally {
+ setKillingId(null);
setKillConfirmId(null);
}
};
@@ -1122,7 +1133,11 @@ export function Sessions() {
<button className="btn-secondary" onClick={() => setDeleteConfirmId(null)}>
{t('common.cancel')}
</button>
- <button className="btn-danger" onClick={() => handleDelete(deleteConfirmId)}>
+ <button
+ className="btn-danger"
+ onClick={() => handleDelete(deleteConfirmId)}
+ disabled={deletingId !== null}
+ >
{t('common.delete')}
</button>
</>
@@ -1151,7 +1166,11 @@ export function Sessions() {
<button className="btn-secondary" onClick={() => setKillConfirmId(null)}>
{t('common.cancel')}
</button>
- <button className="btn-danger" onClick={() => handleForceKill(killConfirmId)}>
+ <button
+ className="btn-danger"
+ onClick={() => handleForceKill(killConfirmId)}
+ disabled={killingId !== null}
+ >
{t('sessions.forceKill.confirm')}
</button>
</>