-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: abort request with AbortController signal #187
Comments
Love it! My first question is whats the API? You invoke a fetch call by dispatching a |
Big question... have not thought about it yet 😅 |
@nason @wachunei I see it this way, const actionCreator = (controller, abortCtrl1, abortCtrl2) => ({
[RSAA]: {
// ...
types: ['REQUEST', 'SUCCESS', 'FAILURE', 'ABORT']
abort: [abortCtrl1, abortCtrl2],
signal: controller.signal
// ...
}
}) when |
And maybe some global |
I like this idea! But would we really need a new Action Type to RSAA spec? According to MDN docs, an aborted fetch should reject the promise, meaning it could produce a normal Failure action, with a specific error type? If that's the case, the RSAA would only need to be given the custom |
And actually, thinking on this more, could we use the existing |
I think we should not polyfill, just like fetch. |
So I tested this out with native I still need to play with this more and test... but I was able to "abort" an RSAA generated Here's what I did to "abort" a network request that was initiated by // example case for basic action creator
const myRsaaCreator = (rsaaProps) => {
const controller = new window.AbortController()
const { signal } = controller
const rsaa = {
[RSAA]: {
// ...
...rsaaProps,
options: { signal }
}
}
return [ rsaa, controller ]
}
// then later dispatch...
const [ rsaa, controller ] = myRsaaCreator()
dispatch(rsaa)
// then later abort...
controller.abort() tricky part is figuring out where you need access to this @nason I think maybe this just needs to be tested a bit more and documented in v 3.0.0? I can help out with this is you feel there needs to be additional changes, since it may help to better handle the "error" message and document behavior... here's the
In v 3.0.0, this would be a |
@darthrellimnad I think we started using that approach in our codebase and I just recently figured out that on abort SUCCESS action is being called with payload = error |
Most probably not a small set of developers had run into wanting to abort an ongoing fetch call. For instance an autocomplete input that makes requests as key events are happening, even with a debouncer.
Now in most browsers
AbortController
API is available in order to fulfill this task.This issue is an open question for the community if there's interest in including this feature and what we could achieve. I think an extension of
RSAA
is needed at least.What do you guys think? I could definitely set up some code proposals or tests in the next days if this idea gains traction 😃
The text was updated successfully, but these errors were encountered: