mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] component: properly handle mounting a destroyed component
part of #685
This commit is contained in:
@@ -316,6 +316,9 @@ export class Component<Props extends {} = any, T extends Env = Env> {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (__owl__.isDestroyed) {
|
||||||
|
throw new Error("Cannot mount a destroyed component");
|
||||||
|
}
|
||||||
if (__owl__.currentFiber) {
|
if (__owl__.currentFiber) {
|
||||||
const currentFiber = __owl__.currentFiber;
|
const currentFiber = __owl__.currentFiber;
|
||||||
if (currentFiber.target === target && currentFiber.position === position) {
|
if (currentFiber.target === target && currentFiber.position === position) {
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import { Component, Env } from "../../src/component/component";
|
import { Component, Env } from "../../src/component/component";
|
||||||
|
import { EventBus } from "../../src/core/event_bus";
|
||||||
|
import { useRef, useState } from "../../src/hooks";
|
||||||
import { QWeb } from "../../src/qweb/qweb";
|
import { QWeb } from "../../src/qweb/qweb";
|
||||||
import { xml } from "../../src/tags";
|
import { xml } from "../../src/tags";
|
||||||
import { useState, useRef } from "../../src/hooks";
|
|
||||||
import { EventBus } from "../../src/core/event_bus";
|
|
||||||
import {
|
import {
|
||||||
|
editInput,
|
||||||
makeDeferred,
|
makeDeferred,
|
||||||
makeTestFixture,
|
|
||||||
makeTestEnv,
|
makeTestEnv,
|
||||||
|
makeTestFixture,
|
||||||
nextMicroTick,
|
nextMicroTick,
|
||||||
nextTick,
|
nextTick,
|
||||||
normalize,
|
normalize,
|
||||||
editInput,
|
|
||||||
} from "../helpers";
|
} from "../helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Component, Env } from "../../src/component/component";
|
|||||||
import { useState } from "../../src/hooks";
|
import { useState } from "../../src/hooks";
|
||||||
import { xml } from "../../src/tags";
|
import { xml } from "../../src/tags";
|
||||||
import { makeDeferred, makeTestEnv, makeTestFixture, nextTick, nextMicroTick } from "../helpers";
|
import { makeDeferred, makeTestEnv, makeTestFixture, nextTick, nextMicroTick } from "../helpers";
|
||||||
|
import { scheduler } from "../../src/component/scheduler";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Setup and helpers
|
// Setup and helpers
|
||||||
@@ -490,4 +491,22 @@ describe("unmounting and remounting", () => {
|
|||||||
expect(steps).toEqual(["1 resolved", "2 resolved"]);
|
expect(steps).toEqual(["1 resolved", "2 resolved"]);
|
||||||
expect(fixture.innerHTML).toBe("<div>Hey</div>");
|
expect(fixture.innerHTML).toBe("<div>Hey</div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("mounting a destroyed widget", async () => {
|
||||||
|
class MyWidget extends Component {
|
||||||
|
static template = xml`<div>Hey</div>`;
|
||||||
|
}
|
||||||
|
const w = new MyWidget();
|
||||||
|
w.destroy(); // because, why not
|
||||||
|
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
await w.mount(fixture);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
expect(scheduler.tasks.length).toBe(0);
|
||||||
|
expect(error).toBeDefined();
|
||||||
|
expect(error.message).toBe("Cannot mount a destroyed component");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user