Skip to content

Commit

Permalink
fix(compiler-core): dynamic component should always be made blocks
Browse files Browse the repository at this point in the history
since it can potentially resolve to plain elements

fix #1018
  • Loading branch information
yyx990803 committed Apr 22, 2020
1 parent 0bdd889 commit 7d0ab33
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ import {
DirectiveArguments,
createVNodeCall
} 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 {
RESOLVE_DIRECTIVE,
Expand Down Expand Up @@ -68,6 +74,8 @@ export const transformElement: NodeTransform = (node, context) => {
const vnodeTag = isComponent
? resolveComponentType(node as ComponentNode, context)
: `"${tag}"`
const isDynamicComponent =
isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT

let vnodeProps: VNodeCall['props']
let vnodeChildren: VNodeCall['children']
Expand All @@ -78,15 +86,17 @@ export const transformElement: NodeTransform = (node, context) => {
let vnodeDirectives: VNodeCall['directives']

let shouldUseBlock =
!isComponent &&
// <svg> and <foreignObject> must be forced into blocks so that block
// updates inside get proper isSVG flag at runtime. (#639, #643)
// This is technically web-specific, but splitting the logic out of core
// leads to too much unnecessary complexity.
(tag === 'svg' ||
tag === 'foreignObject' ||
// #938: elements with dynamic keys should be forced into blocks
findProp(node, 'key', true))
// dynamic component may resolve to plain elements
isDynamicComponent ||
(!isComponent &&
// <svg> and <foreignObject> must be forced into blocks so that block
// updates inside get proper isSVG flag at runtime. (#639, #643)
// This is technically web-specific, but splitting the logic out of core
// leads to too much unnecessary complexity.
(tag === 'svg' ||
tag === 'foreignObject' ||
// #938: elements with dynamic keys should be forced into blocks
findProp(node, 'key', true)))

// props
if (props.length > 0) {
Expand Down

0 comments on commit 7d0ab33

Please sign in to comment.