From 670cc8cdc6d3a474b45ef54d995ae2df5581f548 Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Thu, 22 Jul 2021 06:06:46 +0000 Subject: [PATCH] [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) Signed-off-by: Bruno Boi --- addons/web/static/src/legacy/js/core/dialog.js | 3 +++ addons/web/static/tests/legacy/core/dialog_tests.js | 10 ++++++++++ 2 files changed, 13 insertions(+) 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']"); + }); }); });