From fab4ee8c22fe1a52ad130e0d4a5e9330d628cd7e Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Thu, 15 Sep 2022 10:02:19 -0700 Subject: [PATCH] Unload stale modules from electron cache Summary: `requirePlugin` in electron uses native `require` which has a built-in cache. Without this fix a stale version of the plugin loaded. Reviewed By: lblasa Differential Revision: D39542121 fbshipit-source-id: e6c4b65f9ea7b816803baaae537c234914fcb3d7 --- .../flipper-ui-core/src/dispatcher/pluginManager.tsx | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/desktop/flipper-ui-core/src/dispatcher/pluginManager.tsx b/desktop/flipper-ui-core/src/dispatcher/pluginManager.tsx index e998eac17..bc9ed557b 100644 --- a/desktop/flipper-ui-core/src/dispatcher/pluginManager.tsx +++ b/desktop/flipper-ui-core/src/dispatcher/pluginManager.tsx @@ -160,6 +160,7 @@ async function processPluginCommandsQueue( async function loadPlugin(store: Store, payload: LoadPluginActionPayload) { try { + unloadPluginModule(payload.plugin); const plugin = await requirePlugin(payload.plugin); const enablePlugin = payload.enable; updatePlugin(store, {plugin, enablePlugin}); @@ -292,7 +293,6 @@ function updateClientPlugin( .connections.enabledPlugins[c.query.app]?.includes(plugin.id) ); }); - const previousVersion = store.getState().plugins.clientPlugins.get(plugin.id); clientsWithEnabledPlugin.forEach((client) => { stopPlugin(client, plugin.id); }); @@ -300,10 +300,6 @@ function updateClientPlugin( startPlugin(client, plugin, true); }); store.dispatch(pluginLoaded(plugin)); - if (previousVersion) { - // unload previous version from Electron cache - unloadPluginModule(previousVersion.details); - } } function updateDevicePlugin( @@ -321,11 +317,6 @@ function updateDevicePlugin( devicesWithEnabledPlugin.forEach((d) => { d.unloadDevicePlugin(plugin.id); }); - const previousVersion = store.getState().plugins.devicePlugins.get(plugin.id); - if (previousVersion) { - // unload previous version from Electron cache - unloadPluginModule(previousVersion.details); - } store.dispatch(pluginLoaded(plugin)); devicesWithEnabledPlugin.forEach((d) => { d.loadDevicePlugin(plugin);