From 233d191d0d33802cdf7e2996569372a6442e236a Mon Sep 17 00:00:00 2001 From: zhangzhonghe <38434641+zhangzhonghe@users.noreply.github.com> Date: Thu, 6 Aug 2020 21:42:52 +0800 Subject: [PATCH] fix(keep-alive): fix activated hook invocation on nested components (#1743) fix #1742 --- .../__tests__/components/KeepAlive.spec.ts | 30 +++++++++++++++++++ packages/runtime-core/src/renderer.ts | 5 +++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/components/KeepAlive.spec.ts b/packages/runtime-core/__tests__/components/KeepAlive.spec.ts index f75bb039c4e..8eee2c05e6b 100644 --- a/packages/runtime-core/__tests__/components/KeepAlive.spec.ts +++ b/packages/runtime-core/__tests__/components/KeepAlive.spec.ts @@ -165,6 +165,36 @@ describe('KeepAlive', () => { assertHookCalls(two, [1, 1, 2, 2, 0]) }) + // #1742 + test('should call lifecycle hooks on nested components when root component no hooks', async () => { + const two = { + name: 'two', + data: () => ({ msg: 'two' }), + render(this: any) { + return h('div', this.msg) + }, + activated: jest.fn() + } + const one = { + name: 'one', + data: () => ({ msg: 'one' }), + render(this: any) { + return h(two) + } + } + + const toggle = ref(true) + const App = { + render() { + return h(KeepAlive, () => (toggle.value ? h(one) : null)) + } + } + render(h(App), root) + + expect(serializeInner(root)).toBe(`