]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
addListener and removeListener are only invoked on defined (and valid) values (#11685)
authorArun Philip <dacodedbeat@gmail.com>
Wed, 28 Feb 2024 15:55:52 +0000 (10:55 -0500)
committerGitHub <noreply@github.com>
Wed, 28 Feb 2024 15:55:52 +0000 (10:55 -0500)
src/platform/platform.dom.js

index 301b2c46c47503e963122649507864d9fef30528..6c4b96d7546e35231cd7e52633cfe4243ee2c0eb 100644 (file)
@@ -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) {