From b8fe3ee7795baa6efe4d4f7aa5eed56552472c6d Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Thu, 23 Nov 2023 11:38:46 +0100 Subject: [PATCH] [FIX] web_editor: colorPalette mount in mass_mailing Since [1], the colorPalette component is mounted on a new App via the attachComponent compatibility util. The new App is subject to target validation, which fails in mass_mailing and raises a traceback. This happens because the element for mounting the color palette is created by the top window's document and later attached to the iframe's DOM tree. Unfortunately this holds true for the entire sidebar is mass_mailing. Commit [2] apparently added some flexibility to the attachComponent util, temporarily disabling target validation when about to mount an App. But, due to the asynchronous nature of mounting an App, this was not enough for the present case, as the original App.validateTarget function is restored before it gets called when mounting the ColorPalette. This commit fixes this localized issued, leaving a large-scale fix, in which the snippets menu elements are properly created by the correct document, for a future commit on master. This will have to take into consideration the fact that the code for the snippets menu is shared between mass_mailing and website, and that, in the latter, the snippets menu sits outside the iframe, thus, it is part of the top document tree. Alternatively, the snippets menu should be refactored and converted to owl. task-3605859 [1]: https://github.com/odoo/odoo/commit/36061a4ab017a463c1d5bf838334cb4c0fac25ee [2]: https://github.com/odoo/odoo/commit/6a30ab13536a2dc0a8f23df32962cd1ceec71a5d closes odoo/odoo#143340 Signed-off-by: Antoine Guenet (age) Co-authored-by: Jinjiu Liu --- .../static/src/js/editor/snippets.options.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index e5b78194baa..a45e12d8be8 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -1778,6 +1778,16 @@ const ColorpickerUserValueWidget = SelectUserValueWidget.extend({ options.getTemplate = wysiwyg.getColorpickerTemplate.bind(wysiwyg); } this.colorPaletteWrapper?.destroy(); + const sidebarDocument = this.colorPaletteEl.ownerDocument; + if (!(this.colorPaletteEl instanceof sidebarDocument.defaultView.HTMLElement)) { + // When inside an iframe, the element for mounting a component must + // be an instance of the iframe's HTMLElement, or else target + // validation for attachComponent fails. + const newEl = sidebarDocument.importNode(this.colorPaletteEl, true); + this.colorPaletteEl.before(newEl); + this.colorPaletteEl.remove(); + this.colorPaletteEl = newEl; + } this.colorPaletteWrapper = await attachComponent(this, this.colorPaletteEl, ColorPalette, options); }, /**