Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): show the spinner until a template session is selected

Yudhi Armyndharis46060c0a90e5
diff --git a/dashboard/src/pages/Templates.test.ts b/dashboard/src/pages/Templates.test.ts
index 2821ae697..5cf32333a 100644
--- a/dashboard/src/pages/Templates.test.ts
+++ b/dashboard/src/pages/Templates.test.ts
@@ -163,6 +163,24 @@ test('a successful empty read still shows the empty state', async () => {
await rtl.screen.findByText('No templates saved');
});
+// Between the sessions read and the effect that selects the first session, no templates read has
+// started yet; that frame must show the loading state, not claim the library is empty.
+test('a library with templates never flashes the empty state while the first session is selected', async () => {
+ templates = [{ id: 'tpl-1', name: 'invoice-reminder', body: 'Hi {{name}}' }];
+ let sawEmpty = false;
+ const observer = new MutationObserver(() => {
+ if (document.body.textContent?.includes('No templates saved')) sawEmpty = true;
+ });
+ observer.observe(document.body, { childList: true, subtree: true, characterData: true });
+ try {
+ renderTemplates();
+ await rtl.screen.findByText('invoice-reminder');
+ } finally {
+ observer.disconnect();
+ }
+ assert.equal(sawEmpty, false, 'the empty state rendered before the templates read started');
+});
+
test('a failed sessions read shows the error, not "no sessions available"', async () => {
sessionsStatus = 502;
renderTemplates();
diff --git a/dashboard/src/pages/Templates.tsx b/dashboard/src/pages/Templates.tsx
index 8899eabdf..1f9ba5734 100644
--- a/dashboard/src/pages/Templates.tsx
+++ b/dashboard/src/pages/Templates.tsx
@@ -251,7 +251,8 @@ export function Templates() {
/>
</div>
- {loadingTemplates ? (
+ {/* No session selected yet means the first-session effect has not run: the read is still to start. */}
+ {loadingTemplates || !selectedSessionId ? (
<div className="templates-loading-inline">
<Loader2 className="animate-spin" size={24} />
</div>