]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): fix v-if block handling for components that fail to resolve
authorEvan You <yyx990803@gmail.com>
Mon, 14 Sep 2020 16:41:35 +0000 (12:41 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 14 Sep 2020 16:41:35 +0000 (12:41 -0400)
fix #2058

packages/compiler-core/__tests__/transforms/vIf.spec.ts
packages/compiler-core/src/transforms/vIf.ts

index a93c6053e1ceb15b1a1dda7e4b571f462deff8b2..315497a590c4d7b0c93efe35412eb6b43d1d5384 100644 (file)
@@ -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', () => {
index bebf3eb9082525d17217b774f72d84078fe63e40..2c00349254d3adef61dd63cd0b1f185c4966e92e 100644 (file)
@@ -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)