Skip to content

Commit 3a644de

Browse files
Copilotdanielbarion
andcommitted
Add cleanup for handleShow timeout and position calculation promises
Co-authored-by: danielbarion <[email protected]>
1 parent 7068643 commit 3a644de

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const Tooltip = ({
7676
const tooltipShowDelayTimerRef = useRef<NodeJS.Timeout | null>(null)
7777
const tooltipHideDelayTimerRef = useRef<NodeJS.Timeout | null>(null)
7878
const missedTransitionTimerRef = useRef<NodeJS.Timeout | null>(null)
79+
const tooltipShowTimerRef = useRef<NodeJS.Timeout | null>(null)
7980
const [computedPosition, setComputedPosition] = useState<IComputedPosition>({
8081
tooltipStyles: {},
8182
tooltipArrowStyles: {},
@@ -194,7 +195,8 @@ const Tooltip = ({
194195
* wait for the component to render and calculate position
195196
* before actually showing
196197
*/
197-
setTimeout(() => {
198+
clearTimeoutRef(tooltipShowTimerRef)
199+
tooltipShowTimerRef.current = setTimeout(() => {
198200
if (!mounted.current) {
199201
return
200202
}
@@ -348,6 +350,9 @@ const Tooltip = ({
348350
border,
349351
arrowSize,
350352
}).then((computedStylesData) => {
353+
if (!mounted.current) {
354+
return
355+
}
351356
handleComputedPosition(computedStylesData)
352357
})
353358
}
@@ -803,6 +808,7 @@ const Tooltip = ({
803808
return () => {
804809
clearTimeoutRef(tooltipShowDelayTimerRef)
805810
clearTimeoutRef(tooltipHideDelayTimerRef)
811+
clearTimeoutRef(tooltipShowTimerRef)
806812
}
807813
}, [])
808814

0 commit comments

Comments
 (0)