Skip to content

Commit

Permalink
Cache local reference to global Promise (#21886)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii authored Jul 15, 2021
1 parent d5de458 commit 682bbd0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ export const scheduleTimeout: any =
export const cancelTimeout: any =
typeof clearTimeout === 'function' ? clearTimeout : (undefined: any);
export const noTimeout = -1;
const localPromise = Promise;

// -------------------
// Microtasks
Expand All @@ -400,9 +401,10 @@ export const supportsMicrotasks = true;
export const scheduleMicrotask: any =
typeof queueMicrotask === 'function'
? queueMicrotask
: typeof Promise !== 'undefined'
: typeof localPromise !== 'undefined'
? callback =>
Promise.resolve(null)
localPromise
.resolve(null)
.then(callback)
.catch(handleErrorInNextTick)
: scheduleTimeout; // TODO: Determine the best fallback here.
Expand Down

0 comments on commit 682bbd0

Please sign in to comment.