From 94d7b2a773f2c4666c263d1d26cdbe278887f8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 27 Mar 2023 13:01:17 +0000 Subject: [PATCH] [FIX] web: ComponentAdapter: detach it after unmounting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, the ComponentAdapter would detach its dom before calling the on_detach callback. This is not correct (even though it is usually ok): we want the "unmount" code to be executed while the widget is in the DOM, not after it has been detached. It is even more problematic if the sub widget contains itself some owl components, since this behaviour break Owl assumption that owl components are in the DOM before being unmounted (so, for example, since owl 2.0.9, references are null even if component is not in the DOM, even if the component is still mounted). The fix is quite simple: simply do the DOM removal after calling the callback. closes odoo/odoo#116752 X-original-commit: c56795d8715c9f1c85dec88d1c39e8becb4b1e62 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Géry Debongnie --- addons/web/static/tests/legacy/owl_compatibility_tests.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/web/static/tests/legacy/owl_compatibility_tests.js b/addons/web/static/tests/legacy/owl_compatibility_tests.js index bee421b312f..aa9b889f25b 100644 --- a/addons/web/static/tests/legacy/owl_compatibility_tests.js +++ b/addons/web/static/tests/legacy/owl_compatibility_tests.js @@ -326,13 +326,14 @@ odoo.define('web.OwlCompatibilityTests', function (require) { }); QUnit.test("sub widget methods are correctly called", async function (assert) { - assert.expect(5); + assert.expect(6); const MyWidget = Widget.extend({ on_attach_callback: function () { assert.step('on_attach_callback'); }, on_detach_callback: function () { + assert.ok(document.body.contains(this.el)); assert.step('on_detach_callback'); }, destroy: function () {