Repository navigation
http: write trigger event headers as events are added - #101
Merged
Merged
Conversation
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
force-pushed
the
trigger-events-write-through
branch
from
October 23, 2026 14:28
68d8b66 to
ebce368
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TriggerEvent()now sets theHX-Trigger*header inResponse.Headerson each call instead of writing the collected events in anOnStartingcallback. 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:
FlushAsync()or inOnResultExecutedof a filter, was either silently dropped or threw, depending on whether an earlier event had registered the callback. It now always throwsInvalidOperationException.Response.Clear()did not remove them, and HTMX 2.x triggered them. Removing the header now discards the events collected before, andHtmxResponseHeaders.Trigger*returnnull.