[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) <dmo@odoo.com>
This commit is contained in:
David Monjoie
2022-07-05 16:20:53 +02:00
parent 51f1db9ce4
commit f2e8c22831
@@ -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