[FIX] component: fix scoping issue in nested loops

The templates contained in a slot have to be rendered with the current
scope, but during the rendering of the sub component, which happens
later (after the willStart for the sub component). Therefore, we need to
save the scope that should be used for the slots, so we can access the
proper variables. This was done using an Object.assign() statement,
which is actually only a shallowclone for the own properties.

In this commit, we properly copy all the properties for the current
scope, even those contained in the prototype.

closes #855
This commit is contained in:
Géry Debongnie
2021-07-03 11:18:41 +02:00
committed by aab-odoo
parent 1b513a1637
commit caf842c482
5 changed files with 172 additions and 13 deletions
+1 -1
View File
@@ -355,7 +355,7 @@ QWeb.addDirective({
// SLOTS
const hasSlots = node.childNodes.length;
let scope = hasSlots ? `Object.assign(Object.create(context), scope)` : "undefined";
let scope = hasSlots ? `utils.combine(context, scope)` : "undefined";
ctx.addIf(`w${componentID}`);
+7
View File
@@ -126,6 +126,13 @@ const UTILS: Utils = {
}
return expr;
},
combine(context, scope) {
const clone = Object.create(context);
for (let k in scope) {
clone[k] = scope[k];
}
return clone;
},
shallowEqual,
addNameSpace(vnode) {
addNS(vnode.data, vnode.children, vnode.sel);