Skip to content

Commit

Permalink
fix: remove platform checks from production bundle, fixes #1162
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Jan 26, 2019
1 parent 73068c7 commit 24d0448
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1,978 deletions.
30 changes: 16 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
'use strict'

var evalAllowed = false;
try {
eval('evalAllowed = true');
} catch (e) {
// eval not allowed due to CSP
}
if (!module.hot || process.env.NODE_ENV === 'production') {
module.exports = require('./dist/react-hot-loader.production.min.js');
} else {
var evalAllowed = false;
try {
eval('evalAllowed = true');
} catch (e) {
// eval not allowed due to CSP
}

// RHL needs setPrototypeOf to operate Component inheritance, and eval to patch methods
var platformSupported = !!Object.setPrototypeOf && evalAllowed;
// RHL needs setPrototypeOf to operate Component inheritance, and eval to patch methods
var jsFeaturesPresent = typeof window !== 'undefined' && !!Object.setPrototypeOf;

if (!module.hot || process.env.NODE_ENV === 'production' || !platformSupported) {
if (module.hot) {
if (!jsFeaturesPresent && evalAllowed) {
// we are not in prod mode, but RHL could not be activated
console.warn('React-Hot-Loaded is not supported in this environment');
console.warn('React-Hot-Loader is not supported in this environment');
module.exports = require('./dist/react-hot-loader.production.min.js');
} else {
module.exports = window.reactHotLoaderGlobal = require('./dist/react-hot-loader.development.js');
}
module.exports = require('./dist/react-hot-loader.production.min.js');
} else {
module.exports = require('./dist/react-hot-loader.development.js');
}
4 changes: 3 additions & 1 deletion src/index.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ export { enter as enterModule, leave as leaveModule } from './global/modules'
export * from './utils.dev'
export default ReactHotLoader

ReactHotLoader.patch(React, ReactDOM)
if (typeof React !== 'undefined' && typeof ReactDOM !== 'undefined') {
ReactHotLoader.patch(React, ReactDOM)
}

0 comments on commit 24d0448

Please sign in to comment.