From 0e4a239960c8e0e1e1b957108e57ab889db5588b Mon Sep 17 00:00:00 2001 From: kiragrammel Date: Mon, 4 Sep 2023 11:09:31 +0200 Subject: [PATCH] Unsubscribe from channel when redirecting fixes CODEOCEAN-FRONTEND-2S --- app/assets/javascripts/editor/editor.js.erb | 3 +++ app/assets/javascripts/editor/submissions.js | 1 + 2 files changed, 4 insertions(+) diff --git a/app/assets/javascripts/editor/editor.js.erb b/app/assets/javascripts/editor/editor.js.erb index cdc405f8..a7fce30f 100644 --- a/app/assets/javascripts/editor/editor.js.erb +++ b/app/assets/javascripts/editor/editor.js.erb @@ -1064,6 +1064,9 @@ var CodeOceanEditor = { this.initializeDeadlines(); CodeOceanEditorTips.initializeEventHandlers(); + window.addEventListener("turbolinks:before-render", App.synchronized_editor?.unsubscribe.bind(App.synchronized_editor)); + window.addEventListener("beforeunload", App.synchronized_editor?.unsubscribe.bind(App.synchronized_editor)); + window.addEventListener("turbolinks:before-render", this.autosaveIfChanged.bind(this)); window.addEventListener("beforeunload", this.autosaveIfChanged.bind(this)); // create autosave when the editor is opened the first time diff --git a/app/assets/javascripts/editor/submissions.js b/app/assets/javascripts/editor/submissions.js index e1d0356d..cf62f531 100644 --- a/app/assets/javascripts/editor/submissions.js +++ b/app/assets/javascripts/editor/submissions.js @@ -204,6 +204,7 @@ CodeOceanEditorSubmissions = { this.teardownEventHandlers(); this.createSubmission(button, null, function (response) { if (response.redirect) { + App.synchronized_editor?.unsubscribe(); this.autosaveIfChanged(); this.stopCode(event); this.editors = [];