Skip to content

Commit 20e5760

Browse files
authored
Added resize listener after handler was created (elastic#49452) (elastic#49707)
1 parent 8107ecc commit 20e5760

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

x-pack/legacy/plugins/monitoring/public/components/chart/chart_target.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class ChartTarget extends React.Component {
3535
componentWillUnmount() {
3636
this.shutdownChart();
3737
window.removeEventListener('resize', this._handleResize);
38+
this.componentUnmounted = true;
3839
}
3940

4041
filterByShow(seriesToShow) {
@@ -62,7 +63,6 @@ export class ChartTarget extends React.Component {
6263

6364
componentDidMount() {
6465
this.renderChart();
65-
window.addEventListener('resize', this._handleResize, false);
6666
}
6767

6868
componentDidUpdate() {
@@ -94,6 +94,9 @@ export class ChartTarget extends React.Component {
9494
const data = this.filterData(series, this.props.seriesToShow);
9595

9696
this.plot = $.plot(target, data, await this.getOptions());
97+
if (this.componentUnmounted || !this.plot) {
98+
return;
99+
}
97100

98101
this._handleResize = () => {
99102
if (!this.plot) { return; }
@@ -110,6 +113,8 @@ export class ChartTarget extends React.Component {
110113
}
111114
};
112115

116+
window.addEventListener('resize', this._handleResize, false);
117+
113118
this.handleMouseLeave = () => {
114119
eventBus.trigger('thorPlotLeave', []);
115120
};

0 commit comments

Comments
 (0)