Skip to content

Commit a096a58

Browse files
committed
fix(compiler-core): fix v-if block handling for components that fail to resolve
fix #2058
1 parent 24fcf6a commit a096a58

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ describe('compiler: v-if', () => {
9393
expect((node.branches[0].children[0] as ElementNode).tagType).toBe(
9494
ElementTypes.COMPONENT
9595
)
96+
// #2058 since a component may fail to resolve and fallback to a plain
97+
// element, it still needs to be made a block
9698
expect(
9799
((node.branches[0].children[0] as ElementNode)!
98100
.codegenNode as VNodeCall)!.isBlock
99-
).toBe(false)
101+
).toBe(true)
100102
})
101103

102104
test('v-if + v-else', () => {

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

+2-10
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ import {
2929
CREATE_BLOCK,
3030
FRAGMENT,
3131
CREATE_COMMENT,
32-
OPEN_BLOCK,
33-
TELEPORT
32+
OPEN_BLOCK
3433
} from '../runtimeHelpers'
3534
import { injectProp, findDir, findProp } from '../utils'
3635
import { PatchFlags, PatchFlagNames } from '@vue/shared'
@@ -255,14 +254,7 @@ function createChildrenCodegenNode(
255254
const vnodeCall = (firstChild as ElementNode)
256255
.codegenNode as BlockCodegenNode
257256
// Change createVNode to createBlock.
258-
if (
259-
vnodeCall.type === NodeTypes.VNODE_CALL &&
260-
// component vnodes are always tracked and its children are
261-
// compiled into slots so no need to make it a block
262-
((firstChild as ElementNode).tagType !== ElementTypes.COMPONENT ||
263-
// teleport has component type but isn't always tracked
264-
vnodeCall.tag === TELEPORT)
265-
) {
257+
if (vnodeCall.type === NodeTypes.VNODE_CALL) {
266258
vnodeCall.isBlock = true
267259
helper(OPEN_BLOCK)
268260
helper(CREATE_BLOCK)

0 commit comments

Comments
 (0)