From 8e37913eee703b4a23bc71610e23eb48b0269f7a Mon Sep 17 00:00:00 2001 From: Innei Date: Wed, 28 Aug 2024 21:33:16 +0800 Subject: [PATCH] fix: wrapped element `x,y` detection Signed-off-by: Innei --- src/providers/shared/WrappedElementProvider.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/providers/shared/WrappedElementProvider.tsx b/src/providers/shared/WrappedElementProvider.tsx index 2307ac4f91..d68a243dd7 100644 --- a/src/providers/shared/WrappedElementProvider.tsx +++ b/src/providers/shared/WrappedElementProvider.tsx @@ -70,25 +70,27 @@ export const WrappedElementProvider: Component = ({ const ArticleElementResizeObserver = () => { const setSize = useSetWrappedElementSize() const setPos = useSetElementPosition() - const $article = useWrappedElement() + const $element = useWrappedElement() useIsomorphicLayoutEffect(() => { - if (!$article) return - const { height, width, x, y } = $article.getBoundingClientRect() + if (!$element) return + const { height, width, x, y } = $element.getBoundingClientRect() setSize({ h: height, w: width }) setPos({ x, y }) const observer = new ResizeObserver((entries) => { const entry = entries[0] - const { height, width, x, y } = entry.contentRect + const { height, width } = entry.contentRect + const { x, y } = entry.target.getBoundingClientRect() + setSize({ h: height, w: width }) setPos({ x, y }) }) - observer.observe($article) + observer.observe($element) return () => { - observer.unobserve($article) + observer.unobserve($element) observer.disconnect() } - }, [$article]) + }, [$element]) return null }