diff --git a/web/vector-utils.js b/web/vector-utils.js index e9a208764..ca33306b1 100644 --- a/web/vector-utils.js +++ b/web/vector-utils.js @@ -1,19 +1,21 @@ // @flow import invariant from 'invariant'; declare class SVGElement extends Element {} -function htmlTargetFromEvent(event: SyntheticEvent<*>): HTMLElement { - let target = event.target; +function htmlTargetFromEvent(event: SyntheticEvent): HTMLElement { + let target: EventTarget = event.target; while (!(target instanceof HTMLElement)) { invariant( target instanceof SVGElement, - 'non-HTMLElements in typeahead should be SVGElements', + 'non-HTMLElements in DOM should be SVGElements', ); - target = target.parentNode; + const { parentNode } = target; + invariant(parentNode, 'non-HTMLElements in DOM should have parentNode'); + target = parentNode; } return target; } export { htmlTargetFromEvent };