fix: fall back to DOM traversal in targetFromEvent when composedPath is empty
composedPath() returns an empty array once the native event is no longer dispatching. In React 19, events from a portal-within-portal (EmojiBoard inside #portalContainer, which already hosts the Settings Overlay) can reach the synthetic event handler after the native dispatch window closes. The fallback walks up from evt.target so handleGroupItemClick still finds the emoji button and calls onEmojiSelect — fixing emoji selection in the status-message editor in Settings > Account > Profile. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+11
-1
@@ -1,6 +1,16 @@
|
||||
export const targetFromEvent = (evt: Event, selector: string): Element | undefined => {
|
||||
const targets = evt.composedPath() as Element[];
|
||||
return targets.find((target) => target.matches?.(selector));
|
||||
if (targets.length > 0) {
|
||||
return targets.find((target) => target.matches?.(selector));
|
||||
}
|
||||
// composedPath() is empty when the event is no longer dispatching (e.g. inside a
|
||||
// portal-within-portal in React 19). Walk up the DOM from evt.target instead.
|
||||
let el = evt.target instanceof Element ? evt.target : null;
|
||||
while (el) {
|
||||
if (el.matches(selector)) return el;
|
||||
el = el.parentElement;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const editableActiveElement = (): boolean =>
|
||||
|
||||
Reference in New Issue
Block a user