Sometimes, requests that should be only triggered once at load (with hx-trigger="load") are executed twice. This happens for example when calling htmx.process on an existing node (or a parent node) after changing an attribute on the element with hx-trigger="load".
This PR adds a firstInitCompleted flag to an element's internalData and adds a check for that flag when handling the load triggerEvent.
Corresponding issue:
2973
Testing
Added a test scenario that changes hx-swap="afterbegin" to hx-swap="beforeend" on an element with hx-trigger="load", followed by a call to htmx.process and checks whether the innerHTML of the element stayed the same.
This test fails on the dev branch, and passes with this fix.
Checklist
[x] I have read the contribution guidelines
[x] I have targeted this PR against the correct branch (master for website changes, dev for
source changes)
[x] 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
Description
Sometimes, requests that should be only triggered once at load (with
hx-trigger="load"
) are executed twice. This happens for example when calling htmx.process on an existing node (or a parent node) after changing an attribute on the element withhx-trigger="load"
. This PR adds afirstInitCompleted
flag to an element's internalData and adds a check for that flag when handling theload
triggerEvent.Corresponding issue:
2973
Testing
Added a test scenario that changes
hx-swap="afterbegin"
tohx-swap="beforeend"
on an element withhx-trigger="load"
, followed by a call tohtmx.process
and checks whether the innerHTML of the element stayed the same. This test fails on the dev branch, and passes with this fix.Checklist
master
for website changes,dev
for source changes)npm run test
) and verified that it succeeded