From 556041a41ff40834ed9cee61bb6cc26f2f380709 Mon Sep 17 00:00:00 2001
From: Vukile Langa <vukilelanga@me.com>
Date: Fri, 14 Jun 2024 16:37:34 +0200
Subject: [PATCH] fix(services): check if image exists before getting siblings

---
 wax-prosemirror-services/src/ImageService/AltComponent.js   | 6 ++++--
 .../src/ImageService/LongDescComponent.js                   | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/wax-prosemirror-services/src/ImageService/AltComponent.js b/wax-prosemirror-services/src/ImageService/AltComponent.js
index c7354b0b4..826e6e9e8 100644
--- a/wax-prosemirror-services/src/ImageService/AltComponent.js
+++ b/wax-prosemirror-services/src/ImageService/AltComponent.js
@@ -50,10 +50,12 @@ export default ({ setPosition, position }) => {
         `[data-fileid='${selection.node.attrs.fileid}']`,
       );
 
+    if (!image) return;
+
     const siblings = [...image.parentElement.children];
-    const figCaption = siblings.find(s => s.localName === 'figcaption');
+    const figCaption = siblings.find(s => s.tagName === 'FIGCAPTION');
 
-    if (!image || !figCaption) return;
+    if (!figCaption) return;
     const imagePosition = image.getBoundingClientRect();
     const figCaptionPosition = figCaption.getBoundingClientRect().height - 5;
     const left = imagePosition.left - WaxSurface.left;
diff --git a/wax-prosemirror-services/src/ImageService/LongDescComponent.js b/wax-prosemirror-services/src/ImageService/LongDescComponent.js
index 2412b9474..ca3a9b1c6 100644
--- a/wax-prosemirror-services/src/ImageService/LongDescComponent.js
+++ b/wax-prosemirror-services/src/ImageService/LongDescComponent.js
@@ -53,10 +53,12 @@ export default ({ setPosition, position }) => {
         `[data-fileid='${selection.node.attrs.fileid}']`,
       );
 
+    if (!image) return;
+
     const siblings = [...image.parentElement.children];
-    const figCaption = siblings.find(s => s.localName === 'figcaption');
+    const figCaption = siblings.find(s => s.tagName === 'FIGCAPTION');
 
-    if (!image || !figCaption) return;
+    if (!figCaption) return;
     const imagePosition = image.getBoundingClientRect();
     const figCaptionPosition = figCaption.getBoundingClientRect().height + 10;
     const left = imagePosition.left - WaxSurface.left;
-- 
GitLab