From 4feff2acf76c73a48bbb42ca783e8aa674cd8653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kvasni=C4=8D=C3=A1k?= <michal.kvasnicak@gmail.com> Date: Tue, 4 Oct 2016 14:25:13 +0200 Subject: [PATCH] Make webpackHotDevClient support webpack 2 too (#840) * Support webpack 2 * Code style --- .../react-dev-utils/webpackHotDevClient.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/react-dev-utils/webpackHotDevClient.js b/packages/react-dev-utils/webpackHotDevClient.js index 391db9621..eebf6c0a2 100644 --- a/packages/react-dev-utils/webpackHotDevClient.js +++ b/packages/react-dev-utils/webpackHotDevClient.js @@ -272,8 +272,7 @@ function tryApplyUpdates(onHotUpdateSuccess) { return; } - // https://webpack.github.io/docs/hot-module-replacement.html#check - module.hot.check(/* autoApply */true, function(err, updatedModules) { + function handleApplyUpdates(err, updatedModules) { if (err || !updatedModules) { window.location.reload(); return; @@ -288,5 +287,20 @@ function tryApplyUpdates(onHotUpdateSuccess) { // While we were updating, there was a new update! Do it again. tryApplyUpdates(); } - }); + } + + // https://webpack.github.io/docs/hot-module-replacement.html#check + var result = module.hot.check(/* autoApply */true, handleApplyUpdates); + + // // Webpack 2 returns a Promise instead of invoking a callback + if (result && result.then) { + result.then( + function(updatedModules) { + handleApplyUpdates(null, updatedModules); + }, + function(err) { + handleApplyUpdates(err, null); + } + ); + } }; -- GitLab