Skip to content

Commit a47a979

Browse files
committed
Fix Bug MessageChannel in Node Envs (issue #20756)
1 parent e46d711 commit a47a979

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

packages/scheduler/npm/index.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
'use strict';
22

3-
if (typeof window === 'undefined' || typeof MessageChannel !== 'function') {
4-
module.exports = require('./unstable_no_dom');
5-
} else if (process.env.NODE_ENV === 'production') {
6-
module.exports = require('./cjs/scheduler.production.min.js');
3+
// Duplicated from 'react/packages/shared/ExecutionEnvironment.js'
4+
var canUseDom = !!(
5+
typeof window !== 'undefined' &&
6+
typeof window.document !== 'undefined' &&
7+
typeof window.document.createElement !== 'undefined'
8+
);
9+
10+
// Checks if this is global space
11+
var isThisGlobal = !!(
12+
typeof globalThis !== 'undefined' &&
13+
globalThis === this
14+
);
15+
16+
if (canUseDom && isThisGlobal) {
17+
if (process.env.NODE_ENV === 'production') {
18+
module.exports = require('./cjs/scheduler.production.min.js');
19+
} else {
20+
module.exports = require('./cjs/scheduler.development.js');
21+
}
722
} else {
8-
module.exports = require('./cjs/scheduler.development.js');
23+
module.exports = require('./unstable_no_dom');
924
}

0 commit comments

Comments
 (0)