From d2c2ee749191f585bec5eaff37c115bc969643f8 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 5 Feb 2021 16:05:17 +0000 Subject: [PATCH] Fix UMD bundles by removing usage of global --- packages/react-art/src/ReactARTHostConfig.js | 2 +- packages/react-dom/src/client/ReactDOMHostConfig.js | 6 +++--- packages/react-native-renderer/src/ReactFabricHostConfig.js | 2 +- packages/react-native-renderer/src/ReactNativeHostConfig.js | 2 +- packages/react-noop-renderer/src/createReactNoop.js | 2 +- packages/react-reconciler/README.md | 2 +- packages/react-reconciler/src/ReactFiberWorkLoop.new.js | 4 ++-- packages/react-reconciler/src/ReactFiberWorkLoop.old.js | 4 ++-- .../src/forks/ReactFiberHostConfig.custom.js | 2 +- packages/react-test-renderer/src/ReactTestHostConfig.js | 6 +++--- scripts/flow/environment.js | 2 ++ 11 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/react-art/src/ReactARTHostConfig.js b/packages/react-art/src/ReactARTHostConfig.js index 703d2c21c679d..d31b611ddb34c 100644 --- a/packages/react-art/src/ReactARTHostConfig.js +++ b/packages/react-art/src/ReactARTHostConfig.js @@ -330,7 +330,7 @@ export function getChildHostContext() { export const scheduleTimeout = setTimeout; export const cancelTimeout = clearTimeout; export const noTimeout = -1; -export function queueMicrotask(callback: Function) { +export function scheduleMicrotask(callback: Function) { invariant(false, 'Not implemented.'); } diff --git a/packages/react-dom/src/client/ReactDOMHostConfig.js b/packages/react-dom/src/client/ReactDOMHostConfig.js index fedfe8698e1ff..561ebc4476e36 100644 --- a/packages/react-dom/src/client/ReactDOMHostConfig.js +++ b/packages/react-dom/src/client/ReactDOMHostConfig.js @@ -384,9 +384,9 @@ export const scheduleTimeout: any = export const cancelTimeout: any = typeof clearTimeout === 'function' ? clearTimeout : (undefined: any); export const noTimeout = -1; -export const queueMicrotask: any = - typeof global.queueMicrotask === 'function' - ? global.queueMicrotask +export const scheduleMicrotask: any = + typeof queueMicrotask === 'function' + ? queueMicrotask : typeof Promise !== 'undefined' ? callback => Promise.resolve(null) diff --git a/packages/react-native-renderer/src/ReactFabricHostConfig.js b/packages/react-native-renderer/src/ReactFabricHostConfig.js index 7329a5f04a043..b8e18a01ebcee 100644 --- a/packages/react-native-renderer/src/ReactFabricHostConfig.js +++ b/packages/react-native-renderer/src/ReactFabricHostConfig.js @@ -348,7 +348,7 @@ export const warnsIfNotActing = false; export const scheduleTimeout = setTimeout; export const cancelTimeout = clearTimeout; export const noTimeout = -1; -export function queueMicrotask(callback: Function) { +export function scheduleMicrotask(callback: Function) { invariant(false, 'Not implemented.'); } diff --git a/packages/react-native-renderer/src/ReactNativeHostConfig.js b/packages/react-native-renderer/src/ReactNativeHostConfig.js index 5f64845f31421..8331979199e75 100644 --- a/packages/react-native-renderer/src/ReactNativeHostConfig.js +++ b/packages/react-native-renderer/src/ReactNativeHostConfig.js @@ -247,7 +247,7 @@ export const warnsIfNotActing = true; export const scheduleTimeout = setTimeout; export const cancelTimeout = clearTimeout; export const noTimeout = -1; -export function queueMicrotask(callback: Function) { +export function scheduleMicrotask(callback: Function) { invariant(false, 'Not implemented.'); } diff --git a/packages/react-noop-renderer/src/createReactNoop.js b/packages/react-noop-renderer/src/createReactNoop.js index 15bb2e28fb838..fab721c7bca29 100644 --- a/packages/react-noop-renderer/src/createReactNoop.js +++ b/packages/react-noop-renderer/src/createReactNoop.js @@ -371,7 +371,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { scheduleTimeout: setTimeout, cancelTimeout: clearTimeout, noTimeout: -1, - queueMicrotask: + scheduleMicrotask: typeof queueMicrotask === 'function' ? queueMicrotask : typeof Promise !== 'undefined' diff --git a/packages/react-reconciler/README.md b/packages/react-reconciler/README.md index 217d5f4b8e551..33bbdcfc7fd92 100644 --- a/packages/react-reconciler/README.md +++ b/packages/react-reconciler/README.md @@ -203,7 +203,7 @@ You can proxy this to `clearTimeout` or its equivalent in your environment. This is a property (not a function) that should be set to something that can never be a valid timeout ID. For example, you can set it to `-1`. -#### `queueMicrotask(fn)` +#### `scheduleMicrotask(fn)` You can proxy this to `queueMicrotask` or its equivalent in your environment. diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index 23d8037b4ff25..7513d21e27b1a 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -92,7 +92,7 @@ import { warnsIfNotActing, afterActiveInstanceBlur, clearContainer, - queueMicrotask, + scheduleMicrotask, } from './ReactFiberHostConfig'; import { @@ -766,7 +766,7 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) { enableDiscreteEventMicroTasks && newCallbackPriority === InputDiscreteLanePriority ) { - queueMicrotask(performSyncWorkOnRoot.bind(null, root)); + scheduleMicrotask(performSyncWorkOnRoot.bind(null, root)); newCallbackNode = null; } else { const schedulerPriorityLevel = lanePriorityToSchedulerPriority( diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 0f99452a4c636..5f372831d741a 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -92,7 +92,7 @@ import { warnsIfNotActing, afterActiveInstanceBlur, clearContainer, - queueMicrotask, + scheduleMicrotask, } from './ReactFiberHostConfig'; import { @@ -766,7 +766,7 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) { enableDiscreteEventMicroTasks && newCallbackPriority === InputDiscreteLanePriority ) { - queueMicrotask(performSyncWorkOnRoot.bind(null, root)); + scheduleMicrotask(performSyncWorkOnRoot.bind(null, root)); newCallbackNode = null; } else { const schedulerPriorityLevel = lanePriorityToSchedulerPriority( diff --git a/packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js b/packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js index e195b898749f8..b9ffc05725210 100644 --- a/packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js +++ b/packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js @@ -54,7 +54,7 @@ export const shouldSetTextContent = $$$hostConfig.shouldSetTextContent; export const createTextInstance = $$$hostConfig.createTextInstance; export const scheduleTimeout = $$$hostConfig.scheduleTimeout; export const cancelTimeout = $$$hostConfig.cancelTimeout; -export const queueMicrotask = $$$hostConfig.queueMicrotask; +export const scheduleMicrotask = $$$hostConfig.scheduleMicrotask; export const noTimeout = $$$hostConfig.noTimeout; export const now = $$$hostConfig.now; export const isPrimaryRenderer = $$$hostConfig.isPrimaryRenderer; diff --git a/packages/react-test-renderer/src/ReactTestHostConfig.js b/packages/react-test-renderer/src/ReactTestHostConfig.js index c9f9b2376ebb1..5adf1ac406e90 100644 --- a/packages/react-test-renderer/src/ReactTestHostConfig.js +++ b/packages/react-test-renderer/src/ReactTestHostConfig.js @@ -220,9 +220,9 @@ export const warnsIfNotActing = true; export const scheduleTimeout = setTimeout; export const cancelTimeout = clearTimeout; -export const queueMicrotask = - typeof global.queueMicrotask === 'function' - ? global.queueMicrotask +export const scheduleMicrotask = + typeof queueMicrotask === 'function' + ? queueMicrotask : typeof Promise !== 'undefined' ? (callback: Function) => Promise.resolve(null) diff --git a/scripts/flow/environment.js b/scripts/flow/environment.js index 86b19777cd31f..cb496e748e6cd 100644 --- a/scripts/flow/environment.js +++ b/scripts/flow/environment.js @@ -18,6 +18,8 @@ declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{ inject: ?((stuff: Object) => void) };*/ +declare var queueMicrotask: (fn: () => {}) => void; + declare module 'create-react-class' { declare var exports: React$CreateClass; }