Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Teleport SVG elements #2648

Merged
merged 6 commits into from
Nov 30, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ export const TeleportImpl = {

const disabled = isTeleportDisabled(n2.props)
const { shapeFlag, children } = n2
// Verify whether the target is an SVGElement or not.
const targetIsSVG = (target: RendererElement) => {
Copy link
Member

@edison1105 edison1105 Nov 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use isSVGTag(target.tag) instead of this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return Boolean(
target && (target instanceof SVGElement || target.ownerSVGElement)
)
}

if (n1 == null) {
// insert anchors in the main view
const placeholder = (n2.el = __DEV__
Expand All @@ -90,11 +97,11 @@ export const TeleportImpl = {
: createText(''))
insert(placeholder, container, anchor)
insert(mainAnchor, container, anchor)

const target = (n2.target = resolveTarget(n2.props, querySelector))
const targetAnchor = (n2.targetAnchor = createText(''))
if (target) {
insert(targetAnchor, target)
isSVG = isSVG || targetIsSVG(target)
} else if (__DEV__ && !disabled) {
warn('Invalid Teleport target on mount:', target, `(${typeof target})`)
}
Expand Down Expand Up @@ -129,6 +136,7 @@ export const TeleportImpl = {
const wasDisabled = isTeleportDisabled(n1.props)
const currentContainer = wasDisabled ? container : target
const currentAnchor = wasDisabled ? mainAnchor : targetAnchor
isSVG = isSVG || targetIsSVG(target)

if (n2.dynamicChildren) {
// fast path when the teleport happens to be a block root
Expand Down