diff --git a/js/widgets/popup.js b/js/widgets/popup.js index c0f13536e96..8caea3a6774 100644 --- a/js/widgets/popup.js +++ b/js/widgets/popup.js @@ -683,6 +683,13 @@ define( [ "jquery", // Put the element back to where the placeholder was and remove the "ui-popup" class this._setTheme( "none" ); this.element + // Cannot directly insertAfter() - we need to detach() first, because + // insertAfter() will do nothing if the payload div was not attached + // to the DOM at the time the widget was created, and so the payload + // will remain inside the container even after we call insertAfter(). + // If that happens and we remove the container a few lines below, we + // will cause an infinite recursion - #5244 + .detach() .insertAfter( this._ui.placeholder ) .removeClass( "ui-popup ui-overlay-shadow ui-corner-all" ); this._ui.screen.remove();