mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[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:
@@ -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}`);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user