[FIX] web_editor: do not update the options when destroying them

Since [1] 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.

Before 16.0 (the merge of the frontend into the backend) the bug was
easily visible by following these steps:
- Drop 2 times the image - text block on a page
- Drop a popup block
- Save

=> During the save, a traceback occurs.
From 16.0 the race condition is more difficult to see but we still need
this fix because the problem is still there.

Note: this forward-port commit took time to get merged in master.
Meanwhile, two fixes related to it were merged in stable. The first one
already reached master a while ago ([2]) but had thus no effect as was
relying on this particular commit here. This is actually great as [2]
introduced a big mass mailing bug, fixed by the second fix which is yet
to be forward-ported to master. That one has actually been put as this
current commit's parent so that [2] is fixed before it can create the
mass mailing bug.

[1]: https://github.com/odoo/odoo/commit/686e011f9b54bcfe93cc22db24435d2ca9213664
[2]: https://github.com/odoo/odoo/commit/6bf3823c2996af4ec0534ff69471887ac43a8ddf

Related to opw-2971181

X-original-commit: 47cdb15082f774da0aa07e289361445ddc3a48f1
Part-of: odoo/odoo#107387
Co-authored-by: xO-Tx <mou@odoo.com>
This commit is contained in:
Guillaume (gdi)
2023-02-28 19:08:44 +01:00
co-authored by xO-Tx
parent 562c760ce8
commit 934f413c1f
@@ -1546,6 +1546,10 @@ var SnippetEditor = Widget.extend({
* @param {OdooEvent} ev
*/
_onSnippetOptionVisibilityUpdate: function (ev) {
if (this.options.wysiwyg.isSaving()) {
// Do not update the option visibilities if we are destroying them.
return;
}
ev.data.show = this._toggleVisibilityStatus(ev.data.show);
},
/**
@@ -4051,6 +4055,10 @@ var SnippetsMenu = Widget.extend({
* @param {OdooEvent} ev
*/
_onSnippetOptionVisibilityUpdate: async function (ev) {
if (this.options.wysiwyg.isSaving()) {
// Do not update the option visibilities if we are destroying them.
return;
}
if (!ev.data.show) {
await this._activateSnippet(false);
}