Skip to content

Commit

Permalink
Catch and log module load errors to avoid browser reload (fixes #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Aug 26, 2014
1 parent 8ed94ba commit f3485dc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = function (source) {
this.cacheable();
}

var matches = 0,
var filename = path.basename(this.resourcePath),
matches = 0,
processedSource;

processedSource = source.replace(/React\.createClass\s*\(\s*\{/g, function (match) {
Expand All @@ -21,11 +22,15 @@ module.exports = function (source) {
'var __hotUpdateAPI = (function () {',
' var React = require("react");',
' var getHotUpdateAPI = require(' + JSON.stringify(require.resolve('./getHotUpdateAPI')) + ');',
' return getHotUpdateAPI(React, ' + JSON.stringify(path.basename(this.resourcePath)) + ', module.id);',
' return getHotUpdateAPI(React, ' + JSON.stringify(filename) + ', module.id);',
'})();',
processedSource,
'if (module.hot) {',
' module.hot.accept();',
' module.hot.accept(function (err) {',
' if (err) {',
' console.error("Cannot not apply hot update to " + ' + JSON.stringify(filename) + ' + ": " + err.message);',
' }',
' });',
' module.hot.dispose(function () {',
' var nextTick = require(' + JSON.stringify(require.resolve('next-tick')) + ');',
' nextTick(__hotUpdateAPI.updateMountedInstances);',
Expand Down

1 comment on commit f3485dc

@syranide
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works great! 👍

Please sign in to comment.