From 939af8d88633021817a0047a01841c34931b1617 Mon Sep 17 00:00:00 2001 From: franmagn Date: Tue, 14 Oct 2025 19:10:45 +0200 Subject: [PATCH] fix(#4): :bug: address NotFoundError This fix solves the NotFoundError, throwed whenever there was an attempt of removing an already removed target --- src/AnnotationControl/annotationPanel.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/AnnotationControl/annotationPanel.js b/src/AnnotationControl/annotationPanel.js index 5feb80e..d1e86fb 100644 --- a/src/AnnotationControl/annotationPanel.js +++ b/src/AnnotationControl/annotationPanel.js @@ -343,7 +343,23 @@ export function initAnnotationsPanel(viewer) { ev.stopPropagation() startInlineEditForUUID(uuid) }) - input.replaceWith(newLabel) + // The input may have been removed already by an external update. + // Check connectivity before replacing to avoid DOMNotFound errors. + try { + if (input.isConnected) { + input.replaceWith(newLabel) + } else { + // If input no longer in DOM, ensure any existing label is updated instead + const existing = targetContainer.querySelector(`.annotation-label[data-uuid="${uuid}"]`) + if (existing) existing.textContent = newText + } + } catch (e) { + // ignore DOM replacement errors and try to update label if present + try { + const existing = targetContainer.querySelector(`.annotation-label[data-uuid="${uuid}"]`) + if (existing) existing.textContent = newText + } catch (_) {} + } // commit to jsTree and live annotation _commitEditedName(uuid, newText) }