Skip to content

Commit

Permalink
fix: catch possible invalid CSS selector
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieljablonski committed Oct 24, 2023
1 parent fafd151 commit 3812314
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 3812314

Please sign in to comment.