From 3812314430666172a268d277e1f731584c58885d Mon Sep 17 00:00:00 2001 From: gabrieljablonski Date: Tue, 24 Oct 2023 17:23:20 -0300 Subject: [PATCH] fix: catch possible invalid CSS selector --- src/components/Tooltip/Tooltip.tsx | 33 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index c0f122f1..5413a652 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -504,19 +504,26 @@ const Tooltip = ({ if (activeAnchor) { const elements = [...mutation.removedNodes].filter((node) => node.nodeType === 1) if (selector) { - removedAnchors.push( - // the element itself is an anchor - ...(elements.filter((element) => - (element as HTMLElement).matches(selector), - ) as HTMLElement[]), - ) - removedAnchors.push( - // the element has children which are anchors - ...elements.flatMap( - (element) => - [...(element as HTMLElement).querySelectorAll(selector)] as HTMLElement[], - ), - ) + try { + removedAnchors.push( + // the element itself is an anchor + ...(elements.filter((element) => + (element as HTMLElement).matches(selector), + ) as HTMLElement[]), + ) + removedAnchors.push( + // the element has children which are anchors + ...elements.flatMap( + (element) => + [...(element as HTMLElement).querySelectorAll(selector)] as HTMLElement[], + ), + ) + } catch { + /** + * invalid CSS selector. + * already warned on tooltip controller + */ + } } elements.some((node) => { if (node?.contains?.(activeAnchor)) {