[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) <sad@odoo.com>
This commit is contained in:
Pierre Paridans
2024-03-27 10:59:17 +00:00
parent 65cd911a5a
commit 9c31da401d
@@ -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]")) {