Fixed a bug where an infinite loop occurred in Firefox when compareDocumentPosition results in DOCUMENT_POSITION_DISCONNECTED.

In both Chrome and Firefox, when an element is inside a webcomponent the comparison results in DOCUMENT_POSITION_DISCONNECTED. But in Firefox the element result in DOCUMENT_POSITION_FOLLOWING too, leading to an infinite loop.
This commit is contained in:
Davide Tantillo 2025-01-05 12:52:22 +01:00
parent 4d795da488
commit 3dd4e91ff5

View File

@ -1416,8 +1416,12 @@ class SpineWebComponentOverlay extends HTMLElement implements OverlayAttributes,
addWidget (widget: SpineWebComponentWidget) { addWidget (widget: SpineWebComponentWidget) {
this.skeletonList.push(widget); this.skeletonList.push(widget);
this.intersectionObserver?.observe(widget.getHTMLElementReference()); this.intersectionObserver?.observe(widget.getHTMLElementReference());
if (this.loaded && (this.compareDocumentPosition(widget) & Node.DOCUMENT_POSITION_FOLLOWING)) { if (this.loaded) {
this.parentElement!.appendChild(this); const comparison = this.compareDocumentPosition(widget);
// DOCUMENT_POSITION_DISCONNECTED is needed when a widget is inside the overlay (due to followBone)
if ((comparison & Node.DOCUMENT_POSITION_FOLLOWING) && !(comparison & Node.DOCUMENT_POSITION_DISCONNECTED)) {
this.parentElement!.appendChild(this);
}
} }
} }