Repository navigation
Description
Bug
On the brand detail page (/dashboard/brands/[id]/...), switching quickly between the Topics / Prompts / Settings tabs pops a red error toast at the top (e.g. Failed to fetch / Failed to load data), even though the destination tab renders fine.
Root cause
Each tab is a separate route whose page fetches data in an on-mount useEffect. When you navigate to another tab before that load resolves, Next.js aborts the in-flight server-action request, so the promise rejects (Failed to fetch / unexpected-response). The loaders catch all errors and unconditionally toast.error(...), so an abort caused by normal navigation surfaces as user-facing noise. There's no unmount/abort guard.
Affected on-mount loaders:
| File | Loader | Toast on abort |
|---|---|---|
web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/topics/page.tsx (~L50–60) |
loadTopics |
Failed to load topics |
web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/prompts/page.tsx (~L132–145) |
loadData |
Failed to load data |
web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.tsx (~L472–475) |
loadCompetitors |
Failed to load competitors |
Prior art
insights/page.tsx already handles this exact case — it inspects the error and downgrades a navigation-abort to console.debug instead of a toast (see the /unexpected response/i guard around L1454). The brand tabs just never got the same treatment. Note the brand loaders can also reject with Failed to fetch, so the guard should cover both signatures.
Fix (either approach)
A — mounted/abort guard (preferred): in each loader's useEffect, track a cancellation flag in the cleanup and skip both setState and toast.error when the component has unmounted:
useEffect(() => {
let cancelled = false;
(async () => {
try {
const data = await getTopics(brandId);
if (!cancelled) setTopics(data);
} catch (err) {
if (!cancelled) toast.error('Failed to load topics');
}
})();
return () => { cancelled = true; };
}, [brandId]);B — swallow navigation-abort errors (mirror insights): only toast when the message isn't a navigation abort, e.g. skip when /failed to fetch|unexpected response/i.test(message) and console.debug instead.
Acceptance
- Rapidly switching Topics / Prompts / Settings produces no error toast
- A genuine load failure (while staying on the tab) still shows the error toast
- Applies to all three loaders above
Notes
- Frontend-only; no data/API changes.
Activity
gitbasitmalik commentedon Jun 10, 2026
hi @gkhngyk i would like to work on it