Do not execute hx-trigger="load" on re-initialization of an existing node #2976
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 a
firstInitCompleted
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
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded