mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] runtime: do not check template equality outside dev mode
When defining a template with a name that the template set already contains, we currently always check whether the template is the same and throw an error when it's not. This is potentially expensive as it can involve serializing a pretty large XML document. This check is only supposed to help during development so this commit disables this check outside dev mode.
This commit is contained in:
committed by
Bruno Boi
parent
610ed02373
commit
c78e070636
@@ -66,6 +66,10 @@ export class TemplateSet {
|
||||
|
||||
addTemplate(name: string, template: string | Element) {
|
||||
if (name in this.rawTemplates) {
|
||||
// this check can be expensive, just silently ignore double definitions outside dev mode
|
||||
if (!this.dev) {
|
||||
return;
|
||||
}
|
||||
const rawTemplate = this.rawTemplates[name];
|
||||
const currentAsString =
|
||||
typeof rawTemplate === "string"
|
||||
|
||||
@@ -11,8 +11,8 @@ describe("basic validation", () => {
|
||||
expect(() => context.getTemplate("invalidname")).toThrow("Missing template");
|
||||
});
|
||||
|
||||
test("cannot add a different template with the same name", () => {
|
||||
const context = new TemplateSet();
|
||||
test("cannot add a different template with the same name in dev mode", () => {
|
||||
const context = new TemplateSet({ dev: true });
|
||||
context.addTemplate("test", `<t/>`);
|
||||
// Same template with the same name is fine
|
||||
expect(() => context.addTemplate("test", "<t/>")).not.toThrow();
|
||||
@@ -20,6 +20,13 @@ describe("basic validation", () => {
|
||||
expect(() => context.addTemplate("test", "<div/>")).toThrow("already defined");
|
||||
});
|
||||
|
||||
test("adding different template with same name outside dev mode silently ignores it", () => {
|
||||
const context = new TemplateSet({ dev: false });
|
||||
context.addTemplate("test", `<t/>`);
|
||||
expect(() => context.addTemplate("test", "<div/>")).not.toThrow();
|
||||
expect(context.rawTemplates.test).toBe("<t/>");
|
||||
});
|
||||
|
||||
test("invalid xml", () => {
|
||||
const template = "<div>";
|
||||
expect(() => snapshotTemplate(template)).toThrow("Invalid XML in template");
|
||||
|
||||
Reference in New Issue
Block a user