From c032acbceab7252318234eb7dbc9604bfa19ce2f Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Thu, 28 Apr 2022 12:29:34 +0000 Subject: [PATCH] [FIX] web: set componentRef in onRendered instead of onPatched Previously, we were setting the ref to a component on ComponentWrapper inside the onPatched hook, however, when mounting a component outside the document (eg in a fragment) the patched hook is not supposed to be called, but we need the ref to be set. This commit fixes the issue by setting the componentRef in onRendered so that it's available even when the component is mounted in a fragment. closes odoo/odoo#90375 X-original-commit: 3013d89bcfe04be0207932b237d0e8ff8fb1d52b Signed-off-by: Aaron Bohy (aab) --- .../static/src/legacy/js/owl_compatibility.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/addons/web/static/src/legacy/js/owl_compatibility.js b/addons/web/static/src/legacy/js/owl_compatibility.js index cd9eb32836e..809f81c6446 100644 --- a/addons/web/static/src/legacy/js/owl_compatibility.js +++ b/addons/web/static/src/legacy/js/owl_compatibility.js @@ -483,12 +483,9 @@ odoo.define('web.OwlCompatibility', function (require) { */ class ProxyComponent extends LegacyComponent { setup() { - onMounted(() => { - this.props.mounted(); - }); - onPatched(() => { - this.props.patched(); - }); + for (const [hookName, cb] of Object.entries(this.props.hooks)) { + owl[hookName](cb); + } onWillUnmount(() => { // The current el will be change if we remount after unmounting this._handledEvents = new Set(); @@ -559,8 +556,7 @@ odoo.define('web.OwlCompatibility', function (require) { } _makeOwlNode() { - const onPatched = () => { - this.componentRef.comp = Object.values(this.node.children)[0].component; + const resolveRender = () => { if (this.renderResolve) { this.renderResolve(); } @@ -568,8 +564,13 @@ odoo.define('web.OwlCompatibility', function (require) { const props = { props: this.props, - mounted: onPatched, - patched: onPatched, + hooks: { + onMounted: resolveRender, + onPatched: resolveRender, + onRendered: () => { + this.componentRef.comp = Object.values(this.node.children)[0].component; + }, + }, Component: this.Component, parentWidget: this.parentWidget, };