Skip to content

tag-helpers: reject aliases of attributes that the Tag Helpers render - #118

Merged
rameel merged 3 commits into
mainfrom
tag-helpers/reject-attribute-aliases
Nov 2, 2026
Merged

rameel merged 3 commits into
mainfrom
tag-helpers/reject-attribute-aliases

Conversation

@rameel

@rameel rameel commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

hx-val-*, hx-header-*, and hx-request-* already reject a hand-written hx-vals, hx-headers, hx-request, or hx-config on the same element (PR #115). That check looked only at the hx-* name, but HTMX also reads an alias of these attributes, so the same conflict went unnoticed and one value was silently lost:

  • a generated hx-vals hid a hand-written data-hx-vals;
  • on HTMX 4.x, a hand-written data-hx-vals hid a generated hx-vals:inherited or hx-vals:append.

The check now covers the alias:

Target Alias
HTMX 1.9.x and 2.x data-hx-
HTMX 4.x HtmxV4Config.Prefix, data-hx- by default
HTMX 4.x, Prefix = "" None

With a custom prefix, HTMX no longer reads data-hx-*, so those attributes stay ordinary and do not throw.
The comparison works on spans and does not allocate.

HtmxUrlTagHelper is unchanged. Two request attributes on one element are a mistake with or without
the Toolkit, and the docs already say that it recognizes only the hx- prefix.

The conflict check looked only at the hx-* name, but HTMX also reads an
alias: data-hx-* on HTMX 1.9.x and 2.x, and the configured prefix on
HTMX 4.x. With both on one element, one value was silently lost. A
generated hx-vals hid a hand-written data-hx-vals, and on HTMX 4.x a
hand-written data-hx-vals hid a generated hx-vals:inherited or
hx-vals:append.

The check now covers the alias and follows HtmxV4Config.Prefix: with a
custom prefix, data-hx-* stays an ordinary attribute, and an empty
prefix means there is no alias.
@rameel
rameel merged commit f456bbd into main Nov 2, 2026
1 check passed
@rameel
rameel deleted the tag-helpers/reject-attribute-aliases branch November 2, 2026 16:31
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