@@ -29,6 +29,8 @@ const Tooltip = forwardRef(({ content = '', children, hideShortcut, forcePositio
2929 const timeoutRef = useRef ( null ) ;
3030 const hiddenByClickRef = useRef ( false ) ;
3131 const childRef = useRef ( null ) ;
32+ const showRef = useRef ( false ) ; // track current show state to avoid redundant enqueues from high-frequency pointermove
33+ const opacityRef = useRef ( 0 ) ; // track current opacity to avoid redundant enqueues
3234 useImperativeHandle ( ref , ( ) => childRef . current ) ;
3335 const isDisabled = useSelector ( ( state ) => selectors . isElementDisabled ( state , 'tooltip' ) ) ;
3436
@@ -44,6 +46,20 @@ const Tooltip = forwardRef(({ content = '', children, hideShortcut, forcePositio
4446 const delayShow = 300 ;
4547 const opacityTimeout = 50 ;
4648
49+ const setShowGuarded = ( value ) => {
50+ if ( showRef . current !== value ) {
51+ showRef . current = value ;
52+ setShow ( value ) ;
53+ }
54+ } ;
55+
56+ const setOpacityGuarded = ( value ) => {
57+ if ( opacityRef . current !== value ) {
58+ opacityRef . current = value ;
59+ setOpacity ( value ) ;
60+ }
61+ } ;
62+
4763 useEffect ( ( ) => {
4864 const showToolTip = ( ) => {
4965 clearTimeout ( timeoutRef . current ) ;
@@ -52,14 +68,15 @@ const Tooltip = forwardRef(({ content = '', children, hideShortcut, forcePositio
5268 }
5369 timeoutRef . current = setTimeout ( ( ) => {
5470 setCloseToolTipFunc ( hideByClick ) ;
55- setShow ( true ) ;
71+ setShowGuarded ( true ) ;
5672 fireEvent ( Events . TOOLTIP_OPENED ) ;
5773 } , delayShow - opacityTimeout ) ;
5874 } ;
5975
6076 const hideTooltip = ( ) => {
6177 clearTimeout ( timeoutRef . current ) ;
62- setShow ( false ) ;
78+ setShowGuarded ( false ) ;
79+ setOpacityGuarded ( 0 ) ;
6380 } ;
6481
6582 const hideByBlur = ( ) => {
@@ -208,10 +225,10 @@ const Tooltip = forwardRef(({ content = '', children, hideShortcut, forcePositio
208225 if ( show && childEle && tooltipEle ) {
209226 setTopAndLeft ( ) ;
210227 setTimeout ( ( ) => {
211- setOpacity ( 1 ) ;
228+ setOpacityGuarded ( 1 ) ;
212229 } , opacityTimeout ) ;
213230 } else {
214- setOpacity ( 0 ) ;
231+ setOpacityGuarded ( 0 ) ;
215232 }
216233 } , [ childRef , show ] ) ;
217234
0 commit comments