reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.74k stars 1.18k forks source link

Feature request: provide option to automatically abort requests when response is no longer needed #4618

Open ensconced opened 2 months ago

ensconced commented 2 months ago

In some situations, the backend processing of a request can take a long time or be very expensive. In this situation it would be good to be able to automatically abort requests when the response is no longer needed, either because the component using the query has been unmounted, or because the params have changed.

I imagine this would be achieved via a new option abortRedundantRequests. If set to true on a given endpoint, this would mean that the AbortSignal (which I believe is already passed through to fetchBaseQuery) gets aborted. Then the backend can listen for the connection being closed, and stop any expensive processing it might still be doing.

Is that something that would make sense for RTK to implement? Or is there any way I can achieve this already?

sglogovic-moberg commented 2 months ago

We would use this feature as well in our apps in the similar fashion as described, so +1