Skip to content

Commit

Permalink
fix #2270; improved checks for element existence before doing any cal…
Browse files Browse the repository at this point in the history
…culations
  • Loading branch information
junedchhipa committed Nov 6, 2024
1 parent e928398 commit 5c3bba0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/apexcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class ApexCharts {
// main method
return new Promise((resolve, reject) => {
// only draw chart, if element found
if (this.el !== null) {
if (Utils.elementExists(this.el)) {
if (typeof Apex._chartInstances === 'undefined') {
Apex._chartInstances = []
}
Expand Down Expand Up @@ -129,18 +129,19 @@ export default class ApexCharts {
gl.noData = false
gl.animationEnded = false

if (!Utils.elementExists(this.el)) {
gl.animationEnded = true
this.destroy()
return null
}

this.responsive.checkResponsiveConfig(opts)

if (w.config.xaxis.convertedCatToNumeric) {
const defaults = new Defaults(w.config)
defaults.convertCatToNumericXaxis(w.config, this.ctx)
}

if (this.el === null) {
gl.animationEnded = true
return null
}

this.core.setupElements()

if (w.config.chart.type === 'treemap') {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ class Utils {
return str + z
}

static elementExists(element) {
if (!element || !element.isConnected) {
return false
}
return true
}

static getDimensions(el) {
const computedStyle = getComputedStyle(el, null)

Expand Down

0 comments on commit 5c3bba0

Please sign in to comment.