Files
outline/shared/editor/lib/eventTarget.ts
T
Tom MoorandClaude c265112bd0 fix: Guard Mermaid mouse handlers against text node event targets (#14717)
In Firefox, a mousedown in the editor can have a Text node as its target.
The Mermaid plugin cast the target to HTMLElement and called closest(),
which threw and stopped ProseMirror from handling the event. Resolve the
target to its element (or parent element) before calling element methods.

Sentry: OUTLINE-CLOUD-DFP


Claude-Session: https://claude.ai/code/session_016MJXFcsyhupagpKC181rqW

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-25 19:20:00 -05:00

19 lines
610 B
TypeScript

/**
* Returns the element an event was dispatched to. When the target is a text
* node, as can happen in Firefox, its parent element is returned instead so
* that element methods such as `closest` can be used safely.
*
* @param event the DOM event.
* @returns the target element, or null if the target is not in an element.
*/
export function getEventTargetElement(event: Event): Element | null {
const { target } = event;
if (typeof Node === "undefined" || !(target instanceof Node)) {
return null;
}
if (target instanceof Element) {
return target;
}
return target.parentElement;
}