diff --git a/js/src/dom/event-handler.js b/js/src/dom/event-handler.js index 87f936b41d..0aa628c66d 100644 --- a/js/src/dom/event-handler.js +++ b/js/src/dom/event-handler.js @@ -89,7 +89,7 @@ function getElementEvents(element) { function bootstrapHandler(element, fn) { return function handler(event) { - event.delegateTarget = element + hydrateObj(event, { delegateTarget: element }) if (handler.oneOff) { EventHandler.off(element, event.type, fn) @@ -109,7 +109,7 @@ function bootstrapDelegationHandler(element, selector, fn) { continue } - event.delegateTarget = target + hydrateObj(event, { delegateTarget: target }) if (handler.oneOff) { EventHandler.off(element, event.type, selector, fn) @@ -302,11 +302,16 @@ const EventHandler = { function hydrateObj(obj, meta) { for (const [key, value] of Object.entries(meta || {})) { - Object.defineProperty(obj, key, { - get() { - return value - } - }) + try { + obj[key] = value + } catch { + Object.defineProperty(obj, key, { + configurable: true, + get() { + return value + } + }) + } } return obj diff --git a/js/tests/unit/dom/event-handler.spec.js b/js/tests/unit/dom/event-handler.spec.js index 14037929bc..19d0235e6c 100644 --- a/js/tests/unit/dom/event-handler.spec.js +++ b/js/tests/unit/dom/event-handler.spec.js @@ -441,4 +441,41 @@ describe('EventHandler', () => { expect(i).toEqual(5) }) }) + + describe('general functionality', () => { + it('should hydrate properties, and make them configurable', () => { + return new Promise(resolve => { + fixtureEl.innerHTML = [ + '