diff --git a/src/component/component.ts b/src/component/component.ts index bd2bcd2a..8a7521b6 100644 --- a/src/component/component.ts +++ b/src/component/component.ts @@ -496,9 +496,9 @@ export class Component { } this.willUnmount(); __owl__.isMounted = false; - if (this.__owl__.currentFiber) { - this.__owl__.currentFiber.isCompleted = true; - this.__owl__.currentFiber.root.counter = 0; + if (__owl__.currentFiber) { + __owl__.currentFiber.isCompleted = true; + __owl__.currentFiber.root.counter = 0; } const children = __owl__.children; for (let id in children) { diff --git a/src/component/fiber.ts b/src/component/fiber.ts index dc6b2ba3..e981b9d8 100644 --- a/src/component/fiber.ts +++ b/src/component/fiber.ts @@ -249,7 +249,9 @@ export class Fiber { component.__owl__.pvnode!.elm = component.__owl__.vnode!.elm; } } - component.__owl__.currentFiber = null; + if (fiber === component.__owl__.currentFiber) { + component.__owl__.currentFiber = null; + } } // insert into the DOM (mount case) diff --git a/tests/component/component.test.ts b/tests/component/component.test.ts index e731c1c3..27e1ed0f 100644 --- a/tests/component/component.test.ts +++ b/tests/component/component.test.ts @@ -3064,6 +3064,36 @@ describe("random stuff/miscellaneous", () => { await nextTick(); expect(fixture.textContent!.trim()).toBe("2__3"); }); + + test("two renderings initiated between willPatch and patched", async () => { + let app; + + class Panel extends Component { + static template = xml``; + mounted() { + app.render(); + } + willUnmount() { + app.render(); + } + } + + // Main root component + class App extends Component { + static components = { Panel }; + static template = xml`
`; + + state = useState({ panel: "Panel1" }); + } + + app = new App(); + await app.mount(fixture); + + expect(fixture.innerHTML).toBe("
Panel1
"); + app.state.panel = "Panel2"; + await nextTick(); + expect(fixture.innerHTML).toBe("
Panel2
"); + }); }); describe("widget and observable state", () => {