mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] qweb: fix crash when component only renders empty slot
This commit is contained in:
committed by
Géry Debongnie
parent
a122a94180
commit
c718d8e6c6
@@ -18,7 +18,7 @@ function callSlot(
|
|||||||
name: string,
|
name: string,
|
||||||
defaultSlot?: (ctx: any, key: string) => BDom,
|
defaultSlot?: (ctx: any, key: string) => BDom,
|
||||||
dynamic?: boolean
|
dynamic?: boolean
|
||||||
): BDom | null {
|
): BDom {
|
||||||
const slots = ctx.__owl__.slots;
|
const slots = ctx.__owl__.slots;
|
||||||
const slotFn = slots[name];
|
const slotFn = slots[name];
|
||||||
const slotBDom = slotFn ? slotFn(parent, key) : null;
|
const slotBDom = slotFn ? slotFn(parent, key) : null;
|
||||||
@@ -33,7 +33,7 @@ function callSlot(
|
|||||||
}
|
}
|
||||||
return multi([child1, child2]);
|
return multi([child1, child2]);
|
||||||
}
|
}
|
||||||
return slotBDom;
|
return slotBDom || text("");
|
||||||
}
|
}
|
||||||
|
|
||||||
function capture(ctx: any): any {
|
function capture(ctx: any): any {
|
||||||
|
|||||||
@@ -43,6 +43,18 @@ exports[`slots can define and call slots 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`slots can render only empty 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 content is the default slot (variation) 1`] = `
|
exports[`slots content is the default slot (variation) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1332,4 +1332,19 @@ describe("slots", () => {
|
|||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<div><div><p>Ablip</p><div><p>Bblip</p></div></div></div>");
|
expect(fixture.innerHTML).toBe("<div><div><p>Ablip</p><div><p>Bblip</p></div></div></div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("can render only empty slot", async () => {
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`<t t-slot="default"/>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let error = null;
|
||||||
|
try {
|
||||||
|
await mount(Parent, fixture);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
expect(error).toBeNull();
|
||||||
|
expect(fixture.innerHTML).toEqual("");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user