From d54986c49cbcb217a831769766abc87f6ceb52cd Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Wed, 26 Oct 2022 20:09:32 -0700 Subject: [PATCH] Log Abnormal Closes to Metro Websocket Summary: We are running into a group seeing frequent disconnects from Metro in a specific office. These are surfaced (at least on iOS) as websocket closures, without a prior websocket error. WebSocket closure can be for a variety of reasons, and the spec for a CloseEvent is to include fields `wasClean`, `code`, and `reason`, with `code` having the most well-defined meaning. This change makes it so that we emit extra context when the websocket is closed. That should help inform developers the reason behind any close that may be abnormal. Changelog: [General][Added] - Log Abnormal Closes to Metro Websocket Reviewed By: motiz88 Differential Revision: D40660765 fbshipit-source-id: ef606d8d809af1c697a78eb00cc5666c29a8bca3 --- packages/metro-runtime/src/modules/HMRClient.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/metro-runtime/src/modules/HMRClient.js b/packages/metro-runtime/src/modules/HMRClient.js index 581fc76fe2..751da32fc7 100644 --- a/packages/metro-runtime/src/modules/HMRClient.js +++ b/packages/metro-runtime/src/modules/HMRClient.js @@ -55,9 +55,9 @@ class HMRClient extends EventEmitter { this._ws.onerror = error => { this.emit('connection-error', error); }; - this._ws.onclose = () => { + this._ws.onclose = closeEvent => { this._state = 'closed'; - this.emit('close'); + this.emit('close', closeEvent); }; this._ws.onmessage = message => { const data: HmrMessage = JSON.parse(String(message.data));