From 342868b59f22952c14debbfbb2810ae9671f6f2f Mon Sep 17 00:00:00 2001 From: Vaadin Bot Date: Tue, 3 Dec 2024 12:53:52 +0100 Subject: [PATCH] fix: save userOptions on charts disconnect (#8206) (#8263) Co-authored-by: Diego Cardoso --- packages/charts/src/vaadin-chart.js | 4 ++++ packages/charts/test/reattach.test.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/charts/src/vaadin-chart.js b/packages/charts/src/vaadin-chart.js index 4b43f6d730..87dbb6bd26 100644 --- a/packages/charts/src/vaadin-chart.js +++ b/packages/charts/src/vaadin-chart.js @@ -1078,6 +1078,10 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) { disconnectedCallback() { super.disconnectedCallback(); + if (this.configuration) { + this._jsonConfigurationBuffer = this.configuration.userOptions; + } + queueMicrotask(() => { if (this.isConnected) { return; diff --git a/packages/charts/test/reattach.test.js b/packages/charts/test/reattach.test.js index 3d3e8ce7e0..a04ee5852d 100644 --- a/packages/charts/test/reattach.test.js +++ b/packages/charts/test/reattach.test.js @@ -186,6 +186,20 @@ describe('reattach', () => { expect(chart.configuration.options.plotOptions.series.stacking).to.be.equal('percent'); }); + it('should restore configuration done through `updateConfigaration` after reattach', async () => { + const wrapper = fixtureSync(`
`); + const chart = wrapper.firstElementChild; + chart.updateConfiguration({ title: { text: 'New title' }, series: [{ name: 'series', data: [1, 2, 3] }] }); + await nextFrame(); + wrapper.removeChild(chart); + await nextFrame(); + wrapper.appendChild(chart); + await nextFrame(); + expect(chart.configuration.options.title.text).to.be.equal('New title'); + expect(chart.configuration.options.series.length).to.be.equal(1); + expect(chart.configuration.options.series[0].name).to.be.equal('series'); + }); + it('should apply categories updated while detached after reattach', async () => { chart.categories = ['Jan', 'Feb', 'Mar']; await oneEvent(chart, 'chart-load');