From c00fb3cedea4dda6f7fafdf3df44e95c9498c684 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 23 Jun 2021 07:47:09 +0000 Subject: [PATCH] [FIX] web: register template of dynamic classes once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, the template of some dynamic classes (usually as WOWL to legacyAdapters) were registered at each definition of the class which is potentially at every doAction/switchView After this commit, they are all registered only once, as early as possible. closes odoo/odoo#72476 Related: odoo/enterprise#19199 Signed-off-by: Géry Debongnie (ged) --- .../web/static/src/legacy/action_adapters.js | 4 +++- .../static/src/legacy/js/owl_compatibility.js | 20 +++++++++++-------- .../src/legacy/legacy_client_actions.js | 11 +++++----- addons/web/static/src/legacy/legacy_views.js | 13 ++++++------ .../static/src/legacy/systray_menu_item.js | 4 +++- .../src/webclient/actions/action_service.js | 15 +++++++------- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/addons/web/static/src/legacy/action_adapters.js b/addons/web/static/src/legacy/action_adapters.js index 095e299031e..bb3a1d6e2aa 100644 --- a/addons/web/static/src/legacy/action_adapters.js +++ b/addons/web/static/src/legacy/action_adapters.js @@ -13,6 +13,8 @@ import { cleanDomFromBootstrap, wrapSuccessOrFail, mapDoActionOptionAPI } from " const { Component, tags } = owl; +const warningDialogBodyTemplate = tags.xml``; + class ActionAdapter extends ComponentAdapter { setup() { super.setup(); @@ -95,7 +97,7 @@ class ActionAdapter extends ComponentAdapter { this.title = this.props.title; } } - WarningDialog.bodyTemplate = tags.xml``; + WarningDialog.bodyTemplate = warningDialogBodyTemplate; this.dialogs.add(WarningDialog, { title: payload.title, message: payload.message, diff --git a/addons/web/static/src/legacy/js/owl_compatibility.js b/addons/web/static/src/legacy/js/owl_compatibility.js index afa2cb6a653..aece0d861f3 100644 --- a/addons/web/static/src/legacy/js/owl_compatibility.js +++ b/addons/web/static/src/legacy/js/owl_compatibility.js @@ -16,6 +16,8 @@ odoo.define('web.OwlCompatibility', function () { const widgetSymbol = odoo.widgetSymbol; const children = new WeakMap(); // associates legacy widgets with their Owl children + const templateForLegacy = tags.xml`
`; + const templateForOwl = tags.xml``; /** * Case 1) An Owl component has to instantiate legacy widgets * ---------------------------------------------------------- @@ -85,15 +87,9 @@ odoo.define('web.OwlCompatibility', function () { } let template; if (!(props.Component.prototype instanceof Component)) { - template = tags.xml`
`; + template = templateForLegacy; } else { - let propsStr = ''; - for (let p in props) { - if (p !== 'Component') { - propsStr += ` ${p}="props.${p}"`; - } - } - template = tags.xml``; + template = templateForOwl; } ComponentAdapter.template = template; super(...arguments); @@ -103,6 +99,14 @@ odoo.define('web.OwlCompatibility', function () { this.widget = null; // widget instance, if Component is a legacy widget } + get childProps() { + if (!this._childProps) { + this._childProps = Object.assign({}, this.props); + delete this._childProps.Component; + } + return this._childProps; + } + /** * Starts the legacy widget (not in the DOM yet) * diff --git a/addons/web/static/src/legacy/legacy_client_actions.js b/addons/web/static/src/legacy/legacy_client_actions.js index 93f2434c68b..38d33c805a3 100644 --- a/addons/web/static/src/legacy/legacy_client_actions.js +++ b/addons/web/static/src/legacy/legacy_client_actions.js @@ -11,6 +11,11 @@ import { breadcrumbsToLegacy } from "./utils"; const { Component, hooks, tags } = owl; const actionRegistry = registry.category("actions"); +const legacyClientActionTemplate = tags.xml` + `; + // registers an action from the legacy action registry to the wowl one, ensuring // that widget actions are actually Components function registerClientAction(name, action) { @@ -44,11 +49,7 @@ function registerClientAction(name, action) { }; } } - Action.template = tags.xml` - - `; + Action.template = legacyClientActionTemplate; Action.components = { ClientActionAdapter }; Action.isLegacy = true; Action.target = action.prototype.target; diff --git a/addons/web/static/src/legacy/legacy_views.js b/addons/web/static/src/legacy/legacy_views.js index 5f7ae6962d9..e5268ae32df 100644 --- a/addons/web/static/src/legacy/legacy_views.js +++ b/addons/web/static/src/legacy/legacy_views.js @@ -18,6 +18,11 @@ function getJsClassWidget(fieldsInfo) { return legacyViewRegistry.get(key); } +const legacyViewTemplate = tags.xml` + `; + // registers a view from the legacy view registry to the wowl one, but wrapped // into an Owl Component function registerView(name, LegacyView) { @@ -106,7 +111,7 @@ function registerView(name, LegacyView) { .map(([vid, vtype]) => { const view = this.props.viewSwitcherEntries.find((v) => v.type === vtype); if (view) { - return Object.assign({}, view, {viewID: vid}); + return Object.assign({}, view, { viewID: vid }); } else { return { viewID: vid, @@ -122,12 +127,8 @@ function registerView(name, LegacyView) { }); } } + Controller.template = legacyViewTemplate; - Controller.template = tags.xml` - - `; Controller.components = { ViewAdapter }; Controller.display_name = LegacyView.prototype.display_name; Controller.icon = LegacyView.prototype.icon; diff --git a/addons/web/static/src/legacy/systray_menu_item.js b/addons/web/static/src/legacy/systray_menu_item.js index 44adf61ec56..314fbde985c 100644 --- a/addons/web/static/src/legacy/systray_menu_item.js +++ b/addons/web/static/src/legacy/systray_menu_item.js @@ -20,6 +20,8 @@ const legacySystrayMenuItems = legacySystrayMenu.Items; const convertedItems = []; let id = 1; +const legacySystrayItemTemplate = tags.xml``; + function addSystrayItem(Widget) { const name = `_legacy_systray_item_${id++}`; @@ -29,7 +31,7 @@ function addSystrayItem(Widget) { this.Widget = Widget; } } - SystrayItem.template = tags.xml``; + SystrayItem.template = legacySystrayItemTemplate; SystrayItem.components = { SystrayItemAdapter }; systrayRegistry.add(name, { Component: SystrayItem }, { sequence: Widget.prototype.sequence }); diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index 144c9173b08..dcca897e8b1 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -69,6 +69,13 @@ export class InvalidButtonParamsError extends Error {} // regex that matches context keys not to forward from an action to another const CTX_KEY_REGEX = /^(?:(?:default_|search_default_|show_).+|.+_view_ref|group_by|group_by_no_leaf|active_id|active_ids|orderedBy)$/; +// only register this template once for all dynamic classes ControllerComponent +const ControllerComponentTemplate = tags.xml``; + function makeActionManager(env) { const keepLast = new KeepLast(); let id = 0; @@ -525,13 +532,7 @@ function makeActionManager(env) { controller.title = ev.detail; } } - - ControllerComponent.template = tags.xml``; - + ControllerComponent.template = ControllerComponentTemplate; ControllerComponent.Component = controller.Component; let nextDialog = {};