fix(compiler-core): dynamic component should always be made blocks

since it can potentially resolve to plain elements

fix #1018
This commit is contained in:
Evan You 2020-04-22 14:44:45 -04:00
parent 0bdd889156
commit 7d0ab3392a

View File

@ -20,7 +20,13 @@ import {
DirectiveArguments, DirectiveArguments,
createVNodeCall createVNodeCall
} from '../ast' } from '../ast'
import { PatchFlags, PatchFlagNames, isSymbol, isOn } from '@vue/shared' import {
PatchFlags,
PatchFlagNames,
isSymbol,
isOn,
isObject
} from '@vue/shared'
import { createCompilerError, ErrorCodes } from '../errors' import { createCompilerError, ErrorCodes } from '../errors'
import { import {
RESOLVE_DIRECTIVE, RESOLVE_DIRECTIVE,
@ -68,6 +74,8 @@ export const transformElement: NodeTransform = (node, context) => {
const vnodeTag = isComponent const vnodeTag = isComponent
? resolveComponentType(node as ComponentNode, context) ? resolveComponentType(node as ComponentNode, context)
: `"${tag}"` : `"${tag}"`
const isDynamicComponent =
isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT
let vnodeProps: VNodeCall['props'] let vnodeProps: VNodeCall['props']
let vnodeChildren: VNodeCall['children'] let vnodeChildren: VNodeCall['children']
@ -78,15 +86,17 @@ export const transformElement: NodeTransform = (node, context) => {
let vnodeDirectives: VNodeCall['directives'] let vnodeDirectives: VNodeCall['directives']
let shouldUseBlock = let shouldUseBlock =
!isComponent && // dynamic component may resolve to plain elements
// <svg> and <foreignObject> must be forced into blocks so that block isDynamicComponent ||
// updates inside get proper isSVG flag at runtime. (#639, #643) (!isComponent &&
// This is technically web-specific, but splitting the logic out of core // <svg> and <foreignObject> must be forced into blocks so that block
// leads to too much unnecessary complexity. // updates inside get proper isSVG flag at runtime. (#639, #643)
(tag === 'svg' || // This is technically web-specific, but splitting the logic out of core
tag === 'foreignObject' || // leads to too much unnecessary complexity.
// #938: elements with dynamic keys should be forced into blocks (tag === 'svg' ||
findProp(node, 'key', true)) tag === 'foreignObject' ||
// #938: elements with dynamic keys should be forced into blocks
findProp(node, 'key', true)))
// props // props
if (props.length > 0) { if (props.length > 0) {