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
41 changes: 41 additions & 0 deletions packages/runtime-vapor/__tests__/components/Teleport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,47 @@ function runSharedTests(deferMode: boolean): void {
expect(root.innerHTML).toBe('<div>foo</div><!--if-->')
})

test('should remove teleport with insertion parent when toggled off', async () => {
const root = document.createElement('div')
const target = document.createElement('div')
const show = ref(true)

const { mount } = define({
setup() {
return createIf(
() => show.value,
() => {
const n0 = template('<div></div>')()
setInsertionState(n0 as any, null, 0, true)
createComponent(
VaporTeleport,
{
to: () => target,
},
{
default: () => template('<input>')(),
},
)
return n0
},
)
},
}).create()

mount(root)

expect(root.innerHTML).toBe(
'<div><!--teleport start--><!--teleport end--></div><!--if-->',
)
expect(target.innerHTML).toBe('<input>')

show.value = false
await nextTick()

expect(root.innerHTML).toBe('<!--if-->')
expect(target.innerHTML).toBe('')
})

test('unmount previous sibling node inside target node', async () => {
const root = document.createElement('div')
const parentShow = ref(false)
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export function createComponent(
// teleport
if (isVaporTeleport(component)) {
const frag = component.process(rawProps!, rawSlots!)
onScopeDispose(() => remove(frag), true)
if (!isHydrating) {
if (_insertionParent) insert(frag, _insertionParent, _insertionAnchor)
} else {
Expand Down
Loading