Make sure client is still connected while computing HMR update

Reviewed By: vjeux

Differential Revision: D2803506

fb-gh-sync-id: a182343947d52724e48709a8114fa48e8c97a7e2
This commit is contained in:
Martín Bigio 2016-01-06 13:28:58 -08:00 committed by facebook-github-bot-3
parent 0b15418d92
commit bdbadfd966

View File

@ -113,6 +113,10 @@ function attachHMRServer({httpServer, path, packagerServer}) {
return packagerServer.getShallowDependencies(filename)
.then(deps => {
if (!client) {
return [];
}
// if the file dependencies have change we need to invalidate the
// dependencies caches because the list of files we need to send
// to the client may have changed
@ -129,6 +133,10 @@ function attachHMRServer({httpServer, path, packagerServer}) {
dependenciesModulesCache,
shallowDependencies,
}) => {
if (!client) {
return [];
}
// build list of modules for which we'll send HMR updates
const modulesToUpdate = [];
Object.keys(dependenciesModulesCache).forEach(module => {
@ -146,6 +154,10 @@ function attachHMRServer({httpServer, path, packagerServer}) {
});
})
.then(modulesToUpdate => {
if (!client) {
return;
}
// make sure the file was modified is part of the bundle
if (!client.shallowDependencies[filename]) {
return;
@ -158,6 +170,11 @@ function attachHMRServer({httpServer, path, packagerServer}) {
});
})
.then(bundle => {
if (!client) {
return;
}
// check we actually want to send an HMR update
if (bundle) {
client.ws.send(bundle);
}