From 38ec30bc2efb0edc525ab733f5a3b9ceb0274fad Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Fri, 29 Sep 2017 17:56:26 -0700 Subject: [PATCH] Fix error appearing when disconnecting HMR client Reviewed By: cpojer Differential Revision: D5944285 fbshipit-source-id: 5751f6ad2b999872aa3d33e1c7fca105b3156da4 --- local-cli/server/util/attachWebsocketServer.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/local-cli/server/util/attachWebsocketServer.js b/local-cli/server/util/attachWebsocketServer.js index ae9efed0f..fcbe0f719 100644 --- a/local-cli/server/util/attachWebsocketServer.js +++ b/local-cli/server/util/attachWebsocketServer.js @@ -47,9 +47,14 @@ function attachWebsocketServer({ }); wss.on('connection', async ws => { + let connected = true; const url = ws.upgradeReq.url; - const sendFn = ws.send.bind(ws); + const sendFn = (...args) => { + if (connected) { + ws.send(...args); + } + }; const client = await websocketServer.onClientConnect(url, sendFn); @@ -60,6 +65,7 @@ function attachWebsocketServer({ ws.on('close', () => { websocketServer.onClientDisconnect && websocketServer.onClientDisconnect(client); + connected = false; }); ws.on('message', message => {