diff --git a/packages/x6-vue-shape/src/teleport.ts b/packages/x6-vue-shape/src/teleport.ts index a6f957f3762..8bbc27fb4ab 100644 --- a/packages/x6-vue-shape/src/teleport.ts +++ b/packages/x6-vue-shape/src/teleport.ts @@ -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' @@ -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, @@ -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, @@ -51,4 +74,5 @@ export function getTeleport(): any { ) }, }) + return itemComponets }