Skip to content

Commit 3812314

Browse files
fix: catch possible invalid CSS selector
1 parent fafd151 commit 3812314

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

Diff for: src/components/Tooltip/Tooltip.tsx

+20-13
Original file line numberDiff line numberDiff line change
@@ -504,19 +504,26 @@ const Tooltip = ({
504504
if (activeAnchor) {
505505
const elements = [...mutation.removedNodes].filter((node) => node.nodeType === 1)
506506
if (selector) {
507-
removedAnchors.push(
508-
// the element itself is an anchor
509-
...(elements.filter((element) =>
510-
(element as HTMLElement).matches(selector),
511-
) as HTMLElement[]),
512-
)
513-
removedAnchors.push(
514-
// the element has children which are anchors
515-
...elements.flatMap(
516-
(element) =>
517-
[...(element as HTMLElement).querySelectorAll(selector)] as HTMLElement[],
518-
),
519-
)
507+
try {
508+
removedAnchors.push(
509+
// the element itself is an anchor
510+
...(elements.filter((element) =>
511+
(element as HTMLElement).matches(selector),
512+
) as HTMLElement[]),
513+
)
514+
removedAnchors.push(
515+
// the element has children which are anchors
516+
...elements.flatMap(
517+
(element) =>
518+
[...(element as HTMLElement).querySelectorAll(selector)] as HTMLElement[],
519+
),
520+
)
521+
} catch {
522+
/**
523+
* invalid CSS selector.
524+
* already warned on tooltip controller
525+
*/
526+
}
520527
}
521528
elements.some((node) => {
522529
if (node?.contains?.(activeAnchor)) {

0 commit comments

Comments
 (0)