fix(compiler-core): template v-if should never be treated as dev root fragment
close #5189
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user