Repository: vuejs/vue-next
File: packages/runtime-core/src/components/Teleport.ts (TypeScript)

Code before:
          if (
            targetAnchor &&
            targetAnchor.nodeType === 8 &&
            (targetAnchor as Comment).data === 'teleport anchor'
          ) {
            vnode.targetAnchor = targetAnchor
            ;(target as TeleportTargetElement)._lpa =
              vnode.targetAnchor && nextSibling(vnode.targetAnchor as Node)
            break
          }
        }

        hydrateChildren(
          targetNode,
          vnode,
          target,
          parentComponent,
          parentSuspense,
          slotScopeIds,
          optimized,
        )
      }
    }
    updateCssVars(vnode)
  }
  if (!target && isTeleportDisabled(vnode.props)) {
    const targetNode = nextSibling(node)
    if (vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
      vnode.anchor = hydrateChildren(
        nextSibling(node),
        vnode,
        parentNode(node)!,
        parentComponent,
        parentSuspense,
        slotScopeIds,
        optimized,
      )
      vnode.targetAnchor = targetNode
    }
  }
  return vnode.anchor && nextSibling(vnode.anchor as Node)
}

// Force-casted public typing for h and TSX props inference
export const Teleport = TeleportImpl as unknown as {
  __isTeleport: true
  new (): {
    $props: VNodeProps & TeleportProps
    $slots: {
      default(): VNode[]
    }

Review comment (performance):
```suggestion
  else if (isTeleportDisabled(vnode.props)) {
    if (vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
      vnode.anchor = hydrateChildren(
        nextSibling(node),
        vnode,
        parentNode(node)!,
        parentComponent,
        parentSuspense,
        slotScopeIds,
        optimized,
      )
      vnode.targetStart = node
      vnode.targetAnchor = nextSibling(node)
    }
  }
```

Code after:
interface TeleportTargetElement extends Element {
  // last teleport target
  _lpa?: Node | null
}

function hydrateTeleport(
  node: Node,
  vnode: TeleportVNode,
  parentComponent: ComponentInternalInstance | null,
  parentSuspense: SuspenseBoundary | null,
  slotScopeIds: string[] | null,
  optimized: boolean,
  {
    o: { nextSibling, parentNode, querySelector, insert, createText },
  }: RendererInternals<Node, Element>,
  hydrateChildren: (
    node: Node | null,
    vnode: VNode,
    container: Element,
    parentComponent: ComponentInternalInstance | null,
    parentSuspense: SuspenseBoundary | null,
    slotScopeIds: string[] | null,
    optimized: boolean,
  ) => Node | null,
): Node | null {
  function hydrateDisabledTeleport(
    node: Node,
    vnode: VNode,
    targetStart: Node | null,
    targetAnchor: Node | null,
  ) {
    vnode.anchor = hydrateChildren(
      nextSibling(node),
      vnode,
      parentNode(node)!,
      parentComponent,
      parentSuspense,
      slotScopeIds,
      optimized,
    )
    vnode.targetStart = targetStart
    vnode.targetAnchor = targetAnchor
  }

  const target = (vnode.target = resolveTarget<Element>(
    vnode.props,
    querySelector,
  ))
  const disabled = isTeleportDisabled(vnode.props)
  if (target) {
    // if multiple teleports rendered to the same target element, we need to