fix(compiler-core): fix v-if block handling for components that fail to resolve
fix #2058
This commit is contained in:
parent
24fcf6ae7c
commit
a096a58e41
@ -93,10 +93,12 @@ describe('compiler: v-if', () => {
|
|||||||
expect((node.branches[0].children[0] as ElementNode).tagType).toBe(
|
expect((node.branches[0].children[0] as ElementNode).tagType).toBe(
|
||||||
ElementTypes.COMPONENT
|
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(
|
expect(
|
||||||
((node.branches[0].children[0] as ElementNode)!
|
((node.branches[0].children[0] as ElementNode)!
|
||||||
.codegenNode as VNodeCall)!.isBlock
|
.codegenNode as VNodeCall)!.isBlock
|
||||||
).toBe(false)
|
).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('v-if + v-else', () => {
|
test('v-if + v-else', () => {
|
||||||
|
@ -29,8 +29,7 @@ import {
|
|||||||
CREATE_BLOCK,
|
CREATE_BLOCK,
|
||||||
FRAGMENT,
|
FRAGMENT,
|
||||||
CREATE_COMMENT,
|
CREATE_COMMENT,
|
||||||
OPEN_BLOCK,
|
OPEN_BLOCK
|
||||||
TELEPORT
|
|
||||||
} from '../runtimeHelpers'
|
} from '../runtimeHelpers'
|
||||||
import { injectProp, findDir, findProp } from '../utils'
|
import { injectProp, findDir, findProp } from '../utils'
|
||||||
import { PatchFlags, PatchFlagNames } from '@vue/shared'
|
import { PatchFlags, PatchFlagNames } from '@vue/shared'
|
||||||
@ -255,14 +254,7 @@ function createChildrenCodegenNode(
|
|||||||
const vnodeCall = (firstChild as ElementNode)
|
const vnodeCall = (firstChild as ElementNode)
|
||||||
.codegenNode as BlockCodegenNode
|
.codegenNode as BlockCodegenNode
|
||||||
// Change createVNode to createBlock.
|
// Change createVNode to createBlock.
|
||||||
if (
|
if (vnodeCall.type === NodeTypes.VNODE_CALL) {
|
||||||
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)
|
|
||||||
) {
|
|
||||||
vnodeCall.isBlock = true
|
vnodeCall.isBlock = true
|
||||||
helper(OPEN_BLOCK)
|
helper(OPEN_BLOCK)
|
||||||
helper(CREATE_BLOCK)
|
helper(CREATE_BLOCK)
|
||||||
|
Loading…
Reference in New Issue
Block a user