From 004663f49e7824fd4bd6993d50b2cf138221b04f Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 16 Jul 2020 16:33:04 +0000 Subject: [PATCH] [FIX] web_editor: fix editor-lock after gallery image reordering again The bug was already solved with [1] but was reintroduced later for another reason. [1] solved the problem by checking that the current option is not destroyed before asking for an UI update thanks to a trigger_up (the option was destroyed because of image reordering). The bug is now reintroduced for the same basic reason: a new trigger_up was added between the potential option destroy and the destroy check, so if the option is destroyed, that trigger_up fails to be triggered and the editor is locked. This commit solves the problem once and for all, hopefully, with a more robust solution: only destroy options when none is being processed. That way we ensure that all trigger_up occuring during an option activation / update can be properly done. [1]: https://github.com/odoo/odoo/commit/9eeea4c4107dc15984c475582d5ee58a17cd2568 X-original-commit: 7770430f78ee9e122a732fa042226d362467158e --- addons/web_editor/static/src/js/editor/snippets.editor.js | 7 +++++-- addons/web_editor/static/src/js/editor/snippets.options.js | 7 ------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 2ac2a13a88c..8304599c6d4 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1094,12 +1094,15 @@ var SnippetsMenu = Widget.extend({ * Updates the cover dimensions of the current snippet editor. */ updateCurrentSnippetEditorOverlay: function () { - this.snippetEditors = _.filter(this.snippetEditors, function (snippetEditor) { + this.snippetEditors = this.snippetEditors.filter(snippetEditor => { if (snippetEditor.$target.closest('body').length) { snippetEditor.cover(); return true; } - snippetEditor.destroy(); + // Destroy options whose $target are not in the DOM anymore but + // only do it once all options executions are done. + this._mutex.exec(() => snippetEditor.destroy()); + return false; }); }, diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index deeb85dbceb..285283f1fc8 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -2493,13 +2493,6 @@ const SnippetOptionWidget = Widget.extend({ // Call widget option methods and update $target await this._select(previewMode, widget); - // Enabling an option and notifying that the $target has changed - // may destroy the option (if the DOM is altered in such a way the - // option is not attached to it anymore). In that case, we must not - // wait for a response to the option update. - if (this.isDestroyed()) { - return; - } await new Promise(resolve => setTimeout(() => { // Will update the UI of the correct widgets for all options // related to the same $target/editor if necessary