Skip to content

Commit

Permalink
fix(ssr): render teleport inside async component (#5187)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Jedli膷ka committed May 13, 2022
1 parent 31c0bb3 commit 4d7803e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/server-renderer/__tests__/ssrTeleport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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><!---->`)
})
})
4 changes: 3 additions & 1 deletion packages/server-renderer/src/renderToString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4d7803e

Please sign in to comment.