Skip to content

Commit

Permalink
fix(compiler-core): fix v-if block handling for components that fail …
Browse files Browse the repository at this point in the history
…to resolve

fix #2058
  • Loading branch information
yyx990803 committed Sep 14, 2020
1 parent 24fcf6a commit a096a58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/compiler-core/__tests__/transforms/vIf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
12 changes: 2 additions & 10 deletions packages/compiler-core/src/transforms/vIf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a096a58

Please sign in to comment.