Fix condition on processing message queues for sandy plugins

Summary:
While converting Bloks-Script plugin, Timur found a bug where the message queue wasn't processed.

Although queue processing was unit tested, the integration into the rendering lifecycle wasn't explicitly tested and missed a TODO that already signalled this should have been implemented.

Added a unit test to verify the bug and fix. Also tested in a running Flipper instance with the converted plugin (next diff)

Reviewed By: jknoxville

Differential Revision: D23263909

fbshipit-source-id: 63783c980247bdf6c93d00a46881d7d0eb291d09
This commit is contained in:
Michel Weststrate
2020-08-21 09:07:22 -07:00
committed by Facebook GitHub Bot
parent 6c7748238d
commit 76b72f3d77
2 changed files with 103 additions and 23 deletions

View File

@@ -48,6 +48,7 @@ import {Idler} from './utils/Idler';
import {processMessageQueue} from './utils/messageQueue';
import {ToggleButton, SmallText} from './ui';
import {SandyPluginRenderer} from 'flipper-plugin';
import {isDevicePluginDefinition} from './utils/pluginUtils';
const Container = styled(FlexColumn)({
width: 0,
@@ -193,24 +194,30 @@ class PluginContainer extends PureComponent<Props, State> {
pendingMessages,
activePlugin,
pluginIsEnabled,
target,
} = this.props;
if (pluginKey !== this.pluginBeingProcessed) {
this.pluginBeingProcessed = pluginKey;
this.cancelCurrentQueue();
this.setState({progress: {current: 0, total: 0}});
// device plugins don't have connections so no message queues
if (!activePlugin || isDevicePluginDefinition(activePlugin)) {
return;
}
if (
pluginIsEnabled &&
target instanceof Client &&
activePlugin &&
// TODO: support sandy: T68683442
!isSandyPlugin(activePlugin) &&
activePlugin.persistedStateReducer &&
(isSandyPlugin(activePlugin) || activePlugin.persistedStateReducer) &&
pluginKey &&
pendingMessages?.length
) {
const start = Date.now();
this.idler = new Idler();
processMessageQueue(
activePlugin,
isSandyPlugin(activePlugin)
? target.sandyPluginStates.get(activePlugin.id)!
: activePlugin,
pluginKey,
this.store,
(progress) => {