From 709bc8735e5fc41e62b7d0762b0d1c0db948f443 Mon Sep 17 00:00:00 2001 From: Ivan Necas Date: Mon, 15 Jul 2019 15:26:26 +0200 Subject: [PATCH] Fixes #27292 - workaround for c3 destroy issue (#435) * 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 https://github.com/bcbcarl/react-c3js/issues/22. Delaying the actual destroy a bit seems to help with workarounding the issue. * Refs #27292 - Add note about no need for explicit bind --- webpack/ForemanTasks/Components/Chart/Chart.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/webpack/ForemanTasks/Components/Chart/Chart.js b/webpack/ForemanTasks/Components/Chart/Chart.js index bb4df516b..98f3ad515 100644 --- a/webpack/ForemanTasks/Components/Chart/Chart.js +++ b/webpack/ForemanTasks/Components/Chart/Chart.js @@ -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); }