-
-
Notifications
You must be signed in to change notification settings - Fork 132
Closed as not planned
Closed as not planned
Copy link
Labels
bugSomething isn't workingSomething isn't working
Description
The useOutsideClickCallback hook uses an unsafe as any type cast when checking if a click target is outside a referenced element. This bypasses TypeScript's type safety and could potentially hide runtime errors.
How to Reproduce
visit this file - apps/studio/src/helpers/useOutsideClickCallback.ts
export function useOutsideClickCallback(ref: MutableRefObject<HTMLElement | null>, callback: () => void) {
useEffect(() => {
function handleClickOutside(event: MouseEvent) {
if (ref.current && !ref.current.contains(event.target as any)) {
callback();
}
}
document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, [ref]);
}
Expected behavior
MouseEvent.target has type EventTarget | null, but HTMLElement.contains() expects a Node | null parameter.
If event.target is somehow not a Node (e.g., in edge cases with SVG elements or shadow DOM), the contains() method could behave unexpectedly
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Done