[FIX] component: better templateId for multiple subcomponents

Of course, the templateId computation is kind of tricky.  Here, an issue
occurred because the templateId did not take the componentId into
account when we were in a loop, but with no keyed parent.

This meant that multiple sub components shared the same templateId,
confusing the vdom algorithm.
This commit is contained in:
Géry Debongnie
2019-09-03 16:38:24 +02:00
parent cfdce29ce7
commit 0c1a7aabae
3 changed files with 30 additions and 3 deletions
+27
View File
@@ -1373,6 +1373,33 @@ describe("composition", () => {
);
});
test("list of two sub components inside other nodes", async () => {
// this confuses the patching algorithm...
env.qweb.addTemplate("ChildWidget", `<span>child</span>`);
env.qweb.addTemplates(`
<templates>
<div t-name="Parent">
<div t-foreach="state.blips" t-as="blip" t-key="blip.id">
<SubWidget />
<SubWidget />
</div>
</div>
<span t-name="SubWidget">asdf</span>
</templates>`);
class SubWidget extends Widget {}
class Parent extends Widget {
components = { SubWidget };
state = { blips: [{ a: "a", id: 1 }] };
}
const parent = new Parent(env);
await parent.mount(fixture);
expect(fixture.innerHTML).toBe(
"<div><div><span>asdf</span><span>asdf</span></div></div>"
);
});
test("t-component with dynamic value", async () => {
env.qweb.addTemplate("ParentWidget", `<div><t t-component="{{state.widget}}"/></div>`);
class ParentWidget extends Widget {