@samitouri / QOS-React / commits / 682bbd0e72

Cache local reference to global Promise (#21886)

Ricky committed Jul 15, 2021 at 12:39 UTC 682bbd0e7212df0bfe1d8017284e2822d281f7ea
1 file changed +4 -2
packages/react-dom/src/client/ReactDOMHostConfig.js
+4 -2
@@ -392,6 +392,7 @@ export const scheduleTimeout: any =
392 export const cancelTimeout: any =
393 typeof clearTimeout === 'function' ? clearTimeout : (undefined: any);
394 export const noTimeout = -1;
395 +const localPromise = Promise;
396
397 // -------------------
398 // Microtasks
@@ -400,9 +401,10 @@ export const supportsMicrotasks = true;
401 export const scheduleMicrotask: any =
402 typeof queueMicrotask === 'function'
403 ? queueMicrotask
403 - : typeof Promise !== 'undefined'
404 + : typeof localPromise !== 'undefined'
405 ? callback =>
405 - Promise.resolve(null)
406 + localPromise
407 + .resolve(null)
408 .then(callback)
409 .catch(handleErrorInNextTick)
410 : scheduleTimeout; // TODO: Determine the best fallback here.