mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] compiler: fix t-call at root of template causing crashes
Because the default content of a t-call is compiled before the block of the t-call is created, the default content can sometimes incorrectly be treated as though it is at the root of the template. This causes various issues, in the case of a t-if, the default content will just replace the t-call entirely when truthy, and when falsy the template will not return anything, leading to a crash. Similar things occur with t-foreach and t-out with a default content. This commit fixes that by moving the block creation for the t-call ahead of the compilation of the default content. In doing so, it makes the context attribute "preventRoot" obsolete: the purpose of this attribute is to somehow make the code aware that the root of the template will be defined later, but because it wasn't propagated everywhere properly it caused this issue. Now that the root already exists before we compile the default content, we don't need it anymore.
This commit is contained in:
committed by
Lucas Perais - lpe@odoo
parent
28672096a2
commit
ba34811f71
@@ -430,6 +430,48 @@ describe("t-call (template calling)", () => {
|
||||
expect(context.renderToString("main")).toBe(expected);
|
||||
});
|
||||
|
||||
test("root t-call with body: t-if true", () => {
|
||||
const context = new TestContext();
|
||||
const subTemplate = `sub`;
|
||||
const main = `<t t-call="subTemplate"><t t-if="true">zero</t></t>`;
|
||||
context.addTemplate("subTemplate", subTemplate);
|
||||
context.addTemplate("main", main);
|
||||
const expected = "sub";
|
||||
expect(context.renderToString("main")).toBe(expected);
|
||||
});
|
||||
|
||||
test("root t-call with body: t-if false", () => {
|
||||
const context = new TestContext();
|
||||
const subTemplate = `sub`;
|
||||
const main = `<t t-call="subTemplate"><t t-if="false">zero</t></t>`;
|
||||
context.addTemplate("subTemplate", subTemplate);
|
||||
context.addTemplate("main", main);
|
||||
const expected = "sub";
|
||||
expect(context.renderToString("main")).toBe(expected);
|
||||
});
|
||||
|
||||
test("root t-call with body: t-out with default", () => {
|
||||
const context = new TestContext();
|
||||
const subTemplate = `sub`;
|
||||
const main = `<t t-call="subTemplate"><t t-out="nothing">default</t></t>`;
|
||||
context.addTemplate("subTemplate", subTemplate);
|
||||
context.addTemplate("main", main);
|
||||
const expected = "sub";
|
||||
expect(context.renderToString("main")).toBe(expected);
|
||||
});
|
||||
|
||||
test("root t-call with body: t-foreach", () => {
|
||||
const context = new TestContext();
|
||||
const subTemplate = `sub`;
|
||||
const main = `<t t-call="subTemplate">
|
||||
<t t-foreach="[1]" t-as="i" t-key="i">1</t>
|
||||
</t>`;
|
||||
context.addTemplate("subTemplate", subTemplate);
|
||||
context.addTemplate("main", main);
|
||||
const expected = "sub";
|
||||
expect(context.renderToString("main")).toBe(expected);
|
||||
});
|
||||
|
||||
test("dynamic t-call", () => {
|
||||
const context = new TestContext();
|
||||
const foo = `<foo><t t-esc="val"/></foo>`;
|
||||
|
||||
Reference in New Issue
Block a user