From 957427d7408b3eeca2b73c99be26f3462aa7cc4f Mon Sep 17 00:00:00 2001 From: John Knox Date: Thu, 3 Oct 2019 07:16:33 -0700 Subject: [PATCH] Fix startup race condition Summary: Currently Flipper.init is called as soon as the script loads. However, if the store takes a bit longer than usual to get rehydrated, then this init call can get called before it has been set. Fixing it by using a specific event instead of the generic `onload`. Reviewed By: passy Differential Revision: D17711399 fbshipit-source-id: fcaf9e5943bfd15359038b8e3722f11d7e06379b --- src/init.tsx | 1 + static/index.dev.html | 5 +---- static/index.html | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/init.tsx b/src/init.tsx index c70174c78..17c52f9e0 100644 --- a/src/init.tsx +++ b/src/init.tsx @@ -88,4 +88,5 @@ persistStore(store, undefined, () => { dispatcher(store, logger); // make init function callable from outside window.Flipper.init = init; + window.dispatchEvent(new Event('flipper-store-ready')); }); diff --git a/static/index.dev.html b/static/index.dev.html index 54ff02b3f..c9ce6e76f 100644 --- a/static/index.dev.html +++ b/static/index.dev.html @@ -85,13 +85,10 @@ openError('Script failure. Check Chrome console for more info.'); }; - script.onload = () => { - global.Flipper.init(); - }; + window.addEventListener('flipper-store-ready', () => global.Flipper.init()); document.body.appendChild(script); } - init(); })(); diff --git a/static/index.html b/static/index.html index 773570b77..55e7ae0ed 100644 --- a/static/index.html +++ b/static/index.html @@ -13,9 +13,9 @@ - +