Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
* @private
*/
function eventProxy(e) {
this._listeners[e.type + false](options.event ? options.event(e) : e);
if (this._listeners && this._listeners[e.type + false]) {
this._listeners[e.type + false](options.event ? options.event(e) : e);
}
}

function eventProxyCapture(e) {
this._listeners[e.type + true](options.event ? options.event(e) : e);
if (this._listeners && this._listeners[e.type + true]) {
this._listeners[e.type + true](options.event ? options.event(e) : e);
}
}
26 changes: 26 additions & 0 deletions test/browser/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ describe('event handling', () => {
);
});

it('should not throw an exception if the listeners array is cleared', () => {
render(
<div onClick={() => {}}>
<button />
</div>,
scratch
);

let root = scratch.firstChild;
root._listeners = undefined;
root.firstElementChild.click();
});

// Skip test if browser doesn't support passive events
if (supportsPassiveEvents()) {
it('should use capturing for event props ending with *Capture', () => {
Expand Down Expand Up @@ -198,5 +211,18 @@ describe('event handling', () => {
expect(clickCapture, 'click').to.have.been.calledOnce;
expect(click, 'click').to.have.been.calledOnce;
});

it('should not throw an exception if the listeners array is cleared on capture event', () => {
render(
<div onClickCapture={() => {}}>
<button />
</div>,
scratch
);

let root = scratch.firstChild;
root._listeners = undefined;
root.firstElementChild.click();
});
}
});