Skip to content

fix(prompts): prevent toast after cancelled page navigation - #402

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
Sam-syntax35:fix/prompts-cancelled-toast
Jul 10, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
Sam-syntax35:fix/prompts-cancelled-toast

Conversation

@Sam-syntax35

Copy link
Copy Markdown
Contributor

Summary

Fixes a bug where navigating away from the Prompts page before data loading completed would trigger a misleading "Failed to load prompt data" toast on the destination page.

Changes

  • Added cancellation handling for async loading
  • Prevented state updates after component unmount
  • Suppressed error toast for cancelled requests
  • Preserved existing error handling for genuine failures

Fixes #394

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid fix — this meets all three acceptance criteria from #394: the spurious toast is gone on mid-load navigation, genuine failures still surface (the catch only bails when cancelled), and no state updates fire after cleanup.

I especially like that the finally guard also protects setLoading(false): since the effect cleanup runs on brand switches too (not just unmount), an unguarded finally from the stale run could have prematurely cleared the loading state of the new brand's in-flight load. Nicely done.

Passing the isCancelled callback into loadData (rather than inlining the flag in the effect) keeps the function reusable for the manual loadData() calls in the analyze/refresh handlers, which are unaffected thanks to the optional parameter.

Scoping this to the Prompts page only is exactly what the issue asked for — the optional sweep of the other pages can happen separately.

CI is green. LGTM!

@gkhngyk
gkhngyk merged commit fa8ba28 into ansvisor:main Jul 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants