mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] qweb: properly handle subtemplates in shared templates
With QWeb, we can register globally templates (using the xml tag or the registerTemplate function). However, these templates, once compiled, can generate sub template compiled functions. Before this commit, these sub functions were local to a specific instance. This means that creating a new QWeb instance and rendering a global parent template would crash, since it was unable to find the actual sub function. This commit fixes the issue: the sub functions are now shared statically, but with a unique ID, so we do not have issues with sub functions having a same name in different QWeb instance. closes #701
This commit is contained in:
@@ -1253,7 +1253,7 @@ exports[`other directives with t-component t-set can't alter from within callee
|
||||
if (scope.iter != null) {
|
||||
c2.push({text: scope.iter});
|
||||
}
|
||||
this.subTemplates['ChildWidget'].call(this, Object.assign(Object.create(context), scope), Object.assign({}, extra, {parentNode: c1, parent: utils.getComponent(context), key: '__4__'}));
|
||||
this.constructor.subTemplates['2'].call(this, Object.assign(Object.create(context), scope), Object.assign({}, extra, {parentNode: c1, parent: utils.getComponent(context), key: '__4__'}));
|
||||
let c5 = [], p5 = {key:5};
|
||||
let vn5 = h('p', p5, c5);
|
||||
c1.push(vn5);
|
||||
@@ -1289,7 +1289,7 @@ exports[`other directives with t-component t-set can't alter in t-call body 1`]
|
||||
utils.getScope(scope, 'iter').iter = 'inCall';
|
||||
scope[utils.zero] = c__0;
|
||||
}
|
||||
this.subTemplates['ChildWidget'].call(this, scope, Object.assign({}, extra, {parentNode: c1, parent: utils.getComponent(context), key: '__5__'}));
|
||||
this.constructor.subTemplates['2'].call(this, scope, Object.assign({}, extra, {parentNode: c1, parent: utils.getComponent(context), key: '__5__'}));
|
||||
scope = _origScope4;
|
||||
}
|
||||
let c6 = [], p6 = {key:6};
|
||||
@@ -1410,7 +1410,7 @@ exports[`random stuff/miscellaneous can inject values in tagged templates 1`] =
|
||||
let h = this.h;
|
||||
let c1 = [], p1 = {key:1};
|
||||
let vn1 = h('div', p1, c1);
|
||||
this.subTemplates['__template__1'].call(this, Object.assign(Object.create(context), scope), Object.assign({}, extra, {parentNode: c1, parent: utils.getComponent(context), key: '__4__'}));
|
||||
this.constructor.subTemplates['3'].call(this, Object.assign(Object.create(context), scope), Object.assign({}, extra, {parentNode: c1, parent: utils.getComponent(context), key: '__4__'}));
|
||||
return vn1;
|
||||
}"
|
||||
`;
|
||||
|
||||
@@ -3825,7 +3825,9 @@ describe("t-call", () => {
|
||||
|
||||
expect(fixture.innerHTML).toBe("<div><p>lucas</p></div>");
|
||||
fixture.querySelector("p")!.click();
|
||||
expect(env.qweb.subTemplates["sub"].toString()).toMatchSnapshot();
|
||||
const subId = env.qweb.subTemplates["sub"];
|
||||
const subFn = QWeb.subTemplates[subId] as any;
|
||||
expect(subFn.toString()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("parent is set within t-call", async () => {
|
||||
@@ -3847,7 +3849,10 @@ describe("t-call", () => {
|
||||
|
||||
expect(fixture.innerHTML).toBe("<div><span>lucas</span></div>");
|
||||
expect(child.__owl__.parent).toBe(parent);
|
||||
expect(env.qweb.subTemplates["sub"].toString()).toMatchSnapshot();
|
||||
const subId = env.qweb.subTemplates["sub"];
|
||||
const subFn = QWeb.subTemplates[subId] as any;
|
||||
|
||||
expect(subFn.toString()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("t-call in t-foreach and children component", async () => {
|
||||
@@ -3889,7 +3894,9 @@ describe("t-call", () => {
|
||||
|
||||
expect(fixture.innerHTML).toBe("<span>lucas</span>");
|
||||
expect(child.__owl__.parent).toBe(parent);
|
||||
expect(env.qweb.subTemplates["sub"].toString()).toMatchSnapshot();
|
||||
const subId = env.qweb.subTemplates["sub"];
|
||||
const subFn = QWeb.subTemplates[subId] as any;
|
||||
expect(subFn.toString()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("handlers with arguments are properly bound through a t-call", async () => {
|
||||
@@ -3905,7 +3912,9 @@ describe("t-call", () => {
|
||||
}
|
||||
const parent = new Parent();
|
||||
await parent.mount(fixture);
|
||||
expect(env.qweb.subTemplates["sub"].toString()).toMatchSnapshot();
|
||||
const subId = env.qweb.subTemplates["sub"];
|
||||
const subFn = QWeb.subTemplates[subId] as any;
|
||||
expect(subFn.toString()).toMatchSnapshot();
|
||||
|
||||
fixture.querySelector("p")!.click();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user