From 11a79bc4c43d3697dc43e12d569a891bb2512678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8F=B5=E4=B9=8B?= Date: Mon, 20 Nov 2023 20:32:52 +0800 Subject: [PATCH] fix: ensure first call --- src/overlay.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/overlay.tsx b/src/overlay.tsx index 614de9b..b34321b 100644 --- a/src/overlay.tsx +++ b/src/overlay.tsx @@ -295,9 +295,12 @@ const Overlay = React.forwardRef((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({});