fix(dom): fix <svg> and <foreignObject> mount and updates

This commit is contained in:
Evan You
2020-01-21 11:32:17 -05:00
parent da8c31dc7f
commit 4f06eebc1c
3 changed files with 85 additions and 13 deletions

View File

@@ -70,9 +70,7 @@ export const transformElement: NodeTransform = (node, context) => {
let runtimeDirectives: DirectiveNode[] | undefined
let dynamicPropNames: string[] | undefined
let dynamicComponent: string | CallExpression | undefined
// technically this is web specific but we are keeping it in core to avoid
// extra complexity
let isSVG = false
let shouldUseBlock = false
// handle dynamic component
const isProp = findProp(node, 'is')
@@ -110,8 +108,12 @@ export const transformElement: NodeTransform = (node, context) => {
nodeType = toValidAssetId(tag, `component`)
} else {
// plain element
nodeType = `"${node.tag}"`
isSVG = node.tag === 'svg'
nodeType = `"${tag}"`
// <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.
shouldUseBlock = tag === 'svg' || tag === 'foreignObject'
}
const args: CallExpression['arguments'] = [nodeType]
@@ -197,10 +199,8 @@ export const transformElement: NodeTransform = (node, context) => {
}
const { loc } = node
const vnode = isSVG
? // <svg> must be forced into blocks so that block updates inside retain
// isSVG flag at runtime. (#639, #643)
createSequenceExpression([
const vnode = shouldUseBlock
? createSequenceExpression([
createCallExpression(context.helper(OPEN_BLOCK)),
createCallExpression(context.helper(CREATE_BLOCK), args, loc)
])