From 871df00087cff16698cd598662f26a25b34f1183 Mon Sep 17 00:00:00 2001
From: Lauri Eskola <lauri.eskola@acquia.com>
Date: Tue, 23 Jun 2020 15:33:26 +0300
Subject: [PATCH] Issue #3096516 by narendra.rajwar27, nod_, Charlie ChX
 Negyesi: domready has a race condition

---
 core/misc/drupal.init.es6.js |  8 ++++----
 core/misc/drupal.init.js     | 10 +++++-----
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/core/misc/drupal.init.es6.js b/core/misc/drupal.init.es6.js
index f8706db11a9b..686a062c9790 100644
--- a/core/misc/drupal.init.es6.js
+++ b/core/misc/drupal.init.es6.js
@@ -16,13 +16,13 @@ document.documentElement.className += ' js';
    *   The function to be called on document ready.
    */
   const domReady = callback => {
+    const listener = () => {
+      callback();
+      document.removeEventListener('DOMContentLoaded', listener);
+    };
     if (document.readyState !== 'loading') {
       callback();
     } else {
-      const listener = () => {
-        callback();
-        document.removeEventListener('DOMContentLoaded', listener);
-      };
       document.addEventListener('DOMContentLoaded', listener);
     }
   };
diff --git a/core/misc/drupal.init.js b/core/misc/drupal.init.js
index 4e58fc5e56f9..9b158bab3018 100644
--- a/core/misc/drupal.init.js
+++ b/core/misc/drupal.init.js
@@ -13,14 +13,14 @@ document.documentElement.className += ' js';
 
 (function (Drupal, drupalSettings) {
   var domReady = function domReady(callback) {
+    var listener = function listener() {
+      callback();
+      document.removeEventListener('DOMContentLoaded', listener);
+    };
+
     if (document.readyState !== 'loading') {
       callback();
     } else {
-      var listener = function listener() {
-        callback();
-        document.removeEventListener('DOMContentLoaded', listener);
-      };
-
       document.addEventListener('DOMContentLoaded', listener);
     }
   };
-- 
GitLab