From ec63623fe8d395e1cd759f27b90b1ccc1b616931 Mon Sep 17 00:00:00 2001 From: likui <2218301630@qq.com> Date: Wed, 22 Jan 2020 23:45:27 +0800 Subject: [PATCH] fix: Suspense should include into dynamic children (#653) fix #649 --- packages/runtime-core/__tests__/vnode.spec.ts | 35 ++++++++++++++++++- packages/runtime-core/src/vnode.ts | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/vnode.spec.ts b/packages/runtime-core/__tests__/vnode.spec.ts index 656d2764..ea9fc02b 100644 --- a/packages/runtime-core/__tests__/vnode.spec.ts +++ b/packages/runtime-core/__tests__/vnode.spec.ts @@ -232,7 +232,7 @@ describe('vnode', () => { }) describe('dynamic children', () => { - test('single call openBlock', () => { + test('with patchFlags', () => { const hoist = createVNode('div') let vnode1 const vnode = (openBlock(), @@ -259,5 +259,38 @@ describe('vnode', () => { expect(vnode.dynamicChildren).toStrictEqual([vnode1, vnode2]) expect(vnode2.dynamicChildren).toStrictEqual([vnode3]) }) + + test('with stateful component', () => { + const hoist = createVNode('div') + let vnode1 + const vnode = (openBlock(), + createBlock('div', null, [ + hoist, + (vnode1 = createVNode({}, null, 'text')) + ])) + expect(vnode.dynamicChildren).toStrictEqual([vnode1]) + }) + + test('with functional component', () => { + const hoist = createVNode('div') + let vnode1 + const vnode = (openBlock(), + createBlock('div', null, [ + hoist, + (vnode1 = createVNode(() => {}, null, 'text')) + ])) + expect(vnode.dynamicChildren).toStrictEqual([vnode1]) + }) + + test('with suspense', () => { + const hoist = createVNode('div') + let vnode1 + const vnode = (openBlock(), + createBlock('div', null, [ + hoist, + (vnode1 = createVNode(() => {}, null, 'text')) + ])) + expect(vnode.dynamicChildren).toStrictEqual([vnode1]) + }) }) }) diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 1f08d5ca..33c177d6 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -274,6 +274,7 @@ export function createVNode( shouldTrack > 0 && currentBlock !== null && (patchFlag > 0 || + shapeFlag & ShapeFlags.SUSPENSE || shapeFlag & ShapeFlags.STATEFUL_COMPONENT || shapeFlag & ShapeFlags.FUNCTIONAL_COMPONENT) ) {