Skip to content

script: move child nodes into a fragment instead of spreading them - #99

Merged
rameel merged 1 commit into
mainfrom
fix-argument-limit
Oct 13, 2026
Merged

rameel merged 1 commit into
mainfrom
fix-argument-limit

Conversation

@rameel

@rameel rameel commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Spreading child nodes into replaceChildren/replaceWith can throw a RangeError when there are too many of them, because engines limit the number of call arguments:

  • Chromium: about 125,000
  • Firefox: 500,000
  • Safari: 65,536

Fix:
Move the nodes into a DocumentFragment and pass it as a single argument. This is a precaution against a potential error rather than a fix for a reported issue.

The innerMorph/outerMorph fallback and the outerSync fallback for
HTMX 1.9.x and 2.x spread the response's child nodes into
replaceChildren and replaceWith. Engines limit the number of call
arguments: about 125,000 in Chromium, 500,000 in Firefox and 65,536
in Safari. A larger response made handleSwap throw a RangeError, and
HTMX logged it and fell back to the default swap style: outerMorph
inserted the response inside the target, and outerSync nested the
new element inside the target, whose attributes had already been
synchronized.

Move the nodes into a DocumentFragment and pass it as a single
argument.
@rameel
rameel merged commit b2af702 into main Oct 13, 2026
1 check passed
@rameel
rameel deleted the fix-argument-limit branch October 13, 2026 16:57
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