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