Skip to content

script: return the target instead of live childNodes from outerSync - #97

Merged
rameel merged 1 commit into
mainfrom
outer-sync-return-target
Oct 13, 2026
Merged

rameel merged 1 commit into
mainfrom
outer-sync-return-target

Conversation

@rameel

@rameel rameel commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

With HTMX 1.9.x and 2.x, the outerSync fallback in ramstack-swap returned source.childNodes from handleSwap. This NodeList is live and is already empty after replaceChildren moves the nodes into the target, so HTMX does not process the swapped content:

let nodes = source.childNodes;
target.replaceChildren(...nodes);

return nodes; // <-- empty

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 activated
  • htmx:load does not fire
  • changes to the target's own hx-* attributes are not applied

Fix:
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. Copying childNodes into an array would fix only the children.

Tested in Chromium with HTMX 1.9.12 and 2.0.11.

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.
@rameel
rameel merged commit 3e8ec1b into main Oct 13, 2026
1 check passed
@rameel
rameel deleted the outer-sync-return-target branch October 13, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant