mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] compiler, component: handle change of t-key before patch
Have a dynamic children with a t-key. This child has a delayed willStart. Change the key during a rendering. Before this commit there was a leak: a component corresponding to an old key had been created, xwithout being destroyed. After this commit, the outdated component is destroyed.
This commit is contained in:
@@ -2907,6 +2907,64 @@ test("two sequential renderings before an animation frame", async () => {
|
||||
// we check here that the willPatch and patched hooks are called only once
|
||||
expect(["Parent:willPatch", "Child:willPatch", "Child:patched", "Parent:patched"]).toBeLogged();
|
||||
});
|
||||
|
||||
test("t-key on dynamic async component (toggler is never patched)", async () => {
|
||||
let def: any;
|
||||
class Child extends Component {
|
||||
static template = xml`<div t-esc="props.key" />`;
|
||||
setup() {
|
||||
onWillStart(() => def);
|
||||
useLogLifecycle(this.props.key);
|
||||
}
|
||||
}
|
||||
|
||||
class Parent extends Component {
|
||||
key = 1;
|
||||
myComp = Child;
|
||||
static template = xml`<t t-component="myComp" t-key="key" key="key" />`;
|
||||
}
|
||||
|
||||
const parent = await mount(Parent, fixture);
|
||||
expect(fixture.innerHTML).toBe("<div>1</div>");
|
||||
|
||||
def = makeDeferred();
|
||||
parent.key = 2;
|
||||
parent.render();
|
||||
|
||||
await nextTick();
|
||||
expect([
|
||||
"Child (1):setup",
|
||||
"Child (1):willStart",
|
||||
"Child (1):willRender",
|
||||
"Child (1):rendered",
|
||||
"Child (1):mounted",
|
||||
"Child (2):setup",
|
||||
"Child (2):willStart",
|
||||
]).toBeLogged();
|
||||
expect(fixture.innerHTML).toBe("<div>1</div>");
|
||||
parent.key = 3;
|
||||
parent.render();
|
||||
|
||||
const prevDef = def;
|
||||
def = undefined;
|
||||
|
||||
parent.key = 3;
|
||||
parent.render();
|
||||
prevDef.resolve();
|
||||
await nextTick();
|
||||
|
||||
expect(fixture.innerHTML).toBe("<div>3</div>");
|
||||
expect([
|
||||
"Child (2):willDestroy",
|
||||
"Child (3):setup",
|
||||
"Child (3):willStart",
|
||||
"Child (3):willRender",
|
||||
"Child (3):rendered",
|
||||
"Child (1):willUnmount",
|
||||
"Child (1):willDestroy",
|
||||
"Child (3):mounted",
|
||||
]).toBeLogged();
|
||||
});
|
||||
// test.skip("components with shouldUpdate=false", async () => {
|
||||
// const state = { p: 1, cc: 10 };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user