From c42c54f69d45e1b55b345343d80456248c469ff9 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Fri, 17 Dec 2021 07:55:51 -0800 Subject: [PATCH] For FB, prefer internal build over global build Summary: This commit makes it so when running the internal version of Flipper, we always prefer the internal build of React DevTools as opposed to a global install of DevTools. Note that users may still change the version the use and select the global version. Externally, i.e. for the OSS build, users will still have the option to always prefer the global build and toggle between it. The motivation for this is to let us ensure that employees are using the latest version of React DevTools and in order to obtain accurate logs of internal usage of DevTools Reviewed By: mweststrate Differential Revision: D33167394 fbshipit-source-id: ee75eedc3a488e223189bbfa6288408bb84824e3 --- .../plugins/public/reactdevtools/index.tsx | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/desktop/plugins/public/reactdevtools/index.tsx b/desktop/plugins/public/reactdevtools/index.tsx index adf1e6193..d525da88b 100644 --- a/desktop/plugins/public/reactdevtools/index.tsx +++ b/desktop/plugins/public/reactdevtools/index.tsx @@ -100,16 +100,26 @@ export function devicePlugin(client: DevicePluginClient) { return required.default ?? required; } - function getInitialDevToolsInstance(): DevToolsInstance { - // Load right library - if (useGlobalDevTools.get()) { - return { - type: 'global', - module: getGlobalDevToolsModule(), - }; + async function maybeGetInitialGlobalDevTools(): Promise { + const path = await findGlobalDevTools(); + let instance = devToolsInstance; + if (path) { + globalDevToolsPath.set(path + '/standalone'); + console.log('Found global React DevTools: ', path); + // load global devtools instance if the flag is set and + // we're running a non-FB version of Flipper + if (useGlobalDevTools.get() && !client.isFB) { + selectedDevToolsInstanceType.set('global'); + + instance = { + type: 'global', + module: getGlobalDevToolsModule(), + }; + } } else { - return getDefaultDevToolsInstance(); + useGlobalDevTools.set(false); // disable in case it was enabled } + return instance; } function getDefaultDevToolsInstance(): DevToolsInstance { @@ -341,16 +351,7 @@ export function devicePlugin(client: DevicePluginClient) { } client.onReady(async () => { - const path = await findGlobalDevTools(); - if (path) { - globalDevToolsPath.set(path + '/standalone'); - selectedDevToolsInstanceType.set('global'); - console.log('Found global React DevTools: ', path); - // load it, if the flag is set - devToolsInstance = getInitialDevToolsInstance(); - } else { - useGlobalDevTools.set(false); // disable in case it was enabled - } + devToolsInstance = await maybeGetInitialGlobalDevTools(); }); client.onDestroy(() => {