fix(ssr): render teleport inside async component (#5187)

This commit is contained in:
Adam Jedlička 2022-05-13 09:57:10 +02:00 committed by GitHub
parent 31c0bb355a
commit 4d7803ed28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -117,4 +117,21 @@ describe('ssrRenderTeleport', () => {
'<span>hello</span><!---->world<!---->'
)
})
test('teleport inside async component', async () => {
const ctx: SSRContext = {}
const asyncComponent = {
template: '<teleport to="#target"><div>content</div></teleport>',
async setup() {}
}
const html = await renderToString(
h({
template: '<async-component />',
components: { asyncComponent }
}),
ctx
)
expect(html).toBe('<!--teleport start--><!--teleport end-->')
expect(ctx.teleports!['#target']).toBe(`<div>content</div><!---->`)
})
})

View File

@ -63,9 +63,11 @@ export async function renderToString(
input.provide(ssrContextKey, context)
const buffer = await renderComponentVNode(vnode)
const result = await unrollBuffer(buffer as SSRBuffer)
await resolveTeleports(context)
return unrollBuffer(buffer as SSRBuffer)
return result
}
async function resolveTeleports(context: SSRContext) {