Skip to content

Commit

Permalink
fix: ensure first call
Browse files Browse the repository at this point in the history
  • Loading branch information
YSMJ1994 committed Nov 20, 2023
1 parent 3795da0 commit 11a79bc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,12 @@ const Overlay = React.forwardRef<HTMLDivElement, OverlayProps>((props, ref) => {
});

const waitTime = 100;
ro.current = new ResizeObserver(throttle(updatePosition, waitTime));
const throttledUpdatePosition = throttle(updatePosition, waitTime);
ro.current = new ResizeObserver(throttledUpdatePosition);
ro.current.observe(containerNode);
ro.current.observe(node);
// fist call, 不依赖 ResizeObserver ovserve时的首次执行(测试环境不会执行),因为 throttle 原因也不会执行两次
throttledUpdatePosition();

forceUpdate({});

Expand Down

0 comments on commit 11a79bc

Please sign in to comment.