[FIX] qweb: fix crash with ref an component in same slot

This commit is contained in:
Samuel Degueldre
2021-11-10 09:13:17 +01:00
committed by Géry Debongnie
parent c718d8e6c6
commit 3e70b17da1
4 changed files with 55 additions and 2 deletions
@@ -41,7 +41,7 @@ exports[`refs refs are properly bound in slots 2`] = `
let block1 = createBlock(\`<div><span class=\\"counter\\"><block-text-0/></span><block-child-0/></div>\`);
let block2 = createBlock(\`<button block-handler-0=\\"click\\" block-ref=\\"1\\">do something</button>\`);
const slot3 = ctx => node => {
const slot3 = ctx => (node, key) => {
const refs = ctx.__owl__.refs
let d2 = [ctx, 'doSomething'];
let d3 = (el) => refs[\`myButton\`] = el;
@@ -43,6 +43,42 @@ exports[`slots can define and call slots 2`] = `
}"
`;
exports[`slots can render node with t-ref and Component in same slot 1`] = `
"function anonymous(bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, component } = bdom;
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
return function template(ctx, node, key = \\"\\") {
return callSlot(ctx, node, key, 'default');
}
}"
`;
exports[`slots can render node with t-ref and Component in same slot 2`] = `
"function anonymous(bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, component } = bdom;
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
let assign = Object.assign;
let block2 = createBlock(\`<div block-ref=\\"0\\"/>\`);
const slot2 = ctx => (node, key) => {
const refs = ctx.__owl__.refs
let d1 = (el) => refs[\`div\`] = el;
let b2 = block2([d1]);
let b3 = component(\`Child\`, {}, key + \`__3\`, node, ctx);
return multi([b2, b3]);
}
return function template(ctx, node, key = \\"\\") {
const refs = ctx.__owl__.refs;
return assign(component(\`Child\`, {}, key + \`__1\`, node, ctx), {slots: {'default': slot2(ctx)}});
}
}"
`;
exports[`slots can render only empty slot 1`] = `
"function anonymous(bdom, helpers
) {
+18
View File
@@ -1347,4 +1347,22 @@ describe("slots", () => {
expect(error).toBeNull();
expect(fixture.innerHTML).toEqual("");
});
test("can render node with t-ref and Component in same slot", async () => {
class Child extends Component {
static template = xml`<t t-slot="default"/>`;
}
class Parent extends Component {
static template = xml`<Child><div t-ref="div"/><Child/></Child>`;
static components = { Child };
}
let error = null;
try {
await mount(Parent, fixture);
} catch (e) {
error = e;
}
expect(error).toBeNull();
});
});