From 5c96b0952bc2a3e0dc168e4e976db968118f6070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Thu, 4 Jul 2019 08:04:07 -0700 Subject: [PATCH] set selectedDevice to null instead of undefined Summary: We are using `redux-persist` to persist parts of our redux store over reloads. In this library, there is a check if a value "was removed to the store". However, they are doing this check by checking if the value of this key is `undefined`. This is not a good way of checking if a property exists on an object, because it can exists but explicitly be set to `undefined`. This was the case for `connections.selectedDevice`, we were setting the value to undefined, once the device disconnected. This caused the key to be persisted, eventhough it wasn't whitelisted for persisting. In this diff, we are setting the `selectedDevice` to `null` instead of `undefined` once a device disconnects. Reviewed By: passy Differential Revision: D16121260 fbshipit-source-id: f32c8ea9e30f02e065fa63380ae0245379a47496 --- src/reducers/connections.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reducers/connections.js b/src/reducers/connections.js index cec7a8bb5..ec3848461 100644 --- a/src/reducers/connections.js +++ b/src/reducers/connections.js @@ -189,7 +189,7 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => { let selection = {}; if (selectedDeviceWasRemoved) { selection = { - selectedDevice: devices[devices.length - 1], + selectedDevice: devices[devices.length - 1] || null, selectedApp: null, selectedPlugin: DEFAULT_PLUGIN, };