mirror of
https://github.com/status-im/metro.git
synced 2025-02-11 18:47:20 +00:00
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:
parent
0680259ad4
commit
28b3bbefaf
13
react-packager/src/Server/index.js
vendored
13
react-packager/src/Server/index.js
vendored
@ -180,16 +180,23 @@ class Server {
|
||||
this._fileWatcher.on('all', this._onFileChange.bind(this));
|
||||
|
||||
this._debouncedFileChangeHandler = _.debounce(filePath => {
|
||||
const onFileChange = () => {
|
||||
this._rebuildBundles(filePath);
|
||||
this._informChangeWatchers();
|
||||
};
|
||||
|
||||
// if Hot Loading is enabled avoid rebuilding bundles and sending live
|
||||
// updates. Instead, send the HMR updates right away and once that
|
||||
// finishes, invoke any other file change listener.
|
||||
if (this._hmrFileChangeListener) {
|
||||
this._hmrFileChangeListener(filePath, this._bundler.stat(filePath));
|
||||
this._hmrFileChangeListener(
|
||||
filePath,
|
||||
this._bundler.stat(filePath),
|
||||
).then(onFileChange).done();
|
||||
return;
|
||||
}
|
||||
|
||||
this._rebuildBundles(filePath);
|
||||
this._informChangeWatchers();
|
||||
onFileChange();
|
||||
}, 50);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user