Fix HMR connection issues when the client gets reconnects

Reviewed By: BYK

Differential Revision: D7288613

fbshipit-source-id: ac8b5800af0bfaf1c2a25108b564092e3a47273c
This commit is contained in:
Rafael Oleza 2018-03-15 15:28:00 -07:00 committed by Facebook Github Bot
parent 9ca07d83c5
commit f231396260
2 changed files with 13 additions and 2 deletions

View File

@ -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,

View File

@ -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) {