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
This commit is contained in:
John Knox
2019-10-03 07:16:33 -07:00
committed by Facebook Github Bot
parent b3a98dc5e5
commit 957427d740
3 changed files with 4 additions and 6 deletions

View File

@@ -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'));
});

View File

@@ -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();
})();
</script>

View File

@@ -13,9 +13,9 @@
<script>
global.electronRequire = window.require;
</script>
<script src="bundle.js"></script>
<script>
global.Flipper.init();
window.addEventListener('flipper-store-ready', () => global.Flipper.init());
</script>
<script src="bundle.js"></script>
</body>
</html>