Skip to content

Commit 24d0448

Browse files
committed
fix: remove platform checks from production bundle, fixes #1162
1 parent 73068c7 commit 24d0448

File tree

3 files changed

+19
-1978
lines changed

3 files changed

+19
-1978
lines changed

Diff for: index.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
'use strict'
22

3-
var evalAllowed = false;
4-
try {
5-
eval('evalAllowed = true');
6-
} catch (e) {
7-
// eval not allowed due to CSP
8-
}
3+
if (!module.hot || process.env.NODE_ENV === 'production') {
4+
module.exports = require('./dist/react-hot-loader.production.min.js');
5+
} else {
6+
var evalAllowed = false;
7+
try {
8+
eval('evalAllowed = true');
9+
} catch (e) {
10+
// eval not allowed due to CSP
11+
}
912

10-
// RHL needs setPrototypeOf to operate Component inheritance, and eval to patch methods
11-
var platformSupported = !!Object.setPrototypeOf && evalAllowed;
13+
// RHL needs setPrototypeOf to operate Component inheritance, and eval to patch methods
14+
var jsFeaturesPresent = typeof window !== 'undefined' && !!Object.setPrototypeOf;
1215

13-
if (!module.hot || process.env.NODE_ENV === 'production' || !platformSupported) {
14-
if (module.hot) {
16+
if (!jsFeaturesPresent && evalAllowed) {
1517
// we are not in prod mode, but RHL could not be activated
16-
console.warn('React-Hot-Loaded is not supported in this environment');
18+
console.warn('React-Hot-Loader is not supported in this environment');
19+
module.exports = require('./dist/react-hot-loader.production.min.js');
20+
} else {
21+
module.exports = window.reactHotLoaderGlobal = require('./dist/react-hot-loader.development.js');
1722
}
18-
module.exports = require('./dist/react-hot-loader.production.min.js');
19-
} else {
20-
module.exports = require('./dist/react-hot-loader.development.js');
2123
}

Diff for: src/index.dev.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ export { enter as enterModule, leave as leaveModule } from './global/modules'
1010
export * from './utils.dev'
1111
export default ReactHotLoader
1212

13-
ReactHotLoader.patch(React, ReactDOM)
13+
if (typeof React !== 'undefined' && typeof ReactDOM !== 'undefined') {
14+
ReactHotLoader.patch(React, ReactDOM)
15+
}

0 commit comments

Comments
 (0)