From e9ff9addc6d24322346813b6357856ad730963b2 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 27 Jan 2020 04:02:24 -0800 Subject: [PATCH] Fixed broken navigation plugin Summary: The navigation plugin threw exceptions, as the defaultPersisted state was not mixed into the already stored state, making some fields unreadable Reviewed By: jknoxville Differential Revision: D19554291 fbshipit-source-id: 57f045aa1eae10682e44d479b9aecb51f0391b9e --- src/plugins/navigation/index.tsx | 2 +- src/utils/messageQueue.tsx | 22 ++++++++++++++-------- static/icons.json | 5 ++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/plugins/navigation/index.tsx b/src/plugins/navigation/index.tsx index f75e998ce..63ef984e4 100644 --- a/src/plugins/navigation/index.tsx +++ b/src/plugins/navigation/index.tsx @@ -8,7 +8,7 @@ * @flow strict-local */ -import {FlipperPlugin, bufferToBlob, FlexColumn} from 'flipper'; +import {FlipperPlugin, FlexColumn, bufferToBlob} from 'flipper'; import { BookmarksSidebar, SaveBookmarkDialog, diff --git a/src/utils/messageQueue.tsx b/src/utils/messageQueue.tsx index 873714d0f..365b73c0f 100644 --- a/src/utils/messageQueue.tsx +++ b/src/utils/messageQueue.tsx @@ -143,10 +143,7 @@ export function processMessageImmediately( }, message: {method: string; params?: any}, ) { - const persistedState: any = - store.getState().pluginStates[pluginKey] ?? - plugin.defaultPersistedState ?? - {}; + const persistedState = getCurrentPluginState(store, plugin, pluginKey); const newPluginState = processMessage( persistedState, pluginKey, @@ -217,10 +214,7 @@ export async function processMessageQueue( break; } // there are messages to process! lets do so until we have to idle - const persistedState = - store.getState().pluginStates[pluginKey] ?? - plugin.defaultPersistedState ?? - {}; + const persistedState = getCurrentPluginState(store, plugin, pluginKey); let offset = 0; let newPluginState = persistedState; do { @@ -267,3 +261,15 @@ function getPendingMessages( ): Message[] { return store.getState().pluginMessageQueue[pluginKey] || []; } + +function getCurrentPluginState( + store: MiddlewareAPI, + plugin: {defaultPersistedState: any}, + pluginKey: string, +) { + // possible optimization: don't spread default state here by put proper default state when initializing clients + return { + ...plugin.defaultPersistedState, + ...store.getState().pluginStates[pluginKey], + }; +} diff --git a/static/icons.json b/static/icons.json index 2609664fb..867769852 100644 --- a/static/icons.json +++ b/static/icons.json @@ -346,5 +346,8 @@ ], "app-react-outline": [ 16 + ], + "send-outline": [ + 16 ] -} +} \ No newline at end of file