Skip to content

fix: log the dispatched event name when metaCharacter is set - #4137

Open
Lluczel wants to merge 1 commit into
bigskysoftware:four-devfrom
Lluczel:fix/4108-logall-metachar
Open

Lluczel wants to merge 1 commit into
bigskysoftware:four-devfrom
Lluczel:fix/4108-logall-metachar

Conversation

@Lluczel

@Lluczel Lluczel commented Oct 11, 2026

Copy link
Copy Markdown

Description

With htmx.config.metaCharacter set, __trigger dispatches the adjusted event name but logs the original one. With metaCharacter = '-', logAll prints htmx: htmx:before:request, but the event that fires is htmx-before-request. The same mismatch affects the detail.error and detail.warn log lines, so the console names events that no listener can receive.

This change computes the dispatched name once at the top of __trigger and uses it for the three log calls and for trigger(). __triggerExtensions still receives the original name, because extension methods are keyed on eventName.replace(/:/g, '_') and would stop matching otherwise. Without a metaCharacter, output is unchanged.

The issue also asks whether the renaming itself should go. I kept it, since the 4.x config table describes metaCharacter as the "separator character in attribute/event names". Instead I updated the metaCharacter docs, which only mentioned attribute modifiers, to say that dispatched event names change too.

htmx.config.metaCharacter = '-';
htmx.config.logAll = true;
// before: logs "htmx: htmx:after:settle" while dispatching "htmx-after-settle"
// after:  logs "htmx: htmx-after-settle"

Out of scope: events that extensions fire through the public htmx.trigger() are not renamed (#4084).

Corresponding issue: #4108

Closes #4108

Testing

  • Added logAll logs the dispatched event name when metaCharacter is set to test/tests/unit/logger.js. It fails on four-dev (the log contains htmx:custom) and passes with this change.
  • npm test (Chromium): 1781 passed, 0 failed, 4 skipped.
  • python3 src/scripts/content/check.py: OK.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes) (targeting four-dev, since this is an htmx 4 source fix)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

__trigger logged the original event name but dispatched the
metaCharacter-adjusted one, so logAll/error/warn output named events
that no listener receives. Compute the dispatched name once and use it
for logging and dispatch. Document that metaCharacter also renames
dispatched events.

Closes bigskysoftware#4108
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