mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] crash when rendering component before mounting
This commit makes sure that Owl does not crash when a component is created, then updated (for example, with a (observed) state change), and then, some moment later, mounted. The initial render is not useful, because it is not linked to a mounting action anyway. And it caused issues such as a crash when Owl tried to patch it to a non existing target
This commit is contained in:
@@ -338,6 +338,22 @@ describe("unmounting and remounting", () => {
|
||||
expect(detachedDiv.innerHTML).toBe("<div>2</div>");
|
||||
});
|
||||
|
||||
test("change state and render while not mounted ", async () => {
|
||||
class App extends Component {
|
||||
static template = xml`<div><t t-esc="state.val"/></div>`;
|
||||
state = useState({ val: 1 });
|
||||
}
|
||||
|
||||
const app = new App(null);
|
||||
|
||||
app.state.val = 2; // will call the render method (before being mounted)
|
||||
await nextTick();
|
||||
|
||||
await app.mount(fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe("<div>2</div>");
|
||||
});
|
||||
|
||||
test("destroy and change state after mounted in detached dom", async () => {
|
||||
class App extends Component {
|
||||
static template = xml`<div><t t-esc="state.val"/></div>`;
|
||||
|
||||
Reference in New Issue
Block a user