From b74f289044a09b36d5ad7fed2cb0e83a35c9b9da Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Tue, 7 Nov 2023 20:06:58 +0000
Subject: [PATCH] only trigger if the editor is still attached to the textarea,
 fixes #3440

Closes #3440

Merge request studip/studip!2338
---
 resources/assets/javascripts/lib/wysiwyg.js | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/resources/assets/javascripts/lib/wysiwyg.js b/resources/assets/javascripts/lib/wysiwyg.js
index b462602effb..978328bb050 100644
--- a/resources/assets/javascripts/lib/wysiwyg.js
+++ b/resources/assets/javascripts/lib/wysiwyg.js
@@ -213,8 +213,11 @@ function enhanceEditor($textarea, ckeditor) {
     // make sure HTML marker is always set, in
     // case contents are cut-off by the backend
     $textarea.closest('form').submit(() => {
-        ckeditor.setData(wysiwyg.markAsHtml(ckeditor.getData()));
-        ckeditor.updateSourceElement();
+        // only trigger if the editor is still attached to the textarea
+        if (getEditor($textarea[0]) === ckeditor) {
+            ckeditor.setData(wysiwyg.markAsHtml(ckeditor.getData()));
+            ckeditor.updateSourceElement();
+        }
     });
 
     // focus the editor if requested
-- 
GitLab