From 9c31da401da4bbf2864dbc63bbfaf70efceb9db3 Mon Sep 17 00:00:00 2001 From: Pierre Paridans Date: Fri, 22 Mar 2024 13:31:32 +0100 Subject: [PATCH] [FIX] web: handle MouseEvent triggered from TEXT_NODE in Firefox This commit "fixes" a weird behavior in Firefox where a MouseEvent ("mouseenter" in this case) can be triggered from the target's TEXT_NODE, even if it shouldn't... Note: even though this isn't clearly defined in the spec, MouseEvent shouldn't be dispatched for TEXT_NODE, as implemented in Blink or WebKit... But not everyone agrees (cf. tickets linked below). Steps to reproduce: - open website - go into edit mode - actually edit the page - add a snippet to the page - click on the "Discard" button and move very fast out of it => the error `el.matches is not a function` is "sometimes" raised (if you got the right timing) References: - https://w3c.github.io/uievents/#event-type-mouseenter - https://bugzilla.mozilla.org/show_bug.cgi?id=185889 - https://bugzilla.mozilla.org/show_bug.cgi?id=42717 - https://bugzilla.mozilla.org/show_bug.cgi?id=103055 closes odoo/odoo#158810 Signed-off-by: Samuel Degueldre (sad) --- addons/web/static/src/core/tooltip/tooltip_service.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/web/static/src/core/tooltip/tooltip_service.js b/addons/web/static/src/core/tooltip/tooltip_service.js index 38e2cca939d..7853f391f66 100644 --- a/addons/web/static/src/core/tooltip/tooltip_service.js +++ b/addons/web/static/src/core/tooltip/tooltip_service.js @@ -127,6 +127,11 @@ export const tooltipService = { * @param {HTMLElement} el */ function openElementsTooltip(el) { + // Fix weird behavior in Firefox where MouseEvent can be dispatched + // from TEXT_NODE, even if they shouldn't... + if (el.nodeType === Node.TEXT_NODE) { + return; + } if (elementsWithTooltips.has(el)) { openTooltip(el, elementsWithTooltips.get(el)); } else if (el.matches("[data-tooltip], [data-tooltip-template]")) {