Skip to content

fix(insights): silence the "unexpected response" toast (navigation noise, not a real error) #40

Closed

Description

@gkhngyk

What's wrong

When the Answer Engine Insights page (/dashboard/insights) is still
loading and the user clicks any sidebar link to navigate away, a red
toast appears in the top-right corner:

An unexpected response was received from the server

The navigation completes correctly and the destination page renders
fine — the toast is purely cosmetic noise from the abandoned page's
in-flight requests. But it scares users into thinking something
broke.

Steps to reproduce

  1. Open /dashboard/insights cold (no cache)
  2. While spinners are still visible, click any sidebar link (Brands,
    Topics, Settings, etc.)
  3. Observe: new page loads correctly, but a red error toast
    appears with the message above

What we want

Detect this specific error in the catch block and skip the toast
for it. Other real errors (a genuine server 500, a malformed payload,
etc.) should still surface normally.

Where to fix

web/src/app/[locale]/(dashboard)/dashboard/insights/page.tsx around
line 1473 — the catch block of loadData:

} catch (err) {
  if (!silent) {
    toast.error(
      err instanceof Error ? err.message : 'Failed to load insights',
    );
  }
  // ...
}

Add a guard so this specific known-harmless message is logged but not
toasted. Suggested shape (the exact pattern is up to you):

} catch (err) {
  const message = err instanceof Error ? err.message : '';

  // Next.js surfaces this when a server action's response stream is
  // cut because the user navigated away mid-load. Not a real error —
  // the destination page renders fine.
  const isNavigationCancellation =
    message.includes('unexpected response') ||
    message.includes('An unexpected response from the server');

  if (isNavigationCancellation) {
    console.debug('[insights] load aborted by navigation', err);
  } else if (!silent) {
    toast.error(message || 'Failed to load insights');
  }
}

Match the message case-insensitively if possible — Next.js wording
has shifted between versions and you want the guard to survive a
minor upgrade.

How to verify

  • Open /dashboard/insights cold, click a sidebar link while
    spinners are still showing → no red toast
  • Stop the dev API server, reload /dashboard/insights → a real
    error toast still appears (we're only suppressing one specific
    string, not all errors)
  • Normal page load with data → loads cleanly, no toast either way

Out of scope

  • AbortController / mounted-ref refactor — that's a bigger
    architectural change; for now we only want to silence the toast
  • Same fix on other pages (Topics, Citations, etc.) — open a
    follow-up if those pages show the same toast in the same scenario
  • Plan gating, error tracking integration, etc.

Contribution guide

See CONTRIBUTING.md for branch naming, commit
conventions, and PR workflow.

Activity

  1. added
    bug
    good first issue
    help wanted
    on May 18, 2026
  2. added a commit that references this issue on May 22, 2026
    5996a66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions