Skip to content

Commit dc0cda2

Browse files
authored
fix: fix redundant event dispatch (#599)
Including multiple instances of the webcomponents on the same page causes the global event handlers to be registered multiple times This then causes multiple calls of the event handlers on the prototype and multiple semantic events being fired.
1 parent b0d09a9 commit dc0cda2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/base/src/DOMEventHandler.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,25 @@ const getParentDOMNode = function getParentDOMNode(node) {
4949
return parentNode;
5050
};
5151

52+
const isOtherInstanceRegistered = () => {
53+
return window["@ui5/webcomponents-base/DOMEventHandler"];
54+
};
55+
56+
const registerInstance = () => {
57+
window["@ui5/webcomponents-base/DOMEventHandler"] = true;
58+
};
5259

5360
class DOMEventHandler {
5461
constructor() {
5562
throw new Error("Static class");
5663
}
5764

5865
static start() {
59-
ManagedEvents.bindAllEvents(handleEvent);
66+
// register the handlers just once in case other bundles include and call this method multiple times
67+
if (!isOtherInstanceRegistered()) {
68+
ManagedEvents.bindAllEvents(handleEvent);
69+
registerInstance();
70+
}
6071
}
6172

6273
static stop() {

0 commit comments

Comments
 (0)