Repository navigation
script: return the target instead of live childNodes from outerSync - #97
Merged
Merged
Conversation
The outerSync fallback for HTMX 1.9.x and 2.x returned source.childNodes from handleSwap. That NodeList is live, so it was already empty once replaceChildren had moved the nodes into the target. HTMX 1.9.x therefore found nothing to process, and HTMX 2.x ignores any value that is not an array. As a result, hx-* attributes on the new children were not activated and htmx:load did not fire. Copying the nodes into an array would fix only the children: the target's own hx-* attributes are synchronized too, and HTMX would not re-initialize it. Return [target], as HTMX 4.x does. HTMX then processes the target together with its new children and re-initializes it when its attributes have changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With HTMX 1.9.x and 2.x, the
outerSyncfallback inramstack-swapreturnedsource.childNodesfromhandleSwap. ThisNodeListis live and is already empty afterreplaceChildrenmoves the nodes into the target, so HTMX does not process the swapped content:HTMX 1.9.x iterates over an empty list, and HTMX 2.x ignores anything that is not an array.
Result:
hx-*attributes on the new children are not activatedhtmx:loaddoes not firehx-*attributes are not appliedFix:
Return
[target], as HTMX 4.x does. HTMX then processes the target with its new children and re-initializes it when its attributes have changed. CopyingchildNodesinto an array would fix only the children.Tested in Chromium with HTMX 1.9.12 and 2.0.11.