Skip to content

Commit b24a89a

Browse files
michalkvasnicakfeiqitian
authored andcommitted
Make webpackHotDevClient support webpack 2 too (facebook#840)
* Support webpack 2 * Code style
1 parent 91c0731 commit b24a89a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

packages/react-dev-utils/webpackHotDevClient.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ function tryApplyUpdates(onHotUpdateSuccess) {
272272
return;
273273
}
274274

275-
// https://webpack.github.io/docs/hot-module-replacement.html#check
276-
module.hot.check(/* autoApply */true, function(err, updatedModules) {
275+
function handleApplyUpdates(err, updatedModules) {
277276
if (err || !updatedModules) {
278277
window.location.reload();
279278
return;
@@ -288,5 +287,20 @@ function tryApplyUpdates(onHotUpdateSuccess) {
288287
// While we were updating, there was a new update! Do it again.
289288
tryApplyUpdates();
290289
}
291-
});
290+
}
291+
292+
// https://webpack.github.io/docs/hot-module-replacement.html#check
293+
var result = module.hot.check(/* autoApply */true, handleApplyUpdates);
294+
295+
// // Webpack 2 returns a Promise instead of invoking a callback
296+
if (result && result.then) {
297+
result.then(
298+
function(updatedModules) {
299+
handleApplyUpdates(null, updatedModules);
300+
},
301+
function(err) {
302+
handleApplyUpdates(err, null);
303+
}
304+
);
305+
}
292306
};

0 commit comments

Comments
 (0)