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(vue-shape): vue-shape's teleport is only registered once #4500

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
30 changes: 27 additions & 3 deletions packages/x6-vue-shape/src/teleport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { defineComponent, h, reactive, isVue3, Teleport, markRaw, Fragment } from 'vue-demi'
import {
defineComponent,
h,
reactive,
isVue3,
Teleport,
markRaw,
Fragment,
onBeforeUnmount,
} from 'vue-demi'
import { Graph } from '@antv/x6'
import { VueShape } from './node'

Expand All @@ -15,7 +24,10 @@ export function connect(
if (active) {
items[id] = markRaw(
defineComponent({
render: () => h(Teleport, { to: container } as any, [h(component, { node, graph })]),
render: () =>
h(Teleport, { to: container } as any, [
h(component, { node, graph }),
]),
provide: () => ({
getNode: () => node,
getGraph: () => graph,
Expand All @@ -35,14 +47,25 @@ export function isActive() {
return active
}

let itemComponets: any = null

export function getTeleport(): any {
if (!isVue3) {
throw new Error('teleport is only available in Vue3')
}

if (itemComponets && active) {
return null
}

active = true

return defineComponent({
itemComponets = defineComponent({
setup() {
onBeforeUnmount(() => {
itemComponets = null
})

return () =>
h(
Fragment,
Expand All @@ -51,4 +74,5 @@ export function getTeleport(): any {
)
},
})
return itemComponets
}
Loading