Skip to content

Commit abf1e45

Browse files
authored
initialize visibility on re-slotted/re-attached hotspot elements (#5161)
When a hotspot's light DOM element is shifted in the children list (e.g., because another hotspot is deleted in a reactive UI loop), the browser detaches and re-attaches (re-slots) the element. While the core AnnotationMixin correctly reuses the existing Three.js Hotspot instance and increments its reference count, the newly attached DOM button element never receives the current visibility attributes (such as `data-visible`) because the hotspot's general visibility state has not transitioned. This leaves the re-slotted buttons in a hollow, invisible, or un-annotated state depending on CSS selectors matching :not([data-visible]). This patch updates the addHotspot path in the AnnotationMixin to immediately set the visibility attribute and dispatch the target `hotspot-visibility` custom event on the incoming node when its associated Hotspot object already exists. This guarantees that re-slotted elements inherit and render with the correct Three.js visibility states instantly.
1 parent 24c03ac commit abf1e45

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

packages/model-viewer/src/features/annotation.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ export const AnnotationMixin = <T extends Constructor<ModelViewerElementBase>>(
253253

254254
if (hotspot != null) {
255255
hotspot.increment();
256+
const visibilityAttribute = node.dataset.visibilityAttribute;
257+
if (visibilityAttribute != null) {
258+
const attributeName = `data-${visibilityAttribute}`;
259+
node.toggleAttribute(attributeName, hotspot.facingCamera);
260+
}
261+
node.dispatchEvent(new CustomEvent('hotspot-visibility', {
262+
detail: {
263+
visible: hotspot.facingCamera,
264+
},
265+
}));
256266
} else {
257267
hotspot = new Hotspot({
258268
name: node.slot,

0 commit comments

Comments
 (0)