[FIX] web: avoid displaying empty dialog

BEFORE
If a dialog is destroyed while the dialog is being opened, an empty
modal is still displayed. This could arrive if its parent is destroyed
in this precise phase.

AFTER
The dialog checks if it has been destroyed right before being attached
to the DOM, so displaying an empty modal should not happen anymore.

Taskid-2461277

closes odoo/odoo#74175

X-original-commit: dbfff9079cccdf209cf4164c3722bc7baa1a16d3
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Bruno Boi <brboi@users.noreply.github.com>
This commit is contained in:
Bruno Boi
2021-08-12 14:12:41 +00:00
parent 40e339f449
commit 670cc8cdc6
2 changed files with 13 additions and 0 deletions
@@ -195,6 +195,9 @@ var Dialog = Widget.extend({
var self = this;
this.appendTo($('<div/>')).then(function () {
if (self.isDestroyed()) {
return;
}
self.$modal.find(".modal-body").replaceWith(self.$el);
self.$modal.attr('open', true);
self.$modal.removeAttr("aria-hidden");
@@ -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']");
});
});
});