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
39 changes: 39 additions & 0 deletions packages/runtime-vapor/__tests__/components/Teleport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ describe('renderer: VaporTeleport', () => {
expect(root.innerHTML).toBe(
'<!--teleport start--><!--teleport end--><div>root 2</div>',
)
await nextTick()
expect(target.innerHTML).toBe('<div>teleported 2</div>')
})

Expand Down Expand Up @@ -367,6 +368,7 @@ describe('renderer: VaporTeleport', () => {
expect(root.innerHTML).toBe(
'<!--teleport start--><!--teleport end--><div>root 2</div>',
)
await nextTick()
expect(target.innerHTML).toBe('<div>teleported 2</div>')

// reload parent again by changing disabled
Expand Down Expand Up @@ -1255,4 +1257,41 @@ function runSharedTests(deferMode: boolean): void {
expect(child.outerHTML).toBe(`<div>teleported</div>`)
expect(tRefInMounted).toBe(child)
})

test('with insertion state', async () => {
const root = document.createElement('div')
document.body.appendChild(root)

const Comp = defineVaporComponent({
setup() {
return template('content')()
},
})

const { app, mount } = define({
setup() {
const n0 = template('<div id="tt"></div>')()
const n4 = template('<div></div>')() as any
setInsertionState(n4, null, true)
createComponent(
VaporTeleport,
{ to: () => '#tt' },
{
default: () =>
createComponent(Comp, null, {
default: () => template('content')(),
}),
},
)
return [n0, n4]
},
}).create()

mount(root)

await nextTick()
const target = document.querySelector('#tt')!
expect(target.innerHTML).toBe('content')
app.unmount()
})
}
7 changes: 6 additions & 1 deletion packages/runtime-vapor/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ export class TeleportFragment extends VaporFragment {
}
// mount into target container
else {
if (isTeleportDeferred(this.resolvedProps!)) {
if (
isTeleportDeferred(this.resolvedProps!) ||
// force defer when the parent is not connected to the DOM,
// typically due to an early insertion caused by setInsertionState.
!this.parent!.isConnected
) {
queuePostFlushCb(mountToTarget)
} else {
mountToTarget()
Expand Down
Loading