From de3c29fab2bc5349da8a9418f9d0086d76e6f7de Mon Sep 17 00:00:00 2001 From: "Guillaume (gdi)" <gdi@odoo.com> Date: Mon, 7 Nov 2022 09:51:30 +0000 Subject: [PATCH] [FIX] web_editor: do not update the options when destroying them Since [this commit] it is visible that there is a race condition in the editor. The race condition was caused by a call for an update of the option visibility during the save, but the options may be in the destruction process. This commit prevents the visibility of the options from being updated when the option destruction process begins. Steps to reproduce the bug fixed by this commit: - Drop 2 times the image - text block on a page - Drop a popup block - Save => During the save, a traceback occurs. [this commit]: https://github.com/odoo/odoo/commit/686e011f9b54bcfe93cc22db24435d2ca9213664 Related to opw-2971181 X-original-commit: 17af7977a68c6ec991edb27141bb2889f59fcae9 Part-of: odoo/odoo#107062 --- .../web_editor/static/src/js/editor/snippets.editor.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 351e63ecd63c..7c17fae400a0 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -327,6 +327,7 @@ var SnippetEditor = Widget.extend({ if (this.isDestroyed()) { return; } + this.willDestroyEditors = true; await this.toggleTargetVisibility(!this.$target.hasClass('o_snippet_invisible')); const proms = _.map(this.styles, option => { return option.cleanForSave(); @@ -1139,6 +1140,10 @@ var SnippetEditor = Widget.extend({ * @param {OdooEvent} ev */ _onSnippetOptionVisibilityUpdate: function (ev) { + if (this.willDestroyEditors) { + // Do not update the option visibilities if we are destroying them. + return; + } ev.data.show = this._toggleVisibilityStatus(ev.data.show); }, /** @@ -1574,6 +1579,7 @@ var SnippetsMenu = Widget.extend({ // may be the moment where the public widgets need to be destroyed). this.trigger_up('ready_to_clean_for_save'); + this.willDestroyEditors = true; // Then destroy all snippet editors, making them call their own // "clean for save" methods (and options ones). await this._destroyEditors(); @@ -3403,6 +3409,10 @@ var SnippetsMenu = Widget.extend({ * @param {OdooEvent} ev */ _onSnippetOptionVisibilityUpdate: async function (ev) { + if (this.willDestroyEditors) { + // Do not update the option visibilities if we are destroying them. + return; + } if (!ev.data.show) { await this._activateSnippet(false); } -- GitLab