Skip to content

Fix for MessageChannel in Node Envs (#20756) #20790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
25 changes: 20 additions & 5 deletions packages/scheduler/npm/index.js
Original file line number Diff line number Diff line change
@@ -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'
);

// Checks if this is global space to catch
// execution in node environments and use 'unstable_no_dom'
//
// eslint-disable-next-line no-undef
var isThisGlobal = !!(typeof globalThis !== 'undefined' && globalThis === this);

if (canUseDom && isThisGlobal) {
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');
}