From ec84fcd02edc41cda57004be40b81400bbe2e247 Mon Sep 17 00:00:00 2001 From: Serhii Kulykov Date: Wed, 11 Sep 2024 15:28:55 +0300 Subject: [PATCH] fix: filter out undefined instances when redrawing all charts (#7779) (#7795) --- packages/charts/src/vaadin-chart.js | 9 ++++++++- packages/charts/test/private-api.test.js | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/charts/src/vaadin-chart.js b/packages/charts/src/vaadin-chart.js index 59a157d8ed..1845ea9be7 100644 --- a/packages/charts/src/vaadin-chart.js +++ b/packages/charts/src/vaadin-chart.js @@ -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(); + } + }); } } } diff --git a/packages/charts/test/private-api.test.js b/packages/charts/test/private-api.test.js index fac901e829..6701b54d96 100644 --- a/packages/charts/test/private-api.test.js +++ b/packages/charts/test/private-api.test.js @@ -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'; @@ -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); + }); }); });