Skip to content

fix(citations): don't toast a load failure after leaving the page - #696

Merged
gkhngyk merged 1 commit into
mainfrom
fix/684-citations-spurious-toast
Aug 10, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/684-citations-spurious-toast

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Leaving the Citations page mid-load aborted the request, and the catch treated that rejection as a real failure — setting the failed state and firing a global toast, which then appeared on whatever page the user had navigated to. The effect also had no cleanup, so a slow response could write state after unmount or overwrite newer data after a rapid filter change.

Each load now claims a generation. The effect's cleanup increments the counter, so a response landing after the filters changed — or after the user left — recognises itself as stale and skips the state writes, the console.error and the toast. A genuine failure with the page still open behaves exactly as before.

Why a generation counter rather than a cancelled flag: loadData is also passed directly as onRetry / onAdded to child components, so its signature has to stay parameterless — the counter keeps the callers untouched and additionally covers the Retry-then-navigate case. Same shape as genRef in the audit detail page.

Related issue

Closes #684

Type of change

  • fix — Bug fix

How to test

Reproduced and verified in the browser against a local instance:

  1. Open Citations and navigate away (Prompts, Topics) before it finishes loading — the overview scan takes seconds, so this is easy to hit.
  2. Before: "Failed to load citation data" appeared on the destination page. After: no toast, and no [citations] load failed entry in the console.
  3. With the page open, a real failure still shows the error state and the toast.

Note on the lint directive

The cleanup carries an eslint-disable-next-line react-hooks/exhaustive-deps. The rule warns about reading a ref in cleanup because it assumes the ref points at a rendered node; here it is a counter, and a value that moved on since the effect ran is precisely what we want to invalidate. Without the directive this file gains a warning it didn't have before, so the suppression is scoped to the single line and explained in a comment above it.

Coordination

#656 (@tomatotomata) reworks the same loadData for the refetch-loading state. If that lands first I'll rebase; if this lands first, the cancellation guard is already in place and should make that change smaller.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/)
  • Commits follow Conventional Commits
  • yarn lint passes — no new warnings in this file
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR

Navigating away while the citations overview is still loading aborted the
request, and the catch treated that rejection like a real failure: it set
the failed state and fired a global toast, which surfaced on whichever page
the user had moved to. The effect also had no cleanup, so a slow response
could write state after unmount or overwrite newer data on a rapid filter
change.

Each load now claims a generation; the effect's cleanup bumps the counter,
so a response that lands after the filters changed — or after the user left
— recognises itself as stale and skips the state writes, the log and the
toast. Real failures with the page still open behave exactly as before.

The generation counter is used instead of a cancelled flag because loadData
is also passed directly as an onRetry/onAdded prop, so its signature has to
stay parameterless.

Closes #684
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.

Citations: navigating away mid-load fires a spurious "Failed to load citation data" toast

1 participant