From 40f9b385bb75b05979dc905486c34e6223e1f1bd Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Fri, 10 Jan 2020 06:30:41 -0800 Subject: [PATCH] Fix refresh plugins not having any effect Summary: If a plugin was registered beyond the initial start command, this didn't show up in the Flipper UI. The reason for this is that the client map is updated, but since that object is mutable, components won't detect nor reflect the change. This diff changes to make sure a new plugin map is created if it is changed. Reviewed By: passy Differential Revision: D19345464 fbshipit-source-id: 3aa343e1739caf124a015c88680a94973b87f701 --- package.json | 2 +- src/reducers/plugins.tsx | 33 +++++++++++++++------------------ yarn.lock | 8 ++++---- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 4b0f838e3..64f6d7ce2 100644 --- a/package.json +++ b/package.json @@ -143,7 +143,7 @@ "fb-watchman": "^2.0.0", "flipper-doctor": "^0.6.0", "fs-extra": "^8.0.1", - "immer": "^5.0.1", + "immer": "^5.2.1", "immutable": "^4.0.0-rc.12", "invariant": "^2.2.2", "line-replace": "^1.0.2", diff --git a/src/reducers/plugins.tsx b/src/reducers/plugins.tsx index 2846e6629..1ab925339 100644 --- a/src/reducers/plugins.tsx +++ b/src/reducers/plugins.tsx @@ -10,6 +10,7 @@ import {FlipperPlugin, FlipperDevicePlugin} from '../plugin'; import {PluginDefinition} from '../dispatcher/plugins'; import {Actions} from '.'; +import produce from 'immer'; export type State = { devicePlugins: Map; @@ -58,26 +59,22 @@ export default function reducer( action: Actions, ): State { if (action.type === 'REGISTER_PLUGINS') { - const {devicePlugins, clientPlugins} = state; + return produce(state, draft => { + const {devicePlugins, clientPlugins} = draft; + action.payload.forEach((p: P) => { + if (devicePlugins.has(p.id) || clientPlugins.has(p.id)) { + return; + } - action.payload.forEach((p: P) => { - if (devicePlugins.has(p.id) || clientPlugins.has(p.id)) { - return; - } - - if (p.prototype instanceof FlipperDevicePlugin) { - // @ts-ignore doesn't know p must be typeof FlipperDevicePlugin here - devicePlugins.set(p.id, p); - } else if (p.prototype instanceof FlipperPlugin) { - // @ts-ignore doesn't know p must be typeof FlipperPlugin here - clientPlugins.set(p.id, p); - } + if (p.prototype instanceof FlipperDevicePlugin) { + // @ts-ignore doesn't know p must be typeof FlipperDevicePlugin here + devicePlugins.set(p.id, p); + } else if (p.prototype instanceof FlipperPlugin) { + // @ts-ignore doesn't know p must be typeof FlipperPlugin here + clientPlugins.set(p.id, p); + } + }); }); - return { - ...state, - devicePlugins, - clientPlugins, - }; } else if (action.type === 'GATEKEEPED_PLUGINS') { return { ...state, diff --git a/yarn.lock b/yarn.lock index 2d73e3c17..d43b046a5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4779,10 +4779,10 @@ ignore@^5.1.1: resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.4.tgz#84b7b3dbe64552b6ef0eca99f6743dbec6d97adf" integrity sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A== -immer@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/immer/-/immer-5.0.1.tgz#1a1184fa758f68f1b5573db840825fb5164cceca" - integrity sha512-KFHV1ivrBmPCVRhjy9oBooypnPfJ876NTrWXMNoUhXFAaWWAViVqZ4l6HxPST52qcN82qqsR38/pCGYRWP5W7w== +immer@^5.2.1: + version "5.2.1" + resolved "https://registry.yarnpkg.com/immer/-/immer-5.2.1.tgz#7d4f74c242178e87151d595f48db1b5c51580485" + integrity sha512-9U1GEbJuH6nVoyuFRgTQDGMzcBuNBPfXM3M7Pp/sdmYKTKYOBUZGgeUb9H57GfLK/xC1DMLarWX2FrhMBfUJ8g== immutable@^4.0.0-rc.12: version "4.0.0-rc.12"