[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@e0fdb6a0b4

task-3537756

Part-of: odoo/odoo#141882
Co-authored-by: Nicolas Bayet <nby@odoo.com>
This commit is contained in:
Rodolpho Lima
2023-12-06 09:53:17 +00:00
co-authored by Nicolas Bayet
parent 11bd9e01b7
commit a7ade66595
@@ -147,6 +147,9 @@ patch(Wysiwyg.prototype, {
.write(`<!DOCTYPE html><html${
self.options.iframeHtmlClass ? ' class="' + self.options.iframeHtmlClass +'"' : ''
}>${iframeContent}</html>`);
// 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;
});