From faee60360582138a64e09f2afb7f8e55ff6c354f Mon Sep 17 00:00:00 2001 From: Chaiwat Ekkaewnumchai Date: Tue, 10 Sep 2019 10:43:09 -0700 Subject: [PATCH] Recreate Array to Prevent Same Memory Usage Summary: Plugin is moved up as soon as it gets clicked because of the same array reference Reviewed By: jknoxville Differential Revision: D17285335 fbshipit-source-id: c4413844fe07a9aed77e4b0e9fb5f5e025d722ca --- src/reducers/connections.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/reducers/connections.tsx b/src/reducers/connections.tsx index 3ae1d4b86..b4bdb74a5 100644 --- a/src/reducers/connections.tsx +++ b/src/reducers/connections.tsx @@ -239,8 +239,12 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => { } const userPreferredApp = selectedApp || state.userPreferredApp; - const LRUPlugins = - (userPreferredApp && state.userLRUPlugins[userPreferredApp]) || []; + // Need to recreate an array to make sure that it doesn't refer to the + // array that is showed in on the screen and the array that is kept for + // least recently used plugins reference + const LRUPlugins = [ + ...((userPreferredApp && state.userLRUPlugins[userPreferredApp]) || []), + ]; const idxLRU = (selectedPlugin && LRUPlugins.indexOf(selectedPlugin)) || -1; if (idxLRU >= 0) {