diff --git a/src/component/component.ts b/src/component/component.ts index dabf8897..01ce6511 100644 --- a/src/component/component.ts +++ b/src/component/component.ts @@ -400,6 +400,7 @@ export class Component { if (currentFiber && !currentFiber.isRendered && !currentFiber.isCompleted) { return scheduler.addFiber(currentFiber.root); } + // if we aren't mounted at this point, it implies that there is a // currentFiber that is already rendered (isRendered is true), so we are // about to be mounted @@ -505,7 +506,6 @@ export class Component { const __owl__ = this.__owl__; __owl__.status = STATUS.MOUNTED; - __owl__.currentFiber = null; this.mounted(); if (__owl__.mountedCB) { __owl__.mountedCB(); diff --git a/src/component/fiber.ts b/src/component/fiber.ts index 07150a91..9ad25c06 100644 --- a/src/component/fiber.ts +++ b/src/component/fiber.ts @@ -198,6 +198,7 @@ export class Fiber { // build patchQueue const patchQueue: Fiber[] = []; const doWork: (Fiber) => Fiber | null = function (f) { + f.component.__owl__.currentFiber = null; patchQueue.push(f); return f.child; }; @@ -255,10 +256,6 @@ export class Fiber { component.__owl__.pvnode!.elm = component.__owl__.vnode!.elm; } } - const compOwl = component.__owl__; - if (fiber === compOwl.currentFiber) { - compOwl.currentFiber = null; - } } // insert into the DOM (mount case) diff --git a/tests/component/async.test.ts b/tests/component/async.test.ts index 1425c558..74fdb451 100644 --- a/tests/component/async.test.ts +++ b/tests/component/async.test.ts @@ -1388,6 +1388,62 @@ describe("async rendering", () => { expect(fixture.innerHTML).toBe("4"); }); + test("calling render in destroy", async () => { + let a: any = null; + let c: any = null; + + class C extends Component { + static template = xml` +
+ +
`; + } + + let flag = false; + class B extends Component { + static template = xml``; + static components = { C }; + + setup() { + c = this; + } + + mounted() { + if (flag) { + this.render(); + } else { + flag = true; + } + } + willUnmount() { + c.render(); + } + } + + class A extends Component { + static template = xml``; + static components = { B }; + state = "a"; + key = 1; + + setup() { + a = this; + } + } + + const parent = new A(); + await parent.mount(fixture); + expect(fixture.innerHTML).toBe("
a
"); + + a.state = "A"; + a.key = 2; + await a.render(); + // this nextTick is critical, otherwise jest may silently swallow errors + await nextTick(); + + expect(fixture.innerHTML).toBe("
A
"); + }); + test("change state and call manually render: no unnecessary rendering", async () => { class Widget extends Component { static template = xml`
`;