From 31ffd21b4eff297e9b2afb6284dca9497ff2ac75 Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Thu, 25 Feb 2021 10:07:05 -0500 Subject: [PATCH] (core) Fix JS error when switching to a page containing a chart. Summary: - The error appeared recently, due to more frequent resize calls (added for mobile) - In fact, charts' own resize logic can now be simplified. Test Plan: Added a test case (which fails without the fix) Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2739 --- app/client/components/ChartView.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/client/components/ChartView.ts b/app/client/components/ChartView.ts index f67341f3..1c79772a 100644 --- a/app/client/components/ChartView.ts +++ b/app/client/components/ChartView.ts @@ -105,21 +105,18 @@ export class ChartView extends Disposable { private _options: ObjObservable; private _chartDom: HTMLElement; private _update: () => void; + private _resize: () => void; public create(gristDoc: GristDoc, viewSectionModel: ViewSectionRec) { BaseView.call(this as any, gristDoc, viewSectionModel); this._chartDom = this.autoDispose(this.buildDom()); + this._resize = this.autoDispose(Delay.untilAnimationFrame(this._resizeChart, this)); + // Note that .viewPane is used by ViewLayout to insert the actual DOM into the document. this.viewPane = this._chartDom; - // Resize if the window resizes since that can change the layout leaf size. - // TODO: Belongs into ViewLayout which already does BaseView.onResize for side-pane open/close. - const resizeChart = this.autoDispose(Delay.untilAnimationFrame(this._resizeChart, this)); - window.addEventListener('resize', resizeChart); - this.autoDisposeCallback(() => window.removeEventListener('resize', resizeChart)); - this._chartType = this.viewSection.chartTypeDef; this._options = this.viewSection.optionsObj; @@ -142,7 +139,7 @@ export class ChartView extends Disposable { } protected onResize() { - this._resizeChart(); + this._resize(); } protected buildDom() {