From c498cfb2114ace22193f2761a23ae447d32799ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Wed, 21 Apr 2021 17:38:48 +0200 Subject: [PATCH] Explicitly dispose Monaco editor instance when cell is deleted (#232) --- assets/js/cell/index.js | 4 ++++ assets/js/cell/live_editor.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/assets/js/cell/index.js b/assets/js/cell/index.js index 63b5d6249..e887dc7dd 100644 --- a/assets/js/cell/index.js +++ b/assets/js/cell/index.js @@ -83,6 +83,10 @@ const Cell = { destroyed() { globalPubSub.unsubscribe("session", this.handleSessionEvent); + + if (this.state.liveEditor) { + this.state.liveEditor.destroy(); + } }, updated() { diff --git a/assets/js/cell/live_editor.js b/assets/js/cell/live_editor.js index 1135d9503..839d460be 100644 --- a/assets/js/cell/live_editor.js +++ b/assets/js/cell/live_editor.js @@ -71,6 +71,20 @@ class LiveEditor { .pushEditOperations([], [{ forceMoveMarkers: true, range, text }]); } + /** + * Performs necessary cleanup actions. + */ + destroy() { + // Explicitly destroy the editor instance and its text model. + this.editor.dispose(); + + const model = this.editor.getModel(); + + if (model) { + model.dispose(); + } + } + __mountEditor() { this.editor = monaco.editor.create(this.container, { language: this.type,