Skip to content

Commit

Permalink
fix: save userOptions on charts disconnect (#8206) (#8263)
Browse files Browse the repository at this point in the history
Co-authored-by: Diego Cardoso <diego@vaadin.com>
  • Loading branch information
vaadin-bot and DiegoCardoso authored Dec 3, 2024
1 parent aebdc75 commit 342868b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/charts/src/vaadin-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions packages/charts/test/reattach.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(`<div><vaadin-chart></vaadin-chart></div>`);
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');
Expand Down

0 comments on commit 342868b

Please sign in to comment.