From 10e587c508d3e4ff2d4bfdd1cb16ec9877fea72d Mon Sep 17 00:00:00 2001 From: amensum Date: Thu, 11 Feb 2021 00:50:07 +0300 Subject: [PATCH] Fix Bug MessageChannel in Node Envs (issue #20756) --- packages/scheduler/npm/index.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/scheduler/npm/index.js b/packages/scheduler/npm/index.js index 68a443aa1de8b..94b5e20a71267 100644 --- a/packages/scheduler/npm/index.js +++ b/packages/scheduler/npm/index.js @@ -1,9 +1,24 @@ 'use strict'; -if (typeof window === 'undefined' || typeof MessageChannel !== 'function') { - module.exports = require('./unstable_no_dom'); -} else if (process.env.NODE_ENV === 'production') { - module.exports = require('./cjs/scheduler.production.min.js'); +// Duplicated from 'react/packages/shared/ExecutionEnvironment.js' +var canUseDom = !!( + typeof window !== 'undefined' && + typeof window.document !== 'undefined' && + typeof window.document.createElement !== 'undefined' +); + +// Node environment has cycled global reference +var isCycledGlobal = !!( + typeof global !== 'undefined' && + global.global === global +); + +if (canUseDom && !isCycledGlobal) { + if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/scheduler.production.min.js'); + } else { + module.exports = require('./cjs/scheduler.development.js'); + } } else { - module.exports = require('./cjs/scheduler.development.js'); + module.exports = require('./unstable_no_dom'); }