Skip to content

Commit

Permalink
Wrap check in useLayoutEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltaranto committed Oct 17, 2023
1 parent f25c0d9 commit c9765ad
Showing 1 changed file with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, {
useEffect,
useContext,
useRef,
useLayoutEffect,
} from 'react';
import { usePopperTooltip } from 'react-popper-tooltip';
import isMobile from 'is-mobile';
Expand Down Expand Up @@ -205,23 +206,25 @@ export const TooltipRenderer = ({
},
);

// If the tooltip is visible and the size or position of either the trigger
// or the tooltip has changed, then update the tooltip size and position.
if (
controlledVisible &&
update &&
(doesBoundingBoxNeedUpdating(triggerRef, triggerBoundingBoxRef.current) ||
doesBoundingBoxNeedUpdating(tooltipRef, tooltipBoundingRectRef.current))
) {
triggerBoundingBoxRef.current = normaliseRect(
triggerRef?.getBoundingClientRect(),
);
tooltipBoundingRectRef.current = normaliseRect(
tooltipRef?.getBoundingClientRect(),
);

update();
}
useLayoutEffect(() => {
// If the tooltip is visible and the size or position of either the trigger
// or the tooltip has changed, then update the tooltip size and position.
if (
controlledVisible &&
update &&
(doesBoundingBoxNeedUpdating(triggerRef, triggerBoundingBoxRef.current) ||
doesBoundingBoxNeedUpdating(tooltipRef, tooltipBoundingRectRef.current))
) {
triggerBoundingBoxRef.current = normaliseRect(
triggerRef?.getBoundingClientRect(),
);
tooltipBoundingRectRef.current = normaliseRect(
tooltipRef?.getBoundingClientRect(),
);

update();
}
});

useEffect(() => {
if (visible) {
Expand Down

0 comments on commit c9765ad

Please sign in to comment.