Skip to content

Commit

Permalink
(1.3) Fix ReactMount import for React 15.4 (#430)
Browse files Browse the repository at this point in the history
* Fix ReactMount import for React 15.4

Keep supporting pre-15.4 by using a try-catch and adding the correct
import statement based on whether importing it from react-dom (the new
way) fails.
  • Loading branch information
calesce committed Nov 28, 2016
1 parent 3c8630c commit 7509f42
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ module.exports = function (source, map) {
node,
result;

var reactMountImport;
try {
require('react-dom/lib/ReactMount');
reactMountImport = 'ReactMount = require("react-dom/lib/ReactMount"),';
} catch(e) {
reactMountImport = 'ReactMount = require("react/lib/ReactMount"),';
}

prependText = [
'/* REACT HOT LOADER */',
'if (module.hot) {',
'(function () {',
'var ReactHotAPI = require(' + JSON.stringify(require.resolve('react-hot-api')) + '),',
'RootInstanceProvider = require(' + JSON.stringify(require.resolve('./RootInstanceProvider')) + '),',
'ReactMount = require("react/lib/ReactMount"),',
reactMountImport,
'React = require("react");',

'module.makeHot = module.hot.data ? module.hot.data.makeHot : ReactHotAPI(function () {',
Expand Down

0 comments on commit 7509f42

Please sign in to comment.