diff --git a/addons/web/static/src/legacy/js/core/dialog.js b/addons/web/static/src/legacy/js/core/dialog.js index 7cef878b1bc..1fdf50de198 100644 --- a/addons/web/static/src/legacy/js/core/dialog.js +++ b/addons/web/static/src/legacy/js/core/dialog.js @@ -195,6 +195,9 @@ var Dialog = Widget.extend({ var self = this; this.appendTo($('
')).then(function () { + if (self.isDestroyed()) { + return; + } self.$modal.find(".modal-body").replaceWith(self.$el); self.$modal.attr('open', true); self.$modal.removeAttr("aria-hidden"); diff --git a/addons/web/static/tests/legacy/core/dialog_tests.js b/addons/web/static/tests/legacy/core/dialog_tests.js index abb1cb43251..3c83b2ba3b0 100644 --- a/addons/web/static/tests/legacy/core/dialog_tests.js +++ b/addons/web/static/tests/legacy/core/dialog_tests.js @@ -158,6 +158,16 @@ QUnit.module('core', {}, function () { parent.destroy(); }); + + QUnit.test("Should not be displayed if parent is destroyed while dialog is being opened", async function (assert) { + assert.expect(1); + const parent = await createEmptyParent(); + const dialog = new Dialog(parent); + dialog.open(); + parent.destroy(); + await testUtils.nextTick(); + assert.containsNone(document.body, ".modal[role='dialog']"); + }); }); });