From bbdaa6a14b5b0e9dcce59396f53a2dd51883727d Mon Sep 17 00:00:00 2001 From: Arun Philip Date: Wed, 28 Feb 2024 10:55:52 -0500 Subject: [PATCH] addListener and removeListener are only invoked on defined (and valid) values (#11685) --- src/platform/platform.dom.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/platform/platform.dom.js b/src/platform/platform.dom.js index 301b2c46c47..6c4b96d7546 100644 --- a/src/platform/platform.dom.js +++ b/src/platform/platform.dom.js @@ -95,11 +95,15 @@ function initCanvas(canvas, aspectRatio) { const eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false; function addListener(node, type, listener) { - node.addEventListener(type, listener, eventListenerOptions); + if (node) { + node.addEventListener(type, listener, eventListenerOptions); + } } function removeListener(chart, type, listener) { - chart.canvas.removeEventListener(type, listener, eventListenerOptions); + if (chart && chart.canvas) { + chart.canvas.removeEventListener(type, listener, eventListenerOptions); + } } function fromNativeEvent(event, chart) {