mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] component: propagate correct info when reusing fibers
In some cases, a rendering initiated in some component is then remapped into a larger rendering initiated by some parent. If we have some components which implement shouldUpdate to return false, then the following scenario can happen: - some parent component is mounted (which triggers a rendering with force: true => bypass the shouldUpdate) - some sub component is updated and rerendered, AFTER the previous rendering goes through it - the sub component notices that there is an ongoing rendering, and remaps itself in the parent rendering Before this commit, the new fiber in the subcomponent does not have force flag set to true, so the new rendering for the subcomponent does not go through its own children (if they have shouldUpdate=false) Another more complex kind of scenaria can happen when a remapped rendering happen with sub components with dynamic shouldUpdate. The problem is the same at the end: the new rendering should ignore the shouldUpdate, to make sure we have the last correct information. With this commit, we make sure that the flag of the new fiber is set to true. closes #818
This commit is contained in:
@@ -1405,4 +1405,160 @@ describe("async rendering", () => {
|
||||
expect(fixture.innerHTML).toBe("<div>2</div>");
|
||||
expect(Widget.prototype.__render).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
test("components with shouldUpdate=false", async () => {
|
||||
const state = { p: 1, cc: 10 };
|
||||
|
||||
class ChildChild extends Component {
|
||||
static template = xml`
|
||||
<div>
|
||||
child child: <t t-esc="state.cc"/>
|
||||
</div>`;
|
||||
state = state;
|
||||
shouldUpdate() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class Child extends Component {
|
||||
static components = { ChildChild };
|
||||
static template = xml`
|
||||
<div>
|
||||
child
|
||||
<ChildChild/>
|
||||
</div>`;
|
||||
|
||||
shouldUpdate() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let parent: any;
|
||||
class Parent extends Component {
|
||||
static components = { Child };
|
||||
static template = xml`
|
||||
<div>
|
||||
parent: <t t-esc="state.p"/>
|
||||
<Child/>
|
||||
</div>`;
|
||||
|
||||
state = state;
|
||||
constructor(a, b) {
|
||||
super(a, b);
|
||||
parent = this;
|
||||
}
|
||||
shouldUpdate() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class App extends Component {
|
||||
static components = { Parent };
|
||||
static template = xml`
|
||||
<div>
|
||||
<Parent/>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
var div = document.createElement("div");
|
||||
fixture.appendChild(div);
|
||||
|
||||
const app = new App();
|
||||
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div></div><div><div> parent: 1<div> child <div> child child: 10</div></div></div></div>"
|
||||
);
|
||||
app.mount(div);
|
||||
|
||||
// wait for rendering from second mount to go through parent
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
state.cc++;
|
||||
state.p++;
|
||||
parent.render();
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div><div> parent: 2<div> child <div> child child: 11</div></div></div></div></div>"
|
||||
);
|
||||
});
|
||||
|
||||
test("components with shouldUpdate=false, part 2", async () => {
|
||||
const state = { p: 1, cc: 10 };
|
||||
let shouldUpdate = true;
|
||||
|
||||
class ChildChild extends Component {
|
||||
static template = xml`
|
||||
<div>
|
||||
child child: <t t-esc="state.cc"/>
|
||||
</div>`;
|
||||
state = state;
|
||||
shouldUpdate() {
|
||||
return shouldUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
class Child extends Component {
|
||||
static components = { ChildChild };
|
||||
static template = xml`
|
||||
<div>
|
||||
child
|
||||
<ChildChild/>
|
||||
</div>`;
|
||||
|
||||
shouldUpdate() {
|
||||
return shouldUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
let parent: any;
|
||||
class Parent extends Component {
|
||||
static components = { Child };
|
||||
static template = xml`
|
||||
<div>
|
||||
parent: <t t-esc="state.p"/>
|
||||
<Child/>
|
||||
</div>`;
|
||||
|
||||
state = state;
|
||||
constructor(a, b) {
|
||||
super(a, b);
|
||||
parent = this;
|
||||
}
|
||||
shouldUpdate() {
|
||||
return shouldUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
class App extends Component {
|
||||
static components = { Parent };
|
||||
static template = xml`
|
||||
<div>
|
||||
<Parent/>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
const app = new App();
|
||||
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div> parent: 1<div> child <div> child child: 10</div></div></div></div>"
|
||||
);
|
||||
|
||||
state.cc++;
|
||||
state.p++;
|
||||
app.render();
|
||||
|
||||
// wait for rendering to go through child
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
|
||||
shouldUpdate = false;
|
||||
parent.render();
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div> parent: 2<div> child <div> child child: 11</div></div></div></div>"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user