Skip to content

Commit

Permalink
Fixes #27292 - workaround for c3 destroy issue (#435)
Browse files Browse the repository at this point in the history
* Fixes #27292 - workaround for c3 destroy issue

There is a known issue in react-c3js that can lead to the charts to
disappear due to some race condition during component unmounting/destroy
phase bcbcarl/react-c3js#22.

Delaying the actual destroy a bit seems to help with workarounding the
issue.

* Refs #27292 - Add note about no need for explicit bind
  • Loading branch information
iNecas committed Jul 16, 2019
1 parent aa61ee4 commit d96b627
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion webpack/ForemanTasks/Components/Chart/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ class C3Chart extends React.Component {

destroyChart() {
try {
this.chart = this.chart.destroy();
// A workaround for a case, where the chart might be still in transition
// phase while unmounting/destroying - destroying right away leads
// to issue described in https://github.com/bcbcarl/react-c3js/issues/22.
// Delaying the destroy a bit seems to resolve the issue.
// The chart API methods are already bind explicitly, therefore we don't need
// any special handling when passing the function.
setTimeout(this.chart.destroy, 1000);
this.chart = null;
} catch (err) {
throw new Error('Internal C3 error', err);
}
Expand Down

0 comments on commit d96b627

Please sign in to comment.