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
This commit is contained in:
Daniel Büchele
2019-04-09 11:01:30 -07:00
committed by Facebook Github Bot
parent f21c9f1c61
commit c4a8e73543

View File

@@ -39,13 +39,6 @@ const SidebarContainer = styled(FlexRow)({
overflow: 'scroll', overflow: 'scroll',
}); });
/*
pluginState: pluginStates[pluginKey],
activePlugin,
target,
deepLinkPayload,
pluginKey,
*/
type OwnProps = {| type OwnProps = {|
logger: Logger, logger: Logger,
|}; |};
@@ -55,7 +48,7 @@ type Props = {|
pluginState: Object, pluginState: Object,
activePlugin: ?Class<FlipperPlugin<> | FlipperDevicePlugin<>>, activePlugin: ?Class<FlipperPlugin<> | FlipperDevicePlugin<>>,
target: Client | BaseDevice | null, target: Client | BaseDevice | null,
pluginKey: string, pluginKey: ?string,
deepLinkPayload: ?string, deepLinkPayload: ?string,
selectPlugin: (payload: {| selectPlugin: (payload: {|
@@ -95,7 +88,8 @@ class PluginContainer extends PureComponent<Props> {
target, target,
isArchivedDevice, isArchivedDevice,
} = this.props; } = this.props;
if (!activePlugin || !target) { if (!activePlugin || !target || !pluginKey) {
console.warn(`No selected plugin. Rendering empty!`);
return null; return null;
} }
const props: PluginProps<Object> = { const props: PluginProps<Object> = {
@@ -158,7 +152,7 @@ export default connect<Props, OwnProps, _, _, _, _>(
pluginStates, pluginStates,
plugins: {devicePlugins, clientPlugins}, plugins: {devicePlugins, clientPlugins},
}) => { }) => {
let pluginKey = 'unknown'; let pluginKey = null;
let target = null; let target = null;
let activePlugin: ?Class<FlipperPlugin<> | FlipperDevicePlugin<>> = null; let activePlugin: ?Class<FlipperPlugin<> | FlipperDevicePlugin<>> = null;
@@ -174,14 +168,11 @@ export default connect<Props, OwnProps, _, _, _, _>(
} else { } else {
target = clients.find((client: Client) => client.id === selectedApp); target = clients.find((client: Client) => client.id === selectedApp);
activePlugin = clientPlugins.get(selectedPlugin); activePlugin = clientPlugins.get(selectedPlugin);
if (!activePlugin || !target) { if (activePlugin && target) {
throw new Error(
`Plugin "${selectedPlugin || ''}" could not be found.`,
);
}
pluginKey = getPluginKey(target.id, activePlugin.id); pluginKey = getPluginKey(target.id, activePlugin.id);
} }
} }
}
const isArchivedDevice = !selectedDevice const isArchivedDevice = !selectedDevice
? false ? false
: selectedDevice instanceof ArchivedDevice; : selectedDevice instanceof ArchivedDevice;