chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
63.94k stars 11.89k forks source link

addListener and removeListener should be only invoked on truthy values #11685

Closed DAcodedBEAT closed 4 months ago

DAcodedBEAT commented 4 months ago

As reported in #11677, this issue is experienced in a few libraries integrating chart.js (such as #11295, samber/chartjs-plugin-datasource-prometheus#40, sgratzl/chartjs-chart-graph#79)

TypeError: Cannot read properties of null (reading 'addEventListener')
  at addListener(../../node_modules/chart.js/dist/chart.js:3234:8)
  at createProxyAndListen(../../node_modules/chart.js/dist/chart.js:3360:15)
  at DomPlatform.addEventListener(../../node_modules/chart.js/dist/chart.js:3406:21)
  at _add(../../node_modules/chart.js/dist/chart.js:6216:16)
  at <anonymous>(../../node_modules/chart.js/dist/chart.js:6224:41)
  at each(../../node_modules/chart.js/dist/chunks/helpers.segment.js:56:12)
  at _a.bindUserEvents(../../node_modules/chart.js/dist/chart.js:6224:10)
  at _a.bindEvents(../../node_modules/chart.js/dist/chart.js:6205:10)
  at _a._checkEventBindings(../../node_modules/chart.js/dist/chart.js:5903:12)
  at _a.update(../../node_modules/chart.js/dist/chart.js:5852:10)
  at this._doResize(../../node_modules/chart.js/dist/chart.js:5620:46)
  at sentryWrapped(../../node_modules/@sentry/browser/esm/helpers.js:37:17)

By ensuring that addEventListener and removeEventListener are called on truth-y values, Chart.js can prevent these TypeErrors from occurring and therefore make implementing applications more stable when integrating chart.js.

Closes #11677

DAcodedBEAT commented 4 months ago

Thanks for the approvals @LeeLenaleee and @etimberg! When can this be merged and what is the ETA for it's release?

etimberg commented 4 months ago

Merged it now; we don't have a date on a next release but I think we're getting close. @LeeLenaleee thoughts?

LeeLenaleee commented 4 months ago

There are no enhancements merged so if we rename the milsestone from 4.5.0 to 4.4.2 and create a new 4.5.0 we can do a bugfix release

etimberg commented 4 months ago

i renamed it