Skip to content

Commit 2f3e00c

Browse files
web-padawanDiegoCardoso
authored andcommitted
fix: filter out undefined instances when redrawing all charts (#7779)
1 parent 0409f49 commit 2f3e00c

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

packages/charts/src/vaadin-chart.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,6 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
297297
return 'vaadin-chart';
298298
}
299299

300-
/** @private */
301-
static __callHighchartsFunction(functionName, redrawCharts, ...args) {
302-
const functionToCall = Highcharts[functionName];
303-
if (functionToCall && typeof functionToCall === 'function') {
304-
args.forEach((arg) => inflateFunctions(arg));
305-
functionToCall.apply(this.configuration, args);
306-
if (redrawCharts) {
307-
Highcharts.charts.forEach((c) => c.redraw());
308-
}
309-
}
310-
}
311-
312300
static get properties() {
313301
return {
314302
/**
@@ -506,6 +494,25 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
506494
];
507495
}
508496

497+
/** @private */
498+
static __callHighchartsFunction(functionName, redrawCharts, ...args) {
499+
const functionToCall = Highcharts[functionName];
500+
if (functionToCall && typeof functionToCall === 'function') {
501+
args.forEach((arg) => inflateFunctions(arg));
502+
functionToCall.apply(this.configuration, args);
503+
if (redrawCharts) {
504+
Highcharts.charts.forEach((c) => {
505+
// Ignore `undefined` values that are preserved in the array
506+
// after their corresponding chart instances are destroyed.
507+
// See https://github.com/vaadin/flow-components/issues/6607
508+
if (c !== undefined) {
509+
c.redraw();
510+
}
511+
});
512+
}
513+
}
514+
}
515+
509516
constructor() {
510517
super();
511518

packages/charts/test/private-api.test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync, oneEvent } from '@vaadin/testing-helpers';
2+
import { fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
33
import '../vaadin-chart.js';
44
import { inflateFunctions } from '../src/helpers.js';
55

@@ -193,5 +193,18 @@ describe('vaadin-chart private API', () => {
193193
const legend = chart.$.chart.querySelector('.highcharts-legend-item > text').textContent;
194194
expect(legend).to.be.equal('value');
195195
});
196+
197+
it('should not throw when calling after a chart is destroyed', async () => {
198+
chart.updateConfiguration({}, true);
199+
await nextFrame();
200+
201+
expect(() => {
202+
chart.constructor.__callHighchartsFunction('setOptions', true, {
203+
lang: {
204+
shortWeekdays: ['su', 'ma', 'ti', 'ke', 'to', 'pe', 'la'],
205+
},
206+
});
207+
}).to.not.throw(Error);
208+
});
196209
});
197210
});

0 commit comments

Comments
 (0)