From 1efea5ddda5939d6a4f304ee6eb963ee98295d7b Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 5 Jul 2025 22:53:40 +0800 Subject: [PATCH] fix readyState check --- src/htmx.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/htmx.js b/src/htmx.js index 4c8203ef2..0ebc82440 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -5035,22 +5035,13 @@ var htmx = (function() { //= =================================================================== // Initialization //= =================================================================== - var isReady = false - getDocument().addEventListener('DOMContentLoaded', function() { - isReady = true - }) - /** * Execute a function now if DOMContentLoaded has fired, otherwise listen for it. - * - * This function uses isReady because there is no reliable way to ask the browser whether - * the DOMContentLoaded event has already been fired; there's a gap between DOMContentLoaded - * firing and readystate=complete. */ function ready(fn) { // Checking readyState here is a failsafe in case the htmx script tag entered the DOM by // some means other than the initial page load. - if (isReady || getDocument().readyState === 'complete') { + if (getDocument().readyState !== 'loading') { fn() } else { getDocument().addEventListener('DOMContentLoaded', fn)