Fix plugin custom events never reaching native addEventListener listeners#3416
Open
Salvialf wants to merge 3 commits into
Open
Fix plugin custom events never reaching native addEventListener listeners#3416Salvialf wants to merge 3 commits into
Salvialf wants to merge 3 commits into
Conversation
zoic21
approved these changes
Jul 6, 2026
11 tasks
zoic21
approved these changes
Jul 6, 2026
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.
Problem
Custom events emitted via
event::add()that aren't in the core's hardcoded whitelist (scenario::update, ui::update, etc.) are dispatched exclusively through$('body').trigger()when jQuery is loaded, still the default today even though jQuery's future in Jeedom is to disappear entirely. jQuery's trigger() only invokes handlers bound through its own .on()/.bind() API, it never reaches a plaindocument.body.addEventListener(...)listener. Any plugin that has already migrated its event listeners to native vanilla JS silently stops receiving its own events, with no error and no clear symptom beyond "the listener never fires".Fix
Add
jeedom.vanillaEvents, an extensible array of event names that should be dispatched natively (dispatchEvent(new CustomEvent(...))) instead of through jQuery. Any event name not in this list keeps the exact current behavior (jQuerytrigger()when available), so existing plugins relying on jQuery-based listening are unaffected.A plugin can opt an event into native dispatch once its own JS listener has fully migrated to
addEventListener, by pushing the event name into the list from its own script:This is opt-in per event name, so migration can happen gradually across the plugin ecosystem instead of a single breaking switch for everyone at once.
Alternative considered
Fixes #3185 that proposes always dispatching both natively and via jQuery for every event. That would trigger any jQuery-based listener twice for the same event, since jQuery's own .on() already registers a native listener under the hood, and the two firings wouldn't even carry data the same way: the native dispatch exposes it as event.originalEvent.detail, while .trigger() delivers it as the handler's second argument, the convention jQuery-based plugin code actually expects.