Skip to content

Commit ec84fcd

Browse files
authored
fix: filter out undefined instances when redrawing all charts (#7779) (#7795)
1 parent cdfa319 commit ec84fcd

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/charts/src/vaadin-chart.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,14 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
488488
args.forEach((arg) => inflateFunctions(arg));
489489
functionToCall.apply(this.configuration, args);
490490
if (redrawCharts) {
491-
Highcharts.charts.forEach((c) => c.redraw());
491+
Highcharts.charts.forEach((c) => {
492+
// Ignore `undefined` values that are preserved in the array
493+
// after their corresponding chart instances are destroyed.
494+
// See https://github.com/vaadin/flow-components/issues/6607
495+
if (c !== undefined) {
496+
c.redraw();
497+
}
498+
});
492499
}
493500
}
494501
}

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)