mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] qweb: fix order of lookup in t-component directive
Previously, the order of resolution was: - components defined on the class of the current component - components defined on the QWeb instance - the current instance's context This is unnatural because it doesn't go from most specific to least, as the current instance's context is the most specific. This is also fragile, as adding components to the QWeb instance can break unrelated components. This commit fixes that by making the lookup start with the current component's context instead
This commit is contained in:
committed by
Géry Debongnie
parent
7dfa901332
commit
e646eb697e
@@ -1242,6 +1242,23 @@ describe("composition", () => {
|
||||
delete QWeb.components["WidgetB"];
|
||||
});
|
||||
|
||||
test("don't fallback to global/component's registry if widget defined in the instance's context", async () => {
|
||||
QWeb.registerComponent("WidgetB", WidgetB); // should not use this widget
|
||||
env.qweb.addTemplate("ParentWidget", `<div><t t-component="WidgetB"/></div>`);
|
||||
env.qweb.addTemplate("ComponentWidgetB", `<span>Belgium</span>`); // should not use this widget either
|
||||
env.qweb.addTemplate("InstanceWidgetB", `<span>Chocolate</span>`); // should use this
|
||||
class ComponentWidgetB extends Component {}
|
||||
class InstanceWidgetB extends Component {}
|
||||
class ParentWidget extends Component {
|
||||
static components = { WidgetB: ComponentWidgetB };
|
||||
WidgetB = InstanceWidgetB;
|
||||
}
|
||||
const widget = new ParentWidget();
|
||||
await widget.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("<div><span>Chocolate</span></div>");
|
||||
delete QWeb.components["WidgetB"];
|
||||
});
|
||||
|
||||
test("can define components in template without t-component", async () => {
|
||||
env.qweb.addTemplates(`
|
||||
<templates>
|
||||
|
||||
Reference in New Issue
Block a user