[FIX] web: ComponentAdapter: detach it after unmounting

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) <aab@odoo.com>
Signed-off-by: Géry Debongnie <ged@odoo.com>
This commit is contained in:
Géry Debongnie
2023-03-28 00:05:49 +02:00
parent ee3ff4e36f
commit 94d7b2a773
@@ -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 () {