From 4d7803ed28fb67d45a83d3500f5407754e65bf64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Jedli=C4=8Dka?= Date: Fri, 13 May 2022 09:57:10 +0200 Subject: [PATCH] fix(ssr): render teleport inside async component (#5187) --- .../__tests__/ssrTeleport.spec.ts | 17 +++++++++++++++++ packages/server-renderer/src/renderToString.ts | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/server-renderer/__tests__/ssrTeleport.spec.ts b/packages/server-renderer/__tests__/ssrTeleport.spec.ts index fda95918..f26c9035 100644 --- a/packages/server-renderer/__tests__/ssrTeleport.spec.ts +++ b/packages/server-renderer/__tests__/ssrTeleport.spec.ts @@ -117,4 +117,21 @@ describe('ssrRenderTeleport', () => { 'helloworld' ) }) + + test('teleport inside async component', async () => { + const ctx: SSRContext = {} + const asyncComponent = { + template: '
content
', + async setup() {} + } + const html = await renderToString( + h({ + template: '', + components: { asyncComponent } + }), + ctx + ) + expect(html).toBe('') + expect(ctx.teleports!['#target']).toBe(`
content
`) + }) }) diff --git a/packages/server-renderer/src/renderToString.ts b/packages/server-renderer/src/renderToString.ts index cf6e9759..f35ee9d6 100644 --- a/packages/server-renderer/src/renderToString.ts +++ b/packages/server-renderer/src/renderToString.ts @@ -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) {