Fix: htmx-request class removal for parallel requests
Description
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.
Testing
Test case for multiple requests with same indicator is already covered, but reproducing this race condition in test is hard.
Checklist
- [x] I have read the contribution guidelines
- [x] I have targeted this PR against the correct branch (
masterfor website changes,devfor source changes) - [ ] This is either a bugfix, a documentation update, or a new feature that has been explicitly approved via an issue
- [x] I ran the test suite locally (
npm run test) and verified that it succeeded
is it possible to add a test for this fix?
is it possible to add a test for this fix?
There is already a test, but not for the race condition. Any suggestion on how to reproduce this race condition in test?
@tarunbhardwaj In tests, we manually trigger the server answer, which means you should be able to run multiple client actions and only then simulate the server response. Could that work in your case? if so, you'd want to reproduce the issue with the current lib's state and confirm the test reproduces the bug, then ensure your PR fixes it
See this example of the current setup (picked a random test there): https://github.com/bigskysoftware/htmx/blob/c6a89b315b6f964f6d69fa53252c2eb3e63aa8c8/test/core/ajax.js#L15-L18
Is this related to #2860? Although #2860 is merged, I can't see the problem fixed in version 2.0.3.
Hey @nikalexis, If you're still seeing the issue and are interested in contributing, feel free to open a PR with a test case as described above for that race condition I'll be closing this PR as it looks very similar to #2860 that was merged, so it's likely that if the issue persists, it lies elsewhere than what this PR addresses