Skip to content

fix: clean up resize listener when view gets removed #3805

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

Merged
Merged
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
13 changes: 8 additions & 5 deletions packages/javascript/jupyterlab-plotly/src/Figure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ export class FigureModel extends DOMWidgetModel {
*/
export class FigureView extends DOMWidgetView {
viewID: string;
resizeEventListener: () => void;

/**
* The perform_render method is called by processPhosphorMessage
Expand Down Expand Up @@ -920,10 +921,10 @@ export class FigureView extends DOMWidgetView {
xaxis: axisHidden,
yaxis: axisHidden,
});

window.addEventListener("resize", function () {
that.autosizeFigure();
});
this.resizeEventListener = () => {
this.autosizeFigure();
}
window.addEventListener("resize", this.resizeEventListener);
break;
case "after-attach":
// Rendering actual figure in the after-attach event allows
Expand Down Expand Up @@ -953,8 +954,10 @@ export class FigureView extends DOMWidgetView {
* Purge Plotly.js data structures from the notebook output display
* element when the view is destroyed
*/
destroy() {
remove() {
super.remove();
Plotly.purge(this.el);
window.removeEventListener("resize", this.resizeEventListener);
}

/**
Expand Down