bigskysoftware / bigskysoftware/htmx

Undocumented `response-targets` behavior

Open
#2,361 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

When an element is decorated with both `hx-target` and `hx-target-*` attributes and the `response-targets` extension is enabled on a parent element, there is undocumented behavior.

If the target(s) specified by `hx-target`/`hx-target-*` are not descendants of an element with `hx-ext="response-targets"` (response-targets enabled), then htmx treats the response as if the extension is not enabled.

It seems like this behavior is undocumented, and I'm curious if it's intended.

I was under the impression that so long as the element decorated with `hx-target-*` is a descendant of one decorated with `hx-ext="response-targets"` that everything is gravy. But the targets specified by `hx-target`s _also_ must be descendants of an element with the extension enabled.

If, e.g. you have a "main content" element that is often the target of `hx-target`, it must have `hx-ext="response-targets"` specified on it, or it at least must be a descendant of an element that has response targets enabled, if one wants to use it as a `hx-target`. This means that `hx-ext="response-targets"` needs to be specified as high up the node tree as one will ever target elements. Raising `hx-ext` up the node tree decreases LOB, so I think this should either be better documented, or the behavior hsould not require targets to be descendants of the `hx-ext`-docorated element.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.