diff --git a/packages/metro/src/DeltaBundler/index.js b/packages/metro/src/DeltaBundler/index.js index 7bebc383..5e8f31e9 100644 --- a/packages/metro/src/DeltaBundler/index.js +++ b/packages/metro/src/DeltaBundler/index.js @@ -49,6 +49,16 @@ class DeltaBundler { this._deltaTransformers = new Map(); } + endTransformer(clientId: string) { + const deltaTransformer = this._deltaTransformers.get(clientId); + + if (deltaTransformer) { + deltaTransformer.end(); + + this._deltaTransformers.delete(clientId); + } + } + async getDeltaTransformer( clientId: string, options: BundleOptions, diff --git a/packages/metro/src/HmrServer/index.js b/packages/metro/src/HmrServer/index.js index 34a9c382..4a42724c 100644 --- a/packages/metro/src/HmrServer/index.js +++ b/packages/metro/src/HmrServer/index.js @@ -26,6 +26,7 @@ import type PackagerServer from '../Server'; import type {Reporter} from '../lib/reporting'; type Client = {| + clientId: string, deltaTransformer: DeltaTransformer, sendFn: (data: string) => mixed, |}; @@ -74,7 +75,7 @@ class HmrServer { this._lastSequenceId = id; // Listen to file changes. - const client = {sendFn, deltaTransformer}; + const client = {clientId: clientUrl, deltaTransformer, sendFn}; deltaTransformer.on('change', this._handleFileChange.bind(this, client)); return client; @@ -91,7 +92,7 @@ class HmrServer { onClientDisconnect(client: TClient) { // We can safely stop the delta transformer since the // transformer is not shared between clients. - client.deltaTransformer.end(); + this._packagerServer.getDeltaBundler().endTransformer(client.clientId); } async _handleFileChange(client: Client) {