Skip to content

Commit

Permalink
fix(compiler-core): template v-if should never be treated as dev root…
Browse files Browse the repository at this point in the history
… fragment

close vuejs#5189
  • Loading branch information
yyx990803 authored and iwusong committed May 13, 2022
1 parent 1b213c6 commit ca38b2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/compiler-core/src/ast.ts
Expand Up @@ -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 {
Expand Down
16 changes: 6 additions & 10 deletions packages/compiler-core/src/transforms/vIf.ts
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -272,13 +271,10 @@ function createChildrenCodegenNode(
let patchFlagText = PatchFlagNames[PatchFlags.STABLE_FRAGMENT]
// check if the fragment actually contains a single valid child with
// the rest being comments
const commentNodeCount = children.filter(
c => c.type === NodeTypes.COMMENT
).length
if (
__DEV__ &&
commentNodeCount &&
children.length - commentNodeCount === 1
!branch.isTemplateIf &&
children.filter(c => c.type !== NodeTypes.COMMENT).length === 1
) {
patchFlag |= PatchFlags.DEV_ROOT_FRAGMENT
patchFlagText += `, ${PatchFlagNames[PatchFlags.DEV_ROOT_FRAGMENT]}`
Expand Down

0 comments on commit ca38b2f

Please sign in to comment.