redux-toolkit
redux-toolkit copied to clipboard
[FEAT][AsyncThunk] Pass abort reason of thunk action to AbortController #2395
Closes #2395
Description
asyncThunkApi.signal.reason is set to the first value provided to asyncThunkHandle.abort.
Other changes
- fixes
signal.abortednot being set totruein theAbortControllershim ifabortis called.
Implementation details
It uses a utility function abortControllerWithReason, already used within the listenerMiddleware, that patches reason if it is not available.
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit b72d7f5775f2da85c17861a00a94cfb8fe464c8e:
| Sandbox | Source |
|---|---|
| Vanilla | Configuration |
| Vanilla Typescript | Configuration |
| rsk-github-issues-example | Configuration |
| @examples-query-react/basic | Configuration |
| reduxjs/redux-toolkit | Configuration |
| @examples-action-listener/counter | Configuration |
To be honest, I'm not really sure if I like the thought of adding more "polyfill-like" code. Actually, I'd like to remove the AbortController polyfill in general with RTK 2.0 (#2448).
So I guess we'd need a bit research first:
- At that point, what platforms do have
AbortController, but notreason? - As these platforms will need a Polyfill anyways, which of the existing polyfills do not have
reason? - If all platforms that have it natively support
reason, wouldn't it make more sense to just PR into the missing polyfills?
Why should these changes be included in a minor release (1.9)?
- fix
signal.abortednot being set to true in the polyfill that causes inconsistent behavior between runtimes. - Add support to
signal.reasonreusing code that is already part oflistenerMiddlewarelogic.
what platforms do have AbortController, but not reason?
signal.reason support | 2022-06-25
abortSignal.reason is available in:
server runtimes
browsers
- can i use
82.51%
Samsung internet is a relevant mobile browser (especially in Germany) that does not support signal.reason.
createAsyncThunk changes for 2.0.0
I agree that we should remove if possible obsolete polyfills in 2.0.