From d80078a2242036f187f70cc40dd9722d326692f5 Mon Sep 17 00:00:00 2001
From: Paul Kaplan <pkaplan@media.mit.edu>
Date: Fri, 3 Aug 2018 08:56:30 -0400
Subject: [PATCH] Do not call handleConnected in componentDidMount

Two reasons:
1. Avoid triggering "connected" event, because the device was already connected
2. It is not good to call `setState` in componentDidMount, which is effectively what it was doing.
---
 src/containers/connection-modal.jsx | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/containers/connection-modal.jsx b/src/containers/connection-modal.jsx
index 82b4dbd5f..8edf15e43 100644
--- a/src/containers/connection-modal.jsx
+++ b/src/containers/connection-modal.jsx
@@ -17,18 +17,13 @@ class ConnectionModal extends React.Component {
             'handleHelp'
         ]);
         this.state = {
-            phase: PHASES.scanning
+            phase: props.vm.getPeripheralIsConnected(props.extensionId) ?
+                PHASES.connected : PHASES.scanning
         };
     }
     componentDidMount () {
         this.props.vm.on('PERIPHERAL_CONNECTED', this.handleConnected);
         this.props.vm.on('PERIPHERAL_ERROR', this.handleError);
-
-        // Check if we're already connected
-        if (this.props.vm.getPeripheralIsConnected(this.props.extensionId)) {
-            this.handleConnected();
-        }
-
     }
     componentWillUnmount () {
         this.props.vm.removeListener('PERIPHERAL_CONNECTED', this.handleConnected);
-- 
GitLab