[REF] web,*: remove owl.App.validateTarget override
The motivation of this commit was to remove the override of owl that disables the validateTarget check, which we believed was necessary for the renderToString function. Fun fact: renderToString doesn't seem to need the override, as validateTarget is only called when mounting an app and when completing a fiber, which renderToString doesn't do. It was instead probably necessary for the legacy compatibily layers that have now been removed. So this commit removes the validateTarget override. This commit also simplifies the setup of the renderToString fn by lazy creating the app itself, instead of requiring the application setup to set the main app as renderToString app (e.g. main.js in web). Part of task~3508223 closes odoo/odoo#137807 Related: odoo/enterprise#48514 Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
This commit is contained in:
@@ -66,7 +66,6 @@
|
||||
'web/static/lib/luxon/luxon.js',
|
||||
'web/static/lib/owl/owl.js',
|
||||
'web/static/lib/owl/odoo_module.js',
|
||||
'web/static/src/libs/owl.js',
|
||||
'web/static/lib/jquery/jquery.js',
|
||||
'web/static/lib/jquery.ui/jquery-ui.js',
|
||||
'web/static/lib/popper/popper.js',
|
||||
|
||||
@@ -155,7 +155,6 @@
|
||||
('include', 'point_of_sale._assets_pos'),
|
||||
# dependencies of web.tests_assets (in the web tests, these come from assets_backend)
|
||||
'web/static/tests/patch_translations.js',
|
||||
'web/static/src/libs/owl.js',
|
||||
'web/static/lib/jquery/jquery.js',
|
||||
'web/static/src/legacy/js/**/*',
|
||||
('remove', 'web/static/src/legacy/js/libs/**/*'),
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
import { Chrome } from "@point_of_sale/app/pos_app";
|
||||
import { Loader } from "@point_of_sale/app/loader/loader";
|
||||
import { templates } from "@web/core/assets";
|
||||
import { App, mount, reactive, whenReady, Component } from "@odoo/owl";
|
||||
import { App, mount, reactive, whenReady } from "@odoo/owl";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { hasTouch } from "@web/core/browser/feature_detection";
|
||||
import { localization } from "@web/core/l10n/localization";
|
||||
import { renderToString } from "@web/core/utils/render";
|
||||
import { makeEnv, startServices } from "@web/env";
|
||||
import { session } from "@web/session";
|
||||
|
||||
@@ -26,17 +25,6 @@ whenReady(() => {
|
||||
isEnterprise: session.server_version_info.slice(-1)[0] === "e",
|
||||
};
|
||||
|
||||
// Make a temporary app to be able to use renderToString method before the main app is available.
|
||||
const renderToStringApp = new App(Component, {
|
||||
name: "renderToString app",
|
||||
templates,
|
||||
dev: !!odoo.debug,
|
||||
warnIfNoStaticProps: true,
|
||||
translatableAttributes: ["data-tooltip"],
|
||||
translateFn: _t,
|
||||
});
|
||||
renderToString.app = renderToStringApp;
|
||||
|
||||
// setup environment
|
||||
const env = makeEnv();
|
||||
await startServices(env);
|
||||
@@ -52,7 +40,6 @@ whenReady(() => {
|
||||
translateFn: _t,
|
||||
props: { disableLoader: () => (loader.isShown = false) },
|
||||
});
|
||||
renderToString.app = app;
|
||||
const root = await app.mount(document.body);
|
||||
const classList = document.body.classList;
|
||||
if (localization.direction === "rtl") {
|
||||
|
||||
@@ -116,7 +116,6 @@
|
||||
'web/static/lib/luxon/luxon.js',
|
||||
'web/static/lib/owl/owl.js',
|
||||
'web/static/lib/owl/odoo_module.js',
|
||||
'web/static/src/libs/owl.js',
|
||||
'web/static/lib/jquery/jquery.js',
|
||||
'web/static/lib/jquery.ui/jquery-ui.js',
|
||||
'web/static/lib/popper/popper.js',
|
||||
|
||||
@@ -200,7 +200,6 @@ This module provides the core of the Odoo Web Client.
|
||||
|
||||
'web/static/lib/owl/owl.js',
|
||||
'web/static/lib/owl/odoo_module.js',
|
||||
'web/static/src/libs/owl.js',
|
||||
'web/static/lib/jquery/jquery.js',
|
||||
'web/static/lib/jquery.ui/jquery-ui.js',
|
||||
'web/static/lib/popper/popper.js',
|
||||
@@ -363,7 +362,6 @@ This module provides the core of the Odoo Web Client.
|
||||
# libs
|
||||
'web/static/lib/luxon/luxon.js',
|
||||
'web/static/lib/owl/owl.js',
|
||||
'web/static/src/libs/owl.js',
|
||||
'web/static/lib/owl/odoo_module.js',
|
||||
# core
|
||||
'web/static/src/env.js',
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { blockDom, markup } from "@odoo/owl";
|
||||
import { App, blockDom, Component, markup } from "@odoo/owl";
|
||||
import { templates } from "@web/core/assets";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
|
||||
export function renderToElement(template, context = {}) {
|
||||
const el = render(template, context).firstElementChild;
|
||||
if (el?.nextElementSibling) {
|
||||
throw new Error(
|
||||
`The rendered template '${template}' contains multiple root ` +
|
||||
`nodes that will be ignored using renderToElement, you should ` +
|
||||
`consider using renderToFragment or refactoring the template.`
|
||||
`nodes that will be ignored using renderToElement, you should ` +
|
||||
`consider using renderToFragment or refactoring the template.`
|
||||
);
|
||||
}
|
||||
el?.remove();
|
||||
@@ -33,12 +35,23 @@ export function renderToFragment(template, context = {}) {
|
||||
export function renderToString(template, context = {}) {
|
||||
return render(template, context).innerHTML;
|
||||
}
|
||||
let app;
|
||||
Object.defineProperty(renderToString, "app", {
|
||||
get: () => {
|
||||
if (!app) {
|
||||
app = new App(Component, {
|
||||
name: "renderToString",
|
||||
templates,
|
||||
translatableAttributes: ["data-tooltip"],
|
||||
translateFn: _t,
|
||||
});
|
||||
}
|
||||
return app;
|
||||
},
|
||||
});
|
||||
|
||||
function render(template, context = {}) {
|
||||
const app = renderToString.app;
|
||||
if (!app) {
|
||||
throw new Error("an app must be configured before using renderToString");
|
||||
}
|
||||
const templateFn = app.getTemplate(template);
|
||||
const bdom = templateFn(context, {});
|
||||
const div = document.createElement("div");
|
||||
|
||||
@@ -18,7 +18,6 @@ import { makeEnv, startServices } from "@web/env";
|
||||
import { loadJS, templates } from '@web/core/assets';
|
||||
import { MainComponentsContainer } from "@web/core/main_components_container";
|
||||
import { browser } from '@web/core/browser/browser';
|
||||
import { renderToString } from "@web/core/utils/render";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { App, Component, whenReady } from "@odoo/owl";
|
||||
|
||||
@@ -341,7 +340,6 @@ export async function createPublicRoot(RootWidget) {
|
||||
translateFn: _t,
|
||||
translatableAttributes: ["data-tooltip"],
|
||||
});
|
||||
renderToString.app = app;
|
||||
const language = lang || browser.navigator.language;
|
||||
const locale = language === "sr@latin" ? "sr-Latn-RS" : language.replace(/_/g, "-");
|
||||
Settings.defaultLocale = locale;
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
/* eslint-disable no-undef */
|
||||
owl.App.validateTarget = () => {};
|
||||
@@ -5,7 +5,6 @@ import { legacySetupProm } from "./legacy/legacy_setup";
|
||||
import { mapLegacyEnvToWowlEnv } from "./legacy/utils";
|
||||
import { localization } from "@web/core/l10n/localization";
|
||||
import { session } from "@web/session";
|
||||
import { renderToString } from "./core/utils/render";
|
||||
import { templates } from "@web/core/assets";
|
||||
import { hasTouch } from "@web/core/browser/feature_detection";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
@@ -45,7 +44,6 @@ export async function startWebClient(Webclient) {
|
||||
translatableAttributes: ["data-tooltip"],
|
||||
translateFn: _t,
|
||||
});
|
||||
renderToString.app = app;
|
||||
const root = await app.mount(document.body);
|
||||
const classList = document.body.classList;
|
||||
if (localization.direction === "rtl") {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import Bus from "@web/legacy/js/core/bus";
|
||||
import { templates } from "@web/core/assets";
|
||||
import { renderToString } from "@web/core/utils/render";
|
||||
import { App, Component } from "@odoo/owl";
|
||||
|
||||
let app;
|
||||
@@ -19,7 +18,6 @@
|
||||
function makeTestEnvironment(env = {}, providedRPC = null) {
|
||||
if (!app) {
|
||||
app = new App(null, { templates, test: true });
|
||||
renderToString.app = app;
|
||||
}
|
||||
|
||||
function rpc(route, params, options) {
|
||||
|
||||
@@ -55,7 +55,6 @@ Odoo Web Editor widget.
|
||||
'web/static/lib/luxon/luxon.js',
|
||||
'web/static/lib/owl/owl.js',
|
||||
'web/static/lib/owl/odoo_module.js',
|
||||
'web/static/src/libs/owl.js',
|
||||
'web/static/lib/jquery/jquery.js',
|
||||
'web/static/lib/jquery.ui/jquery-ui.js',
|
||||
'web/static/lib/popper/popper.js',
|
||||
|
||||
@@ -155,7 +155,6 @@ Featuring
|
||||
'web/static/lib/luxon/luxon.js',
|
||||
'web/static/lib/owl/owl.js',
|
||||
'web/static/lib/owl/odoo_module.js',
|
||||
'web/static/src/libs/owl.js',
|
||||
'web/static/lib/jquery/jquery.js',
|
||||
'web/static/lib/jquery.ui/jquery-ui.js',
|
||||
'web/static/lib/popper/popper.js',
|
||||
|
||||
Reference in New Issue
Block a user