Skip to content

Commit 08f3892

Browse files
authored
Merge pull request #2518 from JulienKode/fix/2448-remove-abort-controller
2 parents c8f77a9 + c23f7eb commit 08f3892

File tree

2 files changed

+3
-42
lines changed

2 files changed

+3
-42
lines changed

packages/toolkit/src/createAsyncThunk.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -553,36 +553,6 @@ export const createAsyncThunk = (() => {
553553
})
554554
)
555555

556-
let displayedWarning = false
557-
558-
const AC =
559-
typeof AbortController !== 'undefined'
560-
? AbortController
561-
: class implements AbortController {
562-
signal = {
563-
aborted: false,
564-
addEventListener() {},
565-
dispatchEvent() {
566-
return false
567-
},
568-
onabort() {},
569-
removeEventListener() {},
570-
reason: undefined,
571-
throwIfAborted() {},
572-
}
573-
abort() {
574-
if (process.env.NODE_ENV !== 'production') {
575-
if (!displayedWarning) {
576-
displayedWarning = true
577-
console.info(
578-
`This platform does not implement AbortController.
579-
If you want to use the AbortController to react to \`abort\` events, please consider importing a polyfill like 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'.`
580-
)
581-
}
582-
}
583-
}
584-
}
585-
586556
function actionCreator(
587557
arg: ThunkArg
588558
): AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig> {
@@ -591,10 +561,9 @@ If you want to use the AbortController to react to \`abort\` events, please cons
591561
? options.idGenerator(arg)
592562
: nanoid()
593563

594-
const abortController = new AC()
564+
const abortController = new AbortController()
595565
let abortReason: string | undefined
596566

597-
let started = false
598567
function abort(reason?: string) {
599568
abortReason = reason
600569
abortController.abort()
@@ -615,7 +584,6 @@ If you want to use the AbortController to react to \`abort\` events, please cons
615584
message: 'Aborted due to condition callback returning false.',
616585
}
617586
}
618-
started = true
619587

620588
const abortedPromise = new Promise<never>((_, reject) =>
621589
abortController.signal.addEventListener('abort', () =>

packages/toolkit/src/tests/createAsyncThunk.test.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -505,22 +505,15 @@ describe('createAsyncThunk with abortController', () => {
505505
vi.resetModules()
506506
})
507507

508-
test('calling `abort` on an asyncThunk works with a FallbackAbortController if no global abortController is not available', async () => {
508+
test('calling a thunk made with createAsyncThunk should fail if no global abortController is not available', async () => {
509509
const longRunningAsyncThunk = freshlyLoadedModule.createAsyncThunk(
510510
'longRunning',
511511
async () => {
512512
await new Promise((resolve) => setTimeout(resolve, 30000))
513513
}
514514
)
515515

516-
store.dispatch(longRunningAsyncThunk()).abort()
517-
// should only log once, even if called twice
518-
store.dispatch(longRunningAsyncThunk()).abort()
519-
520-
expect(getLog().log).toMatchInlineSnapshot(`
521-
"This platform does not implement AbortController.
522-
If you want to use the AbortController to react to \`abort\` events, please consider importing a polyfill like 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'."
523-
`)
516+
expect(longRunningAsyncThunk()).toThrow("AbortController is not defined")
524517
})
525518
})
526519
})

0 commit comments

Comments
 (0)