Skip to content

Commit

Permalink
Fix: htmx-request class removal for parallel requests
Browse files Browse the repository at this point in the history
This patch addresses a concurrency issue where the same indicator,
when used for multiple parallel requests, could result in a negative request
count. This issue prevented the proper removal of the `htmx-request` class
upon completion of all requests.
The fix ensures accurate tracking of active requests,
  • Loading branch information
tarunbhardwaj committed Mar 28, 2024
1 parent 45dd5f1 commit 0d50c69
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/htmx.js
Expand Up @@ -3182,14 +3182,14 @@ var htmx = (function() {
function removeRequestIndicators(indicators, disabled) {
forEach(indicators, function(ic) {
const internalData = getInternalData(ic)
internalData.requestCount = (internalData.requestCount || 0) - 1
internalData.requestCount = Math.max((internalData.requestCount || 0) - 1, 0)
if (internalData.requestCount === 0) {
ic.classList.remove.call(ic.classList, htmx.config.requestClass)
}
})
forEach(disabled, function(disabledElement) {
const internalData = getInternalData(disabledElement)
internalData.requestCount = (internalData.requestCount || 0) - 1
internalData.requestCount = Math.max((internalData.requestCount || 0) - 1, 0)
if (internalData.requestCount === 0) {
disabledElement.removeAttribute('disabled')
}
Expand Down

0 comments on commit 0d50c69

Please sign in to comment.