Skip to content

Commit 7d0ab33

Browse files
committed
fix(compiler-core): dynamic component should always be made blocks
since it can potentially resolve to plain elements fix #1018
1 parent 0bdd889 commit 7d0ab33

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

packages/compiler-core/src/transforms/transformElement.ts

+20-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ import {
2020
DirectiveArguments,
2121
createVNodeCall
2222
} from '../ast'
23-
import { PatchFlags, PatchFlagNames, isSymbol, isOn } from '@vue/shared'
23+
import {
24+
PatchFlags,
25+
PatchFlagNames,
26+
isSymbol,
27+
isOn,
28+
isObject
29+
} from '@vue/shared'
2430
import { createCompilerError, ErrorCodes } from '../errors'
2531
import {
2632
RESOLVE_DIRECTIVE,
@@ -68,6 +74,8 @@ export const transformElement: NodeTransform = (node, context) => {
6874
const vnodeTag = isComponent
6975
? resolveComponentType(node as ComponentNode, context)
7076
: `"${tag}"`
77+
const isDynamicComponent =
78+
isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT
7179

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

8088
let shouldUseBlock =
81-
!isComponent &&
82-
// <svg> and <foreignObject> must be forced into blocks so that block
83-
// updates inside get proper isSVG flag at runtime. (#639, #643)
84-
// This is technically web-specific, but splitting the logic out of core
85-
// leads to too much unnecessary complexity.
86-
(tag === 'svg' ||
87-
tag === 'foreignObject' ||
88-
// #938: elements with dynamic keys should be forced into blocks
89-
findProp(node, 'key', true))
89+
// dynamic component may resolve to plain elements
90+
isDynamicComponent ||
91+
(!isComponent &&
92+
// <svg> and <foreignObject> must be forced into blocks so that block
93+
// updates inside get proper isSVG flag at runtime. (#639, #643)
94+
// This is technically web-specific, but splitting the logic out of core
95+
// leads to too much unnecessary complexity.
96+
(tag === 'svg' ||
97+
tag === 'foreignObject' ||
98+
// #938: elements with dynamic keys should be forced into blocks
99+
findProp(node, 'key', true)))
90100

91101
// props
92102
if (props.length > 0) {

0 commit comments

Comments
 (0)