From f2e8c22831bd16dd024bf90acfad800fa85b084a Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Tue, 24 May 2022 08:51:09 +0000 Subject: [PATCH] [FIX] web_editor: only partially clean for urgentSave The urgentSave fix at f9d27d41 was broken by 9e02cec48. Do not wait for the resolution of the cleanForSave promise to update the internal value in case this happens during an urgentSave as the beforeunload event does not play well with asynchronicity. It is better to have a partially cleared value than to lose changes. When this function is called outside of an urgentSave context, the full cleaning is still awaited below and `_super` will reupdate the value. Task-2861050 closes odoo/odoo#95336 X-original-commit: 0483a778a4032fe2264cfdd5f037834cfb903845 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/backend/field_html.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/web_editor/static/src/js/backend/field_html.js b/addons/web_editor/static/src/js/backend/field_html.js index 2ed796da3da..97cfc6b3e25 100644 --- a/addons/web_editor/static/src/js/backend/field_html.js +++ b/addons/web_editor/static/src/js/backend/field_html.js @@ -101,12 +101,20 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, { return this._super(); } var _super = this._super.bind(this); - await this.wysiwyg.cleanForSave(); + // Do not wait for the resolution of the cleanForSave promise to update + // the internal value in case this happens during an urgentSave as the + // beforeunload event does not play well with asynchronicity. It is + // better to have a partially cleared value than to lose changes. When + // this function is called outside of an urgentSave context, the full + // cleaning is still awaited below and `_super` will reupdate the value. + const fullClean = this.wysiwyg.cleanForSave(); this._setValue(this._getValue()); - return this.wysiwyg.saveModifiedImages(this.$content).then(() => { - this._isDirty = this.wysiwyg.isDirty(); - _super(); - }); + this._isDirty = this.wysiwyg.isDirty(); + await fullClean; + await this.wysiwyg.saveModifiedImages(this.$content); + // Update the value to the fully cleaned version. + this._setValue(this._getValue()); + _super(); }, /** * @override