[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:
Géry Debongnie
2019-12-16 14:20:36 +01:00
committed by aab-odoo
parent d9bf4284c6
commit 9216c5c24b
5 changed files with 230 additions and 180 deletions
+10 -1
View File
@@ -383,7 +383,12 @@ export class QWeb extends EventBus {
});
}
_compile(name: string, elem: Element, parentContext?: CompilationContext): CompiledTemplate {
_compile(
name: string,
elem: Element,
parentContext?: CompilationContext,
defineKey?: boolean
): CompiledTemplate {
const isDebug = elem.attributes.hasOwnProperty("t-debug");
const ctx = new CompilationContext(name);
if (elem.tagName !== "t") {
@@ -396,6 +401,10 @@ export class QWeb extends EventBus {
ctx.hasParentWidget = true;
ctx.shouldDefineResult = false;
ctx.addLine(`let c${ctx.parentNode} = extra.parentNode;`);
if (defineKey) {
ctx.currentKey = `key${ctx.generateID()}`;
ctx.addLine(`let ${ctx.currentKey} = extra.key || '';`);
}
}
this._compileNode(elem, ctx);