fix(compiler-core): template v-if should never be treated as dev root fragment

close #5189
This commit is contained in:
Evan You
2022-05-11 17:43:17 +08:00
parent b7025d24f1
commit 51f3d386de
4 changed files with 10 additions and 9 deletions

View File

@@ -259,6 +259,7 @@ export interface IfBranchNode extends Node {
condition: ExpressionNode | undefined // else
children: TemplateChildNode[]
userKey?: AttributeNode | DirectiveNode
isTemplateIf?: boolean
}
export interface ForNode extends Node {

View File

@@ -209,15 +209,14 @@ export function processIf(
}
function createIfBranch(node: ElementNode, dir: DirectiveNode): IfBranchNode {
const isTemplateIf = node.tagType === ElementTypes.TEMPLATE
return {
type: NodeTypes.IF_BRANCH,
loc: node.loc,
condition: dir.name === 'else' ? undefined : dir.exp,
children:
node.tagType === ElementTypes.TEMPLATE && !findDir(node, 'for')
? node.children
: [node],
userKey: findProp(node, `key`)
children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
userKey: findProp(node, `key`),
isTemplateIf
}
}
@@ -274,6 +273,7 @@ function createChildrenCodegenNode(
// the rest being comments
if (
__DEV__ &&
!branch.isTemplateIf &&
children.filter(c => c.type !== NodeTypes.COMMENT).length === 1
) {
patchFlag |= PatchFlags.DEV_ROOT_FRAGMENT