From a7ade66595e13c4e227b2973ded2c83fc18d26c1 Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Mon, 9 Oct 2023 14:01:27 +0200 Subject: [PATCH] [FIX] web_editor: close iframe document after write Since [1], in case of import errors, the module loader waits for `document.readyState` to be "complete" or for the "DOMContentLoaded" event to be triggered in order to replace the DOM content by the error report. But, before this commit, the Wysiwyg's iframe document was opened for writing (`document.open` and `document.write`) and was never closed. As a result, the `readyState` would be left as `loading` and the error import would never be displayed in case of import errors, making imports fail silently. This commit makes sure the iframe document's `readyState` is changed back to "complete" after its content is written to it. [1]: odoo/odoo@e0fdb6a0b4bfaf9c04b52c1f74a266192d0d0676 task-3537756 Part-of: odoo/odoo#141882 Co-authored-by: Nicolas Bayet --- addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js index 967ace42d2e..b93e00f8808 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js @@ -147,6 +147,9 @@ patch(Wysiwyg.prototype, { .write(`${iframeContent}`); + // Closing the document might trigger a new 'load' event. + self.$iframe.off('load', onLoad); + self.$iframe[0].contentWindow.document.close(); }); self.options.document = self.$iframe[0].contentWindow.document; });