From 3055fbb946835b3b13084a38eb77ff3a3cbdd326 Mon Sep 17 00:00:00 2001 From: Julien Karst Date: Sat, 16 Jul 2022 12:40:49 +0200 Subject: [PATCH 1/2] fix(2448): remove abort controller --- packages/toolkit/src/createAsyncThunk.ts | 34 +----------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/packages/toolkit/src/createAsyncThunk.ts b/packages/toolkit/src/createAsyncThunk.ts index eca550d201..c21e761f42 100644 --- a/packages/toolkit/src/createAsyncThunk.ts +++ b/packages/toolkit/src/createAsyncThunk.ts @@ -553,36 +553,6 @@ export const createAsyncThunk = (() => { }) ) - let displayedWarning = false - - const AC = - typeof AbortController !== 'undefined' - ? AbortController - : class implements AbortController { - signal = { - aborted: false, - addEventListener() {}, - dispatchEvent() { - return false - }, - onabort() {}, - removeEventListener() {}, - reason: undefined, - throwIfAborted() {}, - } - abort() { - if (process.env.NODE_ENV !== 'production') { - if (!displayedWarning) { - displayedWarning = true - console.info( - `This platform does not implement AbortController. -If you want to use the AbortController to react to \`abort\` events, please consider importing a polyfill like 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'.` - ) - } - } - } - } - function actionCreator( arg: ThunkArg ): AsyncThunkAction { @@ -591,10 +561,9 @@ If you want to use the AbortController to react to \`abort\` events, please cons ? options.idGenerator(arg) : nanoid() - const abortController = new AC() + const abortController = new AbortController() let abortReason: string | undefined - let started = false function abort(reason?: string) { abortReason = reason abortController.abort() @@ -615,7 +584,6 @@ If you want to use the AbortController to react to \`abort\` events, please cons message: 'Aborted due to condition callback returning false.', } } - started = true const abortedPromise = new Promise((_, reject) => abortController.signal.addEventListener('abort', () => From c23f7eb7395c03794e870d0060d4f718bdc6ca7b Mon Sep 17 00:00:00 2001 From: Julien Karst Date: Sun, 16 Oct 2022 15:20:52 +0200 Subject: [PATCH 2/2] test: update spec for abort controller --- packages/toolkit/src/tests/createAsyncThunk.test.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/toolkit/src/tests/createAsyncThunk.test.ts b/packages/toolkit/src/tests/createAsyncThunk.test.ts index fbc2b8a74a..8f5dfc0a5e 100644 --- a/packages/toolkit/src/tests/createAsyncThunk.test.ts +++ b/packages/toolkit/src/tests/createAsyncThunk.test.ts @@ -505,7 +505,7 @@ describe('createAsyncThunk with abortController', () => { vi.resetModules() }) - test('calling `abort` on an asyncThunk works with a FallbackAbortController if no global abortController is not available', async () => { + test('calling a thunk made with createAsyncThunk should fail if no global abortController is not available', async () => { const longRunningAsyncThunk = freshlyLoadedModule.createAsyncThunk( 'longRunning', async () => { @@ -513,14 +513,7 @@ describe('createAsyncThunk with abortController', () => { } ) - store.dispatch(longRunningAsyncThunk()).abort() - // should only log once, even if called twice - store.dispatch(longRunningAsyncThunk()).abort() - - expect(getLog().log).toMatchInlineSnapshot(` - "This platform does not implement AbortController. - If you want to use the AbortController to react to \`abort\` events, please consider importing a polyfill like 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'." - `) + expect(longRunningAsyncThunk()).toThrow("AbortController is not defined") }) }) })