Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not reset configuration if chart is immediately re-attached (CP: 23.5) #8120

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions packages/charts/src/vaadin-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -1102,14 +1102,20 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
disconnectedCallback() {
super.disconnectedCallback();

if (this.configuration) {
this.configuration.destroy();
this.configuration = undefined;
}
queueMicrotask(() => {
if (this.isConnected) {
return;
}

if (this._childObserver) {
this._childObserver.disconnect();
}
if (this.configuration) {
this.configuration.destroy();
this.configuration = undefined;
}

if (this._childObserver) {
this._childObserver.disconnect();
}
});
}

/** @private */
Expand Down
41 changes: 41 additions & 0 deletions packages/charts/test/reattach.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,43 @@ describe('reattach', () => {

const spy = sinon.spy(chart.configuration, 'destroy');
wrapper.removeChild(chart);
await nextFrame();

expect(spy.calledOnce).to.be.ok;
expect(chart.configuration).to.be.undefined;
});

it('should re-create chart configuration when attached to a new parent', async () => {
await oneEvent(chart, 'chart-load');
wrapper.removeChild(chart);
await nextFrame();

inner.appendChild(chart);
await oneEvent(chart, 'chart-load');
await nextFrame();
expect(chart.configuration.series.length).to.be.equal(chart.childElementCount);
});

it('should not re-create chart configuration when moved to a new parent', async () => {
await oneEvent(chart, 'chart-load');

const configuration = chart.configuration;

const spy = sinon.spy(chart.configuration, 'destroy');
inner.appendChild(chart);
await nextFrame();

expect(spy.called).to.be.false;
expect(chart.configuration).to.be.equal(configuration);
});

it('should apply title updated while detached after reattach', async () => {
chart.title = 'Title';
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ title: { text: 'New title' } });

inner.appendChild(chart);
Expand All @@ -56,6 +74,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ subtitle: { text: 'New subtitle' } });

inner.appendChild(chart);
Expand All @@ -68,6 +88,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ chart: { type: 'line' } });

inner.appendChild(chart);
Expand All @@ -81,6 +103,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ tooltip: { enabled: false } });

inner.appendChild(chart);
Expand All @@ -93,6 +117,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ legend: { enabled: true } });

inner.appendChild(chart);
Expand All @@ -105,6 +131,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ chart: { options3d: { enabled: false } } });

inner.appendChild(chart);
Expand All @@ -117,6 +145,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ chart: { polar: false } });

inner.appendChild(chart);
Expand All @@ -130,6 +160,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ lang: { noData: 'Nothing' } });

inner.appendChild(chart);
Expand All @@ -149,6 +181,7 @@ describe('reattach', () => {
series: { stacking: 'percent' },
},
});
await nextFrame();

inner.appendChild(chart);
await oneEvent(chart, 'chart-load');
Expand All @@ -160,6 +193,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ xAxis: { categories: ['Jun', 'Jul', 'Aug'] } });

inner.appendChild(chart);
Expand All @@ -176,6 +211,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ xAxis: { min: 1 } });

inner.appendChild(chart);
Expand All @@ -188,6 +225,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ xAxis: { max: 3 } });

inner.appendChild(chart);
Expand All @@ -200,6 +239,8 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');

wrapper.removeChild(chart);
await nextFrame();

chart.updateConfiguration({ chart: { inverted: false } });

inner.appendChild(chart);
Expand Down
Loading