Repository navigation
fix(prompts): prevent toast after cancelled page navigation - #402
Conversation
gkhngyk
left a comment
There was a problem hiding this comment.
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!
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
Fixes #394