From fb7246f3dd134a4ecb1c9adbba1bd295a7b7ff35 Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Thu, 4 Apr 2024 15:25:13 +0200 Subject: [PATCH] [FIX] web_editor: fix infinite loop on empty oe-structure click Steps to reproduce the bug: - Install e-commerce. - Open a product page in edit mode. - Click on the "product.description_ecommerce" field. - Bug: an infinite loop starts. The "selectionchange" event is triggered in an endless loop, causing various issues such as the page freezing after a while. This issue was introduced by this commit [1]. Since this other commit [2], when a selection itself is the main container of the editable area, we replace this selection to only include the content of it. With commit [1], this has been modified to take into account "oe_structure" and "[contenteditable]" elements. As these elements can be empty, clicking on them would reselect them, creating an endless loop since we'd never leave the condition that replaces the selection. [1]: https://github.com/odoo/odoo/commit/e93fa23c29421ffe8917d9650330585d6dad210f [2]: https://github.com/odoo/odoo/commit/10c5a16cd44b8d8e54082df90166f2309dfa788d task-3830033 closes odoo/odoo#160535 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index 4ec9cca67e5..46b68b60bda 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -4294,7 +4294,11 @@ export class OdooEditor extends EventTarget { selection.anchorNode === container && selection.focusNode === container && selection.anchorOffset === 0 && - selection.focusOffset === [...container.childNodes].length + selection.focusOffset === [...container.childNodes].length && + // Checks that the container is not an empty editable structure to + // avoid calling "getDeepRange" if it is, otherwise it will be + // selected again, creating an infine loop. + container.childNodes.length ) { getDeepRange(container, {select: true}); // The selection is changed in `getDeepRange` and will therefore