mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] qweb: t-call properly transfer key to sub components
Since t-call is now a function call, we need to properly handle the internal key used to find previous components. If a t-call is inside a t-foreach, then we need to transfer the key to the sub template. Otherwise, each component in the subtemplate will be associated to the same key, which means that it will lead to big issues: components are destroyed and reused... closes #581
This commit is contained in:
@@ -5599,6 +5599,26 @@ describe("t-call", () => {
|
||||
expect(env.qweb.subTemplates["sub"].toString()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("t-call in t-foreach and children component", async () => {
|
||||
env.qweb.addTemplate("sub", `<Child val="val"/>`);
|
||||
class Child extends Component<any, any> {
|
||||
static template = xml`<span><t t-esc="props.val"/></span>`;
|
||||
}
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Child };
|
||||
static template = xml`
|
||||
<div>
|
||||
<t t-foreach="['a', 'b', 'c']" t-as="val" t-key="val">
|
||||
<t t-call="sub"/>
|
||||
</t>
|
||||
</div>`;
|
||||
}
|
||||
const parent = new Parent();
|
||||
await parent.mount(fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe("<div><span>a</span><span>b</span><span>c</span></div>");
|
||||
});
|
||||
|
||||
test("parent is set within t-call with no parentNode", async () => {
|
||||
env.qweb.addTemplate("sub", `<Child/>`);
|
||||
let child;
|
||||
|
||||
Reference in New Issue
Block a user