From 6309d5e4e03eafffac6b1614f0511c4bbac9a188 Mon Sep 17 00:00:00 2001 From: "Mahdi Cheikh Rouhou (macr)" Date: Tue, 6 Feb 2024 09:36:07 +0100 Subject: [PATCH] [FIX] mass_mailing: solve error on add block mailing Issue: ====== Adding a new block in mailing in email marketing raises an error. Steps to reproduce the issue: ============================= - Go to email marketing - Create a new mailing - Create one from scratch - Drop any block - `TypeError : Cannor read properties of null (reading 'parentElement')` Origin of the issue: ==================== When we drop the block in the iframe's document we trigger the `click` event but we don't have any selection yet in the document so `anchorNode`will be `null` thus the error. task-3724551 closes odoo/odoo#152814 Signed-off-by: Antoine Guenet (age) --- addons/mass_mailing/static/src/js/snippets.editor.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/mass_mailing/static/src/js/snippets.editor.js b/addons/mass_mailing/static/src/js/snippets.editor.js index 91de87f2beb..79e208807b8 100644 --- a/addons/mass_mailing/static/src/js/snippets.editor.js +++ b/addons/mass_mailing/static/src/js/snippets.editor.js @@ -63,11 +63,13 @@ export const MassMailingSnippetsMenu = snippetsEditor.SnippetsMenu.extend({ // To prevent unnecessary tab shifting, we provide a selection for this specific case. if (srcElement.classList.contains('o_mail_wrapper') || srcElement.querySelector('.o_mail_wrapper')) { const selection = this.options.wysiwyg.odooEditor.document.getSelection(); - const parent = selection.anchorNode.parentElement; - if (parent) { - srcElement = parent; + if (selection.anchorNode) { + const parent = selection.anchorNode.parentElement; + if (parent) { + srcElement = parent; + } + this._activateSnippet($(srcElement)); } - this._activateSnippet($(srcElement)); } }, /**