Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -5012,9 +5012,20 @@ var htmx = (function() {
// Initialization
//= ===================================================================
var isReady = false
getDocument().addEventListener('DOMContentLoaded', function() {
var readyFunctions = []
/*
* When the HTMX lib is loaded async, the DOMContentLoaded event never fires, so the
* ready functions never trigger. (https://github.com/bigskysoftware/htmx/issues/3165)
* To make sure this never happens, we will listen to both DOMContentLoaded and window.onload
*/
function triggerReadyFunctions() {
if (!readyFunctions) { return }
isReady = true
})
readyFunctions.forEach(x => x())
readyFunctions = undefined
}
getDocument().addEventListener('DOMContentLoaded', triggerReadyFunctions)
window.onload = triggerReadyFunctions

/**
* Execute a function now if DOMContentLoaded has fired, otherwise listen for it.
Expand All @@ -5028,8 +5039,9 @@ var htmx = (function() {
// some means other than the initial page load.
if (isReady || getDocument().readyState === 'complete') {
fn()
triggerReadyFunctions()
} else {
getDocument().addEventListener('DOMContentLoaded', fn)
readyFunctions.push(fn)
}
}

Expand Down