redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

[FEAT][AsyncThunk] Pass abort reason of thunk action to AbortController #2395

Open FaberVitale opened this issue 3 years ago • 3 comments

Closes #2395

Description

asyncThunkApi.signal.reason is set to the first value provided to asyncThunkHandle.abort.

Other changes

  • fixes signal.aborted not being set to true in the AbortController shim if abort is called.

Implementation details

It uses a utility function abortControllerWithReason, already used within the listenerMiddleware, that patches reason if it is not available.

FaberVitale avatar Jun 16 '22 20:06 FaberVitale

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

codesandbox-ci[bot] avatar Jun 16 '22 20:06 codesandbox-ci[bot]

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 not reason?
  • 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?

phryneas avatar Jun 24 '22 12:06 phryneas

Why should these changes be included in a minor release (1.9)?

  1. fix signal.aborted not being set to true in the polyfill that causes inconsistent behavior between runtimes.
  2. Add support to signal.reason reusing code that is already part of listenerMiddleware logic.

what platforms do have AbortController, but not reason?

signal.reason support | 2022-06-25

abortSignal.reason is available in:

server runtimes

browsers

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.

FaberVitale avatar Jun 25 '22 09:06 FaberVitale