Skip to content
Merged
Show file tree
Hide file tree
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: 30 additions & 0 deletions packages/runtime-core/__tests__/components/Teleport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,36 @@ describe('renderer: teleport', () => {
)
})

test('should work when using template ref as target', async () => {
const root = nodeOps.createElement('div')
const target = ref(null)
const disabled = ref(true)

const App = {
setup() {
return () =>
h(Fragment, [
h('div', { ref: target }),
h(
Teleport,
{ to: target.value, disabled: disabled.value },
h('div', 'teleported')
)
])
}
}
render(h(App), root)
expect(serializeInner(root)).toMatchInlineSnapshot(
`"<div></div><!--teleport start--><div>teleported</div><!--teleport end-->"`
)

disabled.value = false
await nextTick()
expect(serializeInner(root)).toMatchInlineSnapshot(
`"<div><div>teleported</div></div><!--teleport start--><!--teleport end-->"`
)
})

test('disabled', () => {
const target = nodeOps.createElement('div')
const root = nodeOps.createElement('div')
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { warn } from '../warning'
export type TeleportVNode = VNode<RendererNode, RendererElement, TeleportProps>

export interface TeleportProps {
to: string | RendererElement
to: string | RendererElement | null | undefined
disabled?: boolean
}

Expand Down Expand Up @@ -50,7 +50,7 @@ const resolveTarget = <T = RendererElement>(
return target as any
}
} else {
if (__DEV__ && !targetSelector) {
if (__DEV__ && !targetSelector && !isTeleportDisabled(props)) {
warn(`Invalid Teleport target: ${targetSelector}`)
}
return targetSelector as any
Expand Down Expand Up @@ -94,7 +94,7 @@ export const TeleportImpl = {
const targetAnchor = (n2.targetAnchor = createText(''))
if (target) {
insert(targetAnchor, target)
} else if (__DEV__) {
} else if (__DEV__ && !disabled) {
warn('Invalid Teleport target on mount:', target, `(${typeof target})`)
}

Expand Down