[FIX] component: prevent rendering if not mounted

This commit is contained in:
Géry Debongnie
2019-05-06 13:45:50 +02:00
parent dfab8c7333
commit 91896942dd
2 changed files with 13 additions and 2 deletions
+1 -1
View File
@@ -238,7 +238,7 @@ export class Component<
}
async render(force: boolean = false, patchQueue?: any[]): Promise<void> {
if (this.__owl__.isDestroyed) {
if (!this.__owl__.isMounted) {
return;
}
const shouldCallPatchHooks: boolean = !patchQueue;
+12 -1
View File
@@ -87,6 +87,16 @@ describe("basic widget properties", () => {
});
test("can be clicked on and updated", async () => {
const counter = new Counter(env);
await counter.mount(fixture);
expect(fixture.innerHTML).toBe("<div>0<button>Inc</button></div>");
const button = (<HTMLElement>counter.el).getElementsByTagName("button")[0];
await button.click();
await nextTick();
expect(fixture.innerHTML).toBe("<div>1<button>Inc</button></div>");
});
test("cannot be clicked on and updated if not in DOM", async () => {
const counter = new Counter(env);
const target = document.createElement("div");
await counter.mount(target);
@@ -94,7 +104,8 @@ describe("basic widget properties", () => {
const button = (<HTMLElement>counter.el).getElementsByTagName("button")[0];
await button.click();
await nextTick();
expect(target.innerHTML).toBe("<div>1<button>Inc</button></div>");
expect(target.innerHTML).toBe("<div>0<button>Inc</button></div>");
expect(counter.state.counter).toBe(1);
});
test("widget style and classname", async () => {