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