Skip to content

Commit 32a699f

Browse files
committed
fix: OPTIC-765: TypeError: Cannot read properties of null (reading 'getBoundingClientRect')
1 parent d579e9d commit 32a699f

File tree

1 file changed

+6
-3
lines changed
  • web/libs/datamanager/src/components/Common/Tooltip

1 file changed

+6
-3
lines changed

web/libs/datamanager/src/components/Common/Tooltip/Tooltip.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ export const Tooltip = forwardRef(({ title, children, defaultVisible, disabled,
1515
const [align, setAlign] = useState("top-center");
1616

1717
const calculatePosition = useCallback(() => {
18+
// If the tooltip is not injected, we cannot yet calculate the position
19+
// Without this check the alignElements function will throw an error if the async transition is not finished but the component is already unmounted
20+
if (!triggerElement.current || !tooltipElement.current) return;
1821
const { left, top, align: resultAlign } = alignElements(triggerElement.current, tooltipElement.current, align, 10);
1922

2023
setOffset({ left, top });
2124
setAlign(resultAlign);
22-
}, [triggerElement.current, tooltipElement.current]);
25+
}, []);
2326

2427
const performAnimation = useCallback(
2528
(visible) => {
@@ -39,7 +42,7 @@ export const Tooltip = forwardRef(({ title, children, defaultVisible, disabled,
3942
});
4043
}
4144
},
42-
[injected, calculatePosition, tooltipElement],
45+
[injected, calculatePosition],
4346
);
4447

4548
const visibilityClasses = useMemo(() => {
@@ -72,7 +75,7 @@ export const Tooltip = forwardRef(({ title, children, defaultVisible, disabled,
7275
<Elem name="body">{title}</Elem>
7376
</Block>
7477
) : null,
75-
[injected, offset, title, visibilityClasses, tooltipElement],
78+
[injected, offset, title, visibilityClasses],
7679
);
7780

7881
useEffect(() => {

0 commit comments

Comments
 (0)