From 1ac82b8df2a9df2d78cd723ae663b53c33663d7b Mon Sep 17 00:00:00 2001 From: CJ <38697367+imisshtml@users.noreply.github.com> Date: Mon, 9 Dec 2019 14:54:41 -0500 Subject: [PATCH] MM-21085 Updated waitHydration (#3677) * 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