From fe63c5d706d279ae4678a6004f898486f726d7ee Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 25 Nov 2024 20:42:31 -0500 Subject: [PATCH] fix: JS error in usePosition hook --- app/editor/components/FloatingToolbar.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/editor/components/FloatingToolbar.tsx b/app/editor/components/FloatingToolbar.tsx index b45173d406..7797a5e2d8 100644 --- a/app/editor/components/FloatingToolbar.tsx +++ b/app/editor/components/FloatingToolbar.tsx @@ -131,13 +131,15 @@ function usePosition({ // Images need their own positioning to get the toolbar in the center if (isImageSelection) { - const element = view.nodeDOM(selection.from) as HTMLElement; + const element = view.nodeDOM(selection.from); // Images are wrapped which impacts positioning - need to get the element // specifically tagged as the handle - const imageElement = element.getElementsByClassName( - EditorStyleHelper.imageHandle - )[0]; + const imageElement = element + ? (element as HTMLElement).getElementsByClassName( + EditorStyleHelper.imageHandle + )[0] + : undefined; if (imageElement) { const { left, top, width } = imageElement.getBoundingClientRect();