@@ -15,11 +15,14 @@ export const Tooltip = forwardRef(({ title, children, defaultVisible, disabled,
15
15
const [ align , setAlign ] = useState ( "top-center" ) ;
16
16
17
17
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 ;
18
21
const { left, top, align : resultAlign } = alignElements ( triggerElement . current , tooltipElement . current , align , 10 ) ;
19
22
20
23
setOffset ( { left, top } ) ;
21
24
setAlign ( resultAlign ) ;
22
- } , [ triggerElement . current , tooltipElement . current ] ) ;
25
+ } , [ ] ) ;
23
26
24
27
const performAnimation = useCallback (
25
28
( visible ) => {
@@ -39,7 +42,7 @@ export const Tooltip = forwardRef(({ title, children, defaultVisible, disabled,
39
42
} ) ;
40
43
}
41
44
} ,
42
- [ injected , calculatePosition , tooltipElement ] ,
45
+ [ injected , calculatePosition ] ,
43
46
) ;
44
47
45
48
const visibilityClasses = useMemo ( ( ) => {
@@ -72,7 +75,7 @@ export const Tooltip = forwardRef(({ title, children, defaultVisible, disabled,
72
75
< Elem name = "body" > { title } </ Elem >
73
76
</ Block >
74
77
) : null ,
75
- [ injected , offset , title , visibilityClasses , tooltipElement ] ,
78
+ [ injected , offset , title , visibilityClasses ] ,
76
79
) ;
77
80
78
81
useEffect ( ( ) => {
0 commit comments