Skip to content

fix(prompts): navigating away mid-load fires a spurious "Failed to load prompt data" toast #394

Closed

Description

@gkhngyk

Problem

Navigating away from Prompts (/dashboard/prompts) while its data is still loading fires a "Failed to load prompt data" error toast — on the page you just navigated to.

Repro:

  1. Open /dashboard/prompts (or switch to it from the sidebar)
  2. Quickly click another sidebar item before the page finishes loading
  3. The destination page shows the "Failed to load prompt data" toast, even though nothing actually failed

Cause

loadData in web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx (~line 308) runs three server actions in parallel and treats any rejection as a failure:

} catch (err) {
  console.error('Failed to load prompt data:', err);
  toast.error('Failed to load prompt data');
}

When the route changes mid-flight, the in-flight Server Action fetches are aborted; the rejection lands in this catch, and since the sonner toaster lives in the persistent layout, the toast surfaces on the next page. There's no cancellation guard distinguishing "component unmounted / navigation aborted" from a real failure.

Fix

Use the cancellation-flag pattern that already exists elsewhere in the codebase (e.g. the report detail page):

  • Track a cancelled flag in the effect (set in the cleanup) and skip both the state updates and the toast.error when it's set, and/or
  • Ignore AbortError-shaped rejections in the catch.

Same pattern elsewhere (optional sweep)

The same unguarded catch → toast.error('Failed to load …') exists in at least:

  • dashboard/insights/page.tsx (~413, "Failed to load prompts")
  • dashboard/content/page.tsx (~181) and dashboard/content/[id]/page.tsx (~107)
  • dashboard/brands/[id]/topics/page.tsx (~64), brands/[id]/prompts/page.tsx (~149, ~426), brands/[id]/settings/page.tsx (~566)

Fixing the Prompts page (the reported repro) is enough to close this; sweeping the others in the same PR is welcome but optional.

Acceptance criteria

  • Quickly navigating away from /dashboard/prompts mid-load no longer shows the "Failed to load prompt data" toast
  • A genuine load failure (e.g. network down) still shows the toast
  • No state updates fire after unmount (no React warnings)

Activity

  1. added
    bug
    good first issue
    on Jul 10, 2026
  2. Sam-syntax35 commented on Jul 10, 2026

    @Sam-syntax35
    Contributor

    Hi @gkhngyk, could you please assign these issues to me? I've already started working on them, and assigning them will help avoid duplicate PRs. Thanks!

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 issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions