Skip to content

http: write trigger event headers as events are added - #101

Merged
rameel merged 3 commits into
mainfrom
trigger-events-write-through
Oct 23, 2026
Merged

rameel merged 3 commits into
mainfrom
trigger-events-write-through

Conversation

@rameel

@rameel rameel commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

TriggerEvent() now sets the HX-Trigger* header in Response.Headers on each call instead of writing the collected events in an OnStarting callback. Trigger events now behave like any other response header: server code can read them right after the call, Response.Clear() removes them, and they cannot be added after the response has started.

Fixes:

  • An event added after the response had started, for example in a view after FlushAsync() or in OnResultExecuted of a filter, was either silently dropped or threw, depending on whether an earlier event had registered the callback. It now always throws InvalidOperationException.
  • An exception handler sent the events of the failed request with the error page, because Response.Clear() did not remove them, and HTMX 2.x triggered them. Removing the header now discards the events collected before, and HtmxResponseHeaders.Trigger* return null.

TriggerEvent() collected events and wrote their headers in an OnStarting
callback, which broke in two cases:

- An event added after the response had started was silently dropped
  if an earlier event had already registered the callback.
- Response.Clear() did not remove the collected events, so an exception
  handler sent them with the error page, and HTMX 2.x triggered them
  for the failed request.

Each TriggerEvent() call now sets the header in Response.Headers,
replacing its value with the collected events. After the response has
started, it throws InvalidOperationException like any other header
change. If the header has been removed, the events collected before
are discarded.
@rameel rameel changed the title Trigger events write through http: write trigger event headers as events are added Oct 23, 2026
@rameel
rameel force-pushed the trigger-events-write-through branch from 68d8b66 to ebce368 Compare October 23, 2026 14:28
@rameel
rameel merged commit 4707049 into main Oct 23, 2026
1 check passed
@rameel
rameel deleted the trigger-events-write-through branch October 23, 2026 14:37
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