Skip to content

Commit bbdaa6a

Browse files
authored
addListener and removeListener are only invoked on defined (and valid) values (#11685)
1 parent 4068bd8 commit bbdaa6a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/platform/platform.dom.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ function initCanvas(canvas, aspectRatio) {
9595
const eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false;
9696

9797
function addListener(node, type, listener) {
98-
node.addEventListener(type, listener, eventListenerOptions);
98+
if (node) {
99+
node.addEventListener(type, listener, eventListenerOptions);
100+
}
99101
}
100102

101103
function removeListener(chart, type, listener) {
102-
chart.canvas.removeEventListener(type, listener, eventListenerOptions);
104+
if (chart && chart.canvas) {
105+
chart.canvas.removeEventListener(type, listener, eventListenerOptions);
106+
}
103107
}
104108

105109
function fromNativeEvent(event, chart) {

0 commit comments

Comments
 (0)