Repository navigation
fix(citations): don't toast a load failure after leaving the page - #696
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Leaving the Citations page mid-load aborted the request, and the
catchtreated 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.errorand the toast. A genuine failure with the page still open behaves exactly as before.Why a generation counter rather than a
cancelledflag:loadDatais also passed directly asonRetry/onAddedto 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 asgenRefin the audit detail page.Related issue
Closes #684
Type of change
fix— Bug fixHow to test
Reproduced and verified in the browser against a local instance:
[citations] load failedentry in the console.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
loadDatafor 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
feature/,fix/,chore/,docs/)yarn lintpasses — no new warnings in this fileyarn typecheckpassesyarn format:checkpasses