Fixes Hot Loading re-loading bug

Summary:
public

Fixes a terrible bug due to which when Hot Loading enabled when the user reloads we'll serve them the first `hot` bundle he requested. This happened because when HMR enabled we bailed out after sending the HMR updates and didn't rebuild any of the bundles the user requested before. As a consequence, when they reload we'd sent him the first and only one we ever built.

The fix is to tweak the hmr listener to return a promise. This way we can run the remaining code on the file change listener just after the HMR stuff finishes. We need to do it this way to avoid the remaining stuff to compete for CPU with the HMR one and give the best possible experience when HMR is enabled.

Reviewed By: davidaurelio

Differential Revision: D2811382

fb-gh-sync-id: 906932d71f35467485cf8a865a8d59f4d2ff41a0
This commit is contained in:
Martín Bigio 2016-01-07 10:39:13 -08:00 committed by facebook-github-bot-3
parent 0680259ad4
commit 28b3bbefaf
1 changed files with 10 additions and 3 deletions

View File

@ -180,16 +180,23 @@ class Server {
this._fileWatcher.on('all', this._onFileChange.bind(this)); this._fileWatcher.on('all', this._onFileChange.bind(this));
this._debouncedFileChangeHandler = _.debounce(filePath => { this._debouncedFileChangeHandler = _.debounce(filePath => {
const onFileChange = () => {
this._rebuildBundles(filePath);
this._informChangeWatchers();
};
// if Hot Loading is enabled avoid rebuilding bundles and sending live // if Hot Loading is enabled avoid rebuilding bundles and sending live
// updates. Instead, send the HMR updates right away and once that // updates. Instead, send the HMR updates right away and once that
// finishes, invoke any other file change listener. // finishes, invoke any other file change listener.
if (this._hmrFileChangeListener) { if (this._hmrFileChangeListener) {
this._hmrFileChangeListener(filePath, this._bundler.stat(filePath)); this._hmrFileChangeListener(
filePath,
this._bundler.stat(filePath),
).then(onFileChange).done();
return; return;
} }
this._rebuildBundles(filePath); onFileChange();
this._informChangeWatchers();
}, 50); }, 50);
} }