Skip to content

Commit 5119c5b

Browse files
authored
fix(48): remove existing annotations container before creating new one (#49)
1 parent f449f7b commit 5119c5b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/components/Annotations/Annotations.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const size = new Vector2()
4444

4545
let x1: number, x2: number, y1: number, y2: number
4646

47+
const id = `annotations_root`;
4748

4849
/**
4950
* The Annotations component is special provider component responsible for managing
@@ -107,14 +108,20 @@ export const Annotations = ({ maxVisible = 100, children }: AnnotationsProviderP
107108

108109
const root = useMemo(() => {
109110
const parent = renderer.domElement.parentElement
110-
let container: HTMLElement | null = null
111111

112112
if (!parent) throw Error('Unable to create root!')
113+
114+
let container: HTMLElement | null = parent.querySelector(id)
115+
116+
if (container) {
117+
container.remove()
118+
}
119+
113120
container = document.createElement('div')
114-
container.setAttribute('id', 'annotations')
121+
container.setAttribute('id', id)
115122
container.setAttribute('style', 'position:absolute;top:0;left:0;z-index: 1;pointer-events:none;padding:0;width:100%;height:100%;user-select:none')
116-
117123
parent.appendChild(container)
124+
118125
const annotationsRoot = createRoot(container)
119126

120127
return annotationsRoot

0 commit comments

Comments
 (0)