From d7d69d13e77421d5600b95a4afd07dd202b3cd12 Mon Sep 17 00:00:00 2001 From: Tobias Buschor Date: Wed, 25 May 2022 05:33:28 +0200 Subject: [PATCH] "FocusGroup polyfill" initialize at the right time There are 3 readyStates in this order: 1. loading | | -> DOMContentLoaded fires 2. interactive | | < - script executes, `!complete` ? addEventListener(...) : OneTimeInit() // addEventListener wins | 3. complete If the script is executed between `interactive` and `complete`, `OneTimeInit` does not run right now and the "DOMContentLoaded" listener will never fire. --- Focusgroup/focusgroup_polyfill.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Focusgroup/focusgroup_polyfill.js b/Focusgroup/focusgroup_polyfill.js index 248be0fe..ae067543 100644 --- a/Focusgroup/focusgroup_polyfill.js +++ b/Focusgroup/focusgroup_polyfill.js @@ -276,9 +276,9 @@ function OneTimeInit() { const focusgroupManagers = new WeakMap(); -if ( document.readyState != "complete" ) { - document.addEventListener('DOMContentLoaded', OneTimeInit, { once: true } ); +if ( document.readyState != "loading" ) { + OneTimeInit(); // run right now. } else { - OneTimeInit(); // run right now. + document.addEventListener('DOMContentLoaded', OneTimeInit, { once: true } ); }