Skip to content

Commit

Permalink
fix: explain why RHL could not be activated, fixes #1362
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Nov 2, 2019
1 parent af42c1a commit 9561d66
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,28 @@ if (process.env.NODE_ENV === 'production') {
module.exports.hot.shouldWrapWithAppContainer = true;
} else {
var evalAllowed = false;
var evalError = null;
try {
eval('evalAllowed = true');
} catch (e) {
// eval not allowed due to CSP
evalError = e && e.message ? e.message : 'unknown reason';
}

// TODO: dont use eval to update methods. see #1273
// RHL needs setPrototypeOf to operate Component inheritance, and eval to patch methods
var jsFeaturesPresent = !!Object.setPrototypeOf;

if (!jsFeaturesPresent || !evalAllowed) {
// we are not in prod mode, but RHL could not be activated
console.warn('React-Hot-Loader is not supported in this environment.');
console.warn(
'React-Hot-Loader is not supported in this environment:',
[
!jsFeaturesPresent && "some JS features are missing",
!evalAllowed && "`eval` is not allowed(" + evalError + ")"
].join(','),
'.'
);
module.exports = require('./dist/react-hot-loader.production.min.js');
} else {
module.exports = window.reactHotLoaderGlobal = require('./dist/react-hot-loader.development.js');
Expand Down

0 comments on commit 9561d66

Please sign in to comment.