From 3dd4e91ff5b871cc8e27ac3ca50e18bcea064dc2 Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Sun, 5 Jan 2025 12:52:22 +0100 Subject: [PATCH] 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. --- spine-ts/spine-webgl/src/SpineWebComponentWidget.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spine-ts/spine-webgl/src/SpineWebComponentWidget.ts b/spine-ts/spine-webgl/src/SpineWebComponentWidget.ts index 069719c7a..8b3c8d14b 100644 --- a/spine-ts/spine-webgl/src/SpineWebComponentWidget.ts +++ b/spine-ts/spine-webgl/src/SpineWebComponentWidget.ts @@ -1416,8 +1416,12 @@ class SpineWebComponentOverlay extends HTMLElement implements OverlayAttributes, addWidget (widget: SpineWebComponentWidget) { this.skeletonList.push(widget); this.intersectionObserver?.observe(widget.getHTMLElementReference()); - if (this.loaded && (this.compareDocumentPosition(widget) & Node.DOCUMENT_POSITION_FOLLOWING)) { - this.parentElement!.appendChild(this); + if (this.loaded) { + 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); + } } }