From c4a8e73543be31a7f9bb4c458a844ea916b61089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Tue, 9 Apr 2019 11:01:30 -0700 Subject: [PATCH] Don't throw if selectedPlugin doesn't exist Summary: When a plugin was selected the last time Flipper was running, but is not available anymore, Flipper was still trying to load the plugin and failed. Now, if the selected plugin is not available, we just don't render anything. Reviewed By: jknoxville Differential Revision: D14854930 fbshipit-source-id: 9ddec47becce7bffcf93b3f4a092a8fcf2022f4f --- src/PluginContainer.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/PluginContainer.js b/src/PluginContainer.js index aa76973e5..126d7ba8c 100644 --- a/src/PluginContainer.js +++ b/src/PluginContainer.js @@ -39,13 +39,6 @@ const SidebarContainer = styled(FlexRow)({ overflow: 'scroll', }); -/* -pluginState: pluginStates[pluginKey], -activePlugin, -target, -deepLinkPayload, -pluginKey, -*/ type OwnProps = {| logger: Logger, |}; @@ -55,7 +48,7 @@ type Props = {| pluginState: Object, activePlugin: ?Class | FlipperDevicePlugin<>>, target: Client | BaseDevice | null, - pluginKey: string, + pluginKey: ?string, deepLinkPayload: ?string, selectPlugin: (payload: {| @@ -95,7 +88,8 @@ class PluginContainer extends PureComponent { target, isArchivedDevice, } = this.props; - if (!activePlugin || !target) { + if (!activePlugin || !target || !pluginKey) { + console.warn(`No selected plugin. Rendering empty!`); return null; } const props: PluginProps = { @@ -158,7 +152,7 @@ export default connect( pluginStates, plugins: {devicePlugins, clientPlugins}, }) => { - let pluginKey = 'unknown'; + let pluginKey = null; let target = null; let activePlugin: ?Class | FlipperDevicePlugin<>> = null; @@ -174,12 +168,9 @@ export default connect( } else { target = clients.find((client: Client) => client.id === selectedApp); activePlugin = clientPlugins.get(selectedPlugin); - if (!activePlugin || !target) { - throw new Error( - `Plugin "${selectedPlugin || ''}" could not be found.`, - ); + if (activePlugin && target) { + pluginKey = getPluginKey(target.id, activePlugin.id); } - pluginKey = getPluginKey(target.id, activePlugin.id); } } const isArchivedDevice = !selectedDevice