Skip to content

Commit

Permalink
fix: filter out undefined instances when redrawing all charts (#7779) (
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Sep 11, 2024
1 parent cdfa319 commit ec84fcd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/charts/src/vaadin-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,14 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
args.forEach((arg) => inflateFunctions(arg));
functionToCall.apply(this.configuration, args);
if (redrawCharts) {
Highcharts.charts.forEach((c) => c.redraw());
Highcharts.charts.forEach((c) => {
// Ignore `undefined` values that are preserved in the array
// after their corresponding chart instances are destroyed.
// See https://github.com/vaadin/flow-components/issues/6607
if (c !== undefined) {
c.redraw();
}
});
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion packages/charts/test/private-api.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync, oneEvent } from '@vaadin/testing-helpers';
import { fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import '../vaadin-chart.js';
import { inflateFunctions } from '../src/helpers.js';

Expand Down Expand Up @@ -193,5 +193,18 @@ describe('vaadin-chart private API', () => {
const legend = chart.$.chart.querySelector('.highcharts-legend-item > text').textContent;
expect(legend).to.be.equal('value');
});

it('should not throw when calling after a chart is destroyed', async () => {
chart.updateConfiguration({}, true);
await nextFrame();

expect(() => {
chart.constructor.__callHighchartsFunction('setOptions', true, {
lang: {
shortWeekdays: ['su', 'ma', 'ti', 'ke', 'to', 'pe', 'la'],
},
});
}).to.not.throw(Error);
});
});
});

0 comments on commit ec84fcd

Please sign in to comment.