Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/cdk/platform/features/shadow-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,14 @@ export function _getFocusedElementPierceShadowDom(): HTMLElement | null {
export function _getEventTarget<T extends EventTarget>(event: Event): T | null {
// If an event is bound outside the Shadow DOM, the `event.target` will
// point to the shadow root so we have to use `composedPath` instead.
return (event.composedPath ? event.composedPath()[0] : event.target) as T | null;
if (event.composedPath) {
try {
return event.composedPath()[0] as T | null;
} catch {
// Hydration event replay can dispatch wrapper events whose `composedPath`
// intentionally throws. Fall back to the event target in that case.
}
}

return event.target as T | null;
}
Loading