Skip to content

http: keep trigger events in call order - #85

Merged
rameel merged 4 commits into
mainfrom
ordered-trigger-events
Oct 11, 2026
Merged

rameel merged 4 commits into
mainfrom
ordered-trigger-events

Conversation

@rameel

@rameel rameel commented Oct 11, 2026

Copy link
Copy Markdown
Owner

No description provided.

The rs:event handler passed each detail to htmx.trigger as is, while
HTMX prepares every HX-Trigger entry first. A repeated event with a
primitive detail therefore threw a TypeError in HTMX 2 (strict mode),
and HTMX 4 listeners received "a" instead of { value: "a" }.

Prepare each entry the way the loaded HTMX version does:
- HTMX 1.x wraps non-objects in { value } and ignores "target";
- HTMX 2.x also applies "target" to this and all following events;
- HTMX 4.x passes any object as is and applies "target" to one event.
Pending events were stored in a dictionary that mixed two kinds of
values. SmallDictionary sorted its keys after five entries, and repeats
were written at the position of the first repeat, so the browser could
receive events out of call order.

- Store the events of each timing in a list.
- Write events as object properties when their names are unique. When a
  name repeats, write all events of the header under "rs:event" in call
  order.
- Send event names as given instead of converting them to camelCase.
- Write a null detail as {"value":null}. HTMX 1.x and 2.x already wrap
  it this way, and HTMX 4.x fails on null.
- Return IReadOnlyList<KeyValuePair<string, string>> from the
  HtmxResponseHeaders.Trigger* properties.
The buffer is needed only while Flush writes the HX-Trigger* headers,
but as a field it stayed reachable from HttpContext.Items until the
request ended. Create it in Flush and pass it to SetHeader.
@rameel
rameel merged commit 56d1490 into main Oct 11, 2026
1 check passed
@rameel
rameel deleted the ordered-trigger-events branch October 11, 2026 12:33
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