Skip to content

Commit 1cb135e

Browse files
committed
Add extra check for global in queueMicrotask polyfills
1 parent 69ee99a commit 1cb135e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/toolkit/src/autoBatchEnhancer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ export const prepareAutoBatched =
1414
let promise: Promise<any>
1515
const queueMicrotaskShim =
1616
typeof queueMicrotask === 'function'
17-
? queueMicrotask.bind(typeof window !== 'undefined' ? window : global)
17+
? queueMicrotask.bind(
18+
typeof window !== 'undefined'
19+
? window
20+
: typeof global !== 'undefined'
21+
? global
22+
: globalThis
23+
)
1824
: // reuse resolved promise, and allocate it lazily
1925
(cb: () => void) =>
2026
(promise || (promise = Promise.resolve())).then(cb).catch((err: any) =>

packages/toolkit/src/query/core/buildMiddleware/batchActions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import { createSlice, PayloadAction, AnyAction } from '@reduxjs/toolkit'
1212
let promise: Promise<any>
1313
const queueMicrotaskShim =
1414
typeof queueMicrotask === 'function'
15-
? queueMicrotask.bind(typeof window !== 'undefined' ? window : global)
15+
? queueMicrotask.bind(
16+
typeof window !== 'undefined'
17+
? window
18+
: typeof global !== 'undefined'
19+
? global
20+
: globalThis
21+
)
1622
: // reuse resolved promise, and allocate it lazily
1723
(cb: () => void) =>
1824
(promise || (promise = Promise.resolve())).then(cb).catch((err: any) =>

0 commit comments

Comments
 (0)