From a096a58e412dc37ae618a3b4702f591c580d376a Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 14 Sep 2020 12:41:35 -0400 Subject: [PATCH] fix(compiler-core): fix v-if block handling for components that fail to resolve fix #2058 --- .../compiler-core/__tests__/transforms/vIf.spec.ts | 4 +++- packages/compiler-core/src/transforms/vIf.ts | 12 ++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/vIf.spec.ts b/packages/compiler-core/__tests__/transforms/vIf.spec.ts index a93c6053..315497a5 100644 --- a/packages/compiler-core/__tests__/transforms/vIf.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vIf.spec.ts @@ -93,10 +93,12 @@ describe('compiler: v-if', () => { expect((node.branches[0].children[0] as ElementNode).tagType).toBe( ElementTypes.COMPONENT ) + // #2058 since a component may fail to resolve and fallback to a plain + // element, it still needs to be made a block expect( ((node.branches[0].children[0] as ElementNode)! .codegenNode as VNodeCall)!.isBlock - ).toBe(false) + ).toBe(true) }) test('v-if + v-else', () => { diff --git a/packages/compiler-core/src/transforms/vIf.ts b/packages/compiler-core/src/transforms/vIf.ts index bebf3eb9..2c003492 100644 --- a/packages/compiler-core/src/transforms/vIf.ts +++ b/packages/compiler-core/src/transforms/vIf.ts @@ -29,8 +29,7 @@ import { CREATE_BLOCK, FRAGMENT, CREATE_COMMENT, - OPEN_BLOCK, - TELEPORT + OPEN_BLOCK } from '../runtimeHelpers' import { injectProp, findDir, findProp } from '../utils' import { PatchFlags, PatchFlagNames } from '@vue/shared' @@ -255,14 +254,7 @@ function createChildrenCodegenNode( const vnodeCall = (firstChild as ElementNode) .codegenNode as BlockCodegenNode // Change createVNode to createBlock. - if ( - vnodeCall.type === NodeTypes.VNODE_CALL && - // component vnodes are always tracked and its children are - // compiled into slots so no need to make it a block - ((firstChild as ElementNode).tagType !== ElementTypes.COMPONENT || - // teleport has component type but isn't always tracked - vnodeCall.tag === TELEPORT) - ) { + if (vnodeCall.type === NodeTypes.VNODE_CALL) { vnodeCall.isBlock = true helper(OPEN_BLOCK) helper(CREATE_BLOCK)