mirror of https://github.com/status-im/metro.git
Fix HMR connection issues when the client gets reconnects
Reviewed By: BYK Differential Revision: D7288613 fbshipit-source-id: ac8b5800af0bfaf1c2a25108b564092e3a47273c
This commit is contained in:
parent
9ca07d83c5
commit
f231396260
|
@ -49,6 +49,16 @@ class DeltaBundler {
|
||||||
this._deltaTransformers = new Map();
|
this._deltaTransformers = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
endTransformer(clientId: string) {
|
||||||
|
const deltaTransformer = this._deltaTransformers.get(clientId);
|
||||||
|
|
||||||
|
if (deltaTransformer) {
|
||||||
|
deltaTransformer.end();
|
||||||
|
|
||||||
|
this._deltaTransformers.delete(clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async getDeltaTransformer(
|
async getDeltaTransformer(
|
||||||
clientId: string,
|
clientId: string,
|
||||||
options: BundleOptions,
|
options: BundleOptions,
|
||||||
|
|
|
@ -26,6 +26,7 @@ import type PackagerServer from '../Server';
|
||||||
import type {Reporter} from '../lib/reporting';
|
import type {Reporter} from '../lib/reporting';
|
||||||
|
|
||||||
type Client = {|
|
type Client = {|
|
||||||
|
clientId: string,
|
||||||
deltaTransformer: DeltaTransformer,
|
deltaTransformer: DeltaTransformer,
|
||||||
sendFn: (data: string) => mixed,
|
sendFn: (data: string) => mixed,
|
||||||
|};
|
|};
|
||||||
|
@ -74,7 +75,7 @@ class HmrServer<TClient: Client> {
|
||||||
this._lastSequenceId = id;
|
this._lastSequenceId = id;
|
||||||
|
|
||||||
// Listen to file changes.
|
// Listen to file changes.
|
||||||
const client = {sendFn, deltaTransformer};
|
const client = {clientId: clientUrl, deltaTransformer, sendFn};
|
||||||
deltaTransformer.on('change', this._handleFileChange.bind(this, client));
|
deltaTransformer.on('change', this._handleFileChange.bind(this, client));
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
|
@ -91,7 +92,7 @@ class HmrServer<TClient: Client> {
|
||||||
onClientDisconnect(client: TClient) {
|
onClientDisconnect(client: TClient) {
|
||||||
// We can safely stop the delta transformer since the
|
// We can safely stop the delta transformer since the
|
||||||
// transformer is not shared between clients.
|
// transformer is not shared between clients.
|
||||||
client.deltaTransformer.end();
|
this._packagerServer.getDeltaBundler().endTransformer(client.clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _handleFileChange(client: Client) {
|
async _handleFileChange(client: Client) {
|
||||||
|
|
Loading…
Reference in New Issue