From 7378e116d6b7537808616ec3d70b6b3f5af342b8 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Mon, 9 Dec 2019 20:58:09 +0100 Subject: [PATCH] Automated cherry pick of #3677 (#3679) * MM-21085 Updated waitHydration Updated the hydration of hte store to first check if it completed as this was being caused due to a race condition. * MM-21085 Updated for callback MM-21085 Updated for callback --- app/store/utils.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/store/utils.js b/app/store/utils.js index 192b70826..494ba42b1 100644 --- a/app/store/utils.js +++ b/app/store/utils.js @@ -42,14 +42,20 @@ export function transformSet(incoming, setTransforms, toStorage = true) { } export function waitForHydration(store, callback) { - const subscription = () => { - if (store.getState().views.root.hydrationComplete) { - unsubscribeFromStore(); - if (callback && typeof callback === 'function') { - callback(); - } + if (store.getState().views.root.hydrationComplete) { + if (callback && typeof callback === 'function') { + callback(); } - }; + } else { + const subscription = () => { + if (store.getState().views.root.hydrationComplete) { + unsubscribeFromStore(); + if (callback && typeof callback === 'function') { + callback(); + } + } + }; - const unsubscribeFromStore = store.subscribe(subscription); + const unsubscribeFromStore = store.subscribe(subscription); + } } \ No newline at end of file