Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep Infrastructure on screen when a status refetch fails

Yudhi Armyndharis98f01d431101
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.ts
index 61c54b9dd..fedc26b8a 100644
--- a/dashboard/src/pages/Infrastructure.test.ts
+++ b/dashboard/src/pages/Infrastructure.test.ts
@@ -85,6 +85,7 @@ let overrides: {
status?: InfraStatus;
saved?: SavedConfig;
savedFails?: boolean;
+ statusFails?: boolean;
currentEngine?: { engineType: string };
} = {};
@@ -147,8 +148,10 @@ function installFetchStub(): void {
}
fetchCalls.push({ method, path, body });
- if (method === 'GET' && path === '/api/infra/status')
+ if (method === 'GET' && path === '/api/infra/status') {
+ if (overrides.statusFails) return Promise.resolve(jsonResponse({ message: 'Bad Gateway' }, 502));
return Promise.resolve(jsonResponse(overrides.status ?? INFRA_STATUS));
+ }
if (method === 'GET' && path === '/api/infra/config') {
if (overrides.savedFails) return Promise.resolve(jsonResponse({ message: 'boom' }, 500));
return Promise.resolve(jsonResponse(overrides.saved ?? SAVED_CONFIG));
@@ -429,6 +432,35 @@ test('a successful save opens the restart modal', async () => {
within(dialog).getByRole('button', { name: 'Restart Later' });
});
+const STATUS_LOAD_ERROR = "Couldn't load the current infrastructure status. Refresh to try again.";
+
+test('a failed first /status read shows the status error card and no form', async () => {
+ overrides = { statusFails: true };
+ renderInfrastructure();
+
+ await rtl.screen.findByText(STATUS_LOAD_ERROR);
+ assert.equal(rtl.screen.queryByRole('button', { name: 'Save Configuration' }), null);
+});
+
+test('a failed background /status refetch keeps the form and the restart modal on screen', async () => {
+ const { screen, fireEvent } = rtl;
+ renderInfrastructure();
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Save Configuration' }));
+ await screen.findByRole('dialog');
+
+ // A focus refetch while the gateway is down: the cached status is still there, only the read failed.
+ overrides = { statusFails: true };
+ await queryClient!.refetchQueries({ queryKey: ['infra', 'status'] });
+ assert.equal(queryClient!.getQueryState(['infra', 'status'])?.status, 'error');
+ // Let the error state render before looking.
+ await new Promise(resolve => setTimeout(resolve, 50));
+
+ assert.ok(screen.queryByRole('dialog'), 'the restart modal must stay open');
+ assert.equal(screen.queryByText(STATUS_LOAD_ERROR), null);
+ screen.getByRole('button', { name: 'Save Configuration' });
+});
+
// ── The engine radio's seed source (#1082) ───────────────────────────────────
// ENGINES fixture order fixes the radio order: [0] whatsapp-web.js, [1] baileys.
diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsx
index e246f94e1..4a2c9f0ee 100644
--- a/dashboard/src/pages/Infrastructure.tsx
+++ b/dashboard/src/pages/Infrastructure.tsx
@@ -41,7 +41,7 @@ export function Infrastructure() {
const { t } = useTranslation();
useDocumentTitle(t('infrastructure.title'));
const toast = useToast();
- const { data: infraStatus, isLoading: loading, isError: statusError } = useInfraStatusQuery();
+ const { data: infraStatus, isLoading: loading } = useInfraStatusQuery();
const { data: savedConfig, isLoading: configLoading } = useInfraConfigQuery();
const { data: engines = [] } = useEnginesQuery();
const { data: currentEngineData } = useCurrentEngineQuery();
@@ -150,8 +150,10 @@ export function Infrastructure() {
// external+empty. Show an error + retry instead. (#488 review)
// Likewise without the saved config: the database, storage and engine detail fields hydrate only
// from it, and a Save sends every one of them.
- if (statusError || !infraStatus || !savedConfig) {
- const configOnly = !statusError && !!infraStatus;
+ // Keyed on missing data, not on the query's error flag: a failed background refetch keeps the last
+ // good data, and replacing the page then would unmount the form and a restart already in progress.
+ if (!infraStatus || !savedConfig) {
+ const configOnly = !!infraStatus;
return (
<div className="infrastructure-page">
<PageHeader title={t('infrastructure.title')} subtitle={t('infrastructure.subtitle')} />