Skip to content

Commit db0f832

Browse files
Merge pull request #54 from equinor/fix/48/revert_reuse_fix_query_selector
fix(48): Revert trying to reuse annotations root, but leave fix for q…
2 parents 73dcec1 + 00285d5 commit db0f832

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/components/Annotations/Annotations.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,14 @@ export const Annotations = ({ maxVisible = 100, children }: AnnotationsProviderP
111111

112112
if (!parent) throw Error('Unable to create root!')
113113

114-
let container: HTMLElement | null = parent.querySelector(`#${id}`)
115-
116-
if (!container) {
117-
container = document.createElement('div')
118-
container.setAttribute('id', id)
119-
container.setAttribute('style', 'position:absolute;top:0;left:0;z-index: 1;pointer-events:none;padding:0;width:100%;height:100%;user-select:none')
120-
parent.appendChild(container)
121-
}
122-
123-
const annotationsRoot = createRoot(container)
124-
125-
return annotationsRoot
114+
parent.querySelector(`#${id}`)?.remove() // remove any existing annotations container
115+
116+
const container = document.createElement('div')
117+
container.setAttribute('id', id)
118+
container.setAttribute('style', 'position:absolute;top:0;left:0;z-index: 1;pointer-events:none;padding:0;width:100%;height:100%;user-select:none')
119+
parent.appendChild(container)
120+
121+
return createRoot(container)
126122
}, [renderer])
127123

128124
useEffect(() => {
@@ -134,7 +130,6 @@ export const Annotations = ({ maxVisible = 100, children }: AnnotationsProviderP
134130
}, [root, dispose])
135131

136132

137-
138133
useFrame(({ gl, camera, scene, clock, pointer }) => {
139134
// take over the render loop so we can ensure we render on top of the last frame
140135
gl.getSize(size)

0 commit comments

Comments
 (0)