diff --git a/libs/features/webapp-prompt/webapp-prompt.js b/libs/features/webapp-prompt/webapp-prompt.js index c1be12f4a9..418d2ad68d 100644 --- a/libs/features/webapp-prompt/webapp-prompt.js +++ b/libs/features/webapp-prompt/webapp-prompt.js @@ -53,8 +53,13 @@ class AppPrompt { this.getAnchorState = getAnchorState; this.id = this.promptPath.split('/').pop(); this.elements = {}; - if (modalsActive()) waitForClosedModalsThen(this.init); - else this.init(); + if (modalsActive()) { + window.addEventListener( + 'milo:modal:closed', + () => waitForClosedModalsThen(this.init), + { once: true }, + ); + } else this.init(); } init = async () => { diff --git a/test/features/webapp-prompt/webapp-prompt.test.js b/test/features/webapp-prompt/webapp-prompt.test.js index 1e90c0be96..c3e6bf6c6c 100644 --- a/test/features/webapp-prompt/webapp-prompt.test.js +++ b/test/features/webapp-prompt/webapp-prompt.test.js @@ -93,8 +93,8 @@ describe('PEP', () => { }); it('should not render PEP when the GRM is open', async () => { - document.body.insertAdjacentHTML('afterbegin', '
'); - document.body.insertAdjacentHTML('afterbegin', '
'); + document.body.insertAdjacentHTML('afterbegin', '
'); + document.body.insertAdjacentHTML('afterbegin', '
'); await initPep({}); @@ -104,8 +104,11 @@ describe('PEP', () => { expect(document.querySelector(allSelectors.pepWrapper)).to.not.exist; } + const event = new CustomEvent('milo:modal:closed'); + window.dispatchEvent(event); + document.querySelector('.locale-modal-v2')?.remove(); - document.querySelector('.locale-modal')?.remove(); + document.querySelector('.dialog-modal')?.remove(); await clock.runAllAsync(); expect(document.querySelector(allSelectors.pepWrapper)).to.exist;