Skip to content

Commit 5cc3c81

Browse files
Merge pull request #3805 from maartenbreddels/fix_resize_listener_cleanup
fix: clean up resize listener when view gets removed
2 parents d9dbcb8 + 2099f88 commit 5cc3c81

File tree

1 file changed

+8
-5
lines changed
  • packages/javascript/jupyterlab-plotly/src

1 file changed

+8
-5
lines changed

Diff for: packages/javascript/jupyterlab-plotly/src/Figure.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ export class FigureModel extends DOMWidgetModel {
804804
*/
805805
export class FigureView extends DOMWidgetView {
806806
viewID: string;
807+
resizeEventListener: () => void;
807808

808809
/**
809810
* The perform_render method is called by processPhosphorMessage
@@ -921,10 +922,10 @@ export class FigureView extends DOMWidgetView {
921922
xaxis: axisHidden,
922923
yaxis: axisHidden,
923924
});
924-
925-
window.addEventListener("resize", function () {
926-
that.autosizeFigure();
927-
});
925+
this.resizeEventListener = () => {
926+
this.autosizeFigure();
927+
}
928+
window.addEventListener("resize", this.resizeEventListener);
928929
break;
929930
case "after-attach":
930931
// Rendering actual figure in the after-attach event allows
@@ -954,8 +955,10 @@ export class FigureView extends DOMWidgetView {
954955
* Purge Plotly.js data structures from the notebook output display
955956
* element when the view is destroyed
956957
*/
957-
destroy() {
958+
remove() {
959+
super.remove();
958960
Plotly.purge(this.el);
961+
window.removeEventListener("resize", this.resizeEventListener);
959962
}
960963

961964
/**

0 commit comments

Comments
 (0)