Skip to content
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

Pass abort reason of thunk action to AbortController #2395

Open
xbaun opened this issue Jun 9, 2022 · 3 comments
Open

Pass abort reason of thunk action to AbortController #2395

xbaun opened this issue Jun 9, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@xbaun
Copy link

xbaun commented Jun 9, 2022

Hi,

I noticed that the abort reason of a thunk action is not getting passed down to the AbortController in line 578:

function abort(reason?: string) {
if (started) {
abortReason = reason
abortController.abort()
}
}

It would be useful to get the abort reason directly in the thunk action, so the thunk can cleanup its states.

thx

@phryneas
Copy link
Member

phryneas commented Jun 9, 2022

AbortController only added support for a reason recently and it is spotty across different platforms. If you can come up with a good overview on where it is supported and where it might cause problems passing it in we could get to an informed decision, but I don't have the time to do that research atm.

@xbaun
Copy link
Author

xbaun commented Jun 9, 2022

There is a MDN overview for reason where it is supported https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason#browser_compatibility - looks pretty good.

It's also supported on node with version v16 and above: https://nodejs.org/docs/latest-v16.x/api/globals.html#abortcontrollerabortreason

Are there other platforms do you mean?

@FaberVitale
Copy link
Contributor

AbortController only added support for a reason recently and it is spotty across different platforms. If you can come up with a good overview on where it is supported and where it might cause problems passing it in we could get to an informed decision, but I don't have the time to do that research atm.

In listenerMiddleware code, reason is patched if it is not avaible at runtime:

export const abortControllerWithReason = <T>(

We could reuse abortControllerWithReason in asyncThunks

FaberVitale added a commit to FaberVitale/redux-toolkit that referenced this issue Jun 16, 2022
…vided to asyncThunkHandle.abort reduxjs#2395

Other changes:

fixes signal.aborted not set in AbortController shim
@aryaemami59 aryaemami59 added the enhancement New feature or request label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants