department-of-veterans-affairs / va-mobile-app

"If VA were a company, it would have a flagship mobile app."
https://department-of-veterans-affairs.github.io/va-mobile-app/
17 stars 2 forks source link

CU - Add global AbortController for API requests #5583

Open alexandec opened 1 year ago

alexandec commented 1 year ago

Proposed Change

Our current AbortController implementation is piecemeal, meaning certain back button presses cancel certain API requests. We'd like to make this universal and automatic, where each API request creates its own AbortController. Any back button press in the app would then abort all API requests currently in flight.

Implementation idea (global state approach)

Alternate implementation idea (screen transition approach)

Why Should We Prioritize?

Coding Time Estimation

3

Testing Considerations

Checklist

timwright12 commented 2 weeks ago

@alexandec is this still a valid issue since we've mostly moved over to ReactQuery?

alexandec commented 2 weeks ago

@timwright12 yes, it's still an issue. React Query doesn't abort queries by default. It does provide a method for doing so, which we could use: https://tanstack.com/query/v4/docs/framework/react/guides/query-cancellation. One note: since React Query caches query results, sometimes it's still useful to complete the query and cache the results for later, even if the user has changed screens and won't see the results immediately. So we should be judicious in deciding which queries to abort.