| 68 | } |
| 69 | |
| 70 | export async function renderToString( |
| 71 | input: App | VNode, |
| 72 | context: SSRContext = {}, |
| 73 | ): Promise<string> { |
| 74 | if (isVNode(input)) { |
| 75 | // raw vnode, wrap with app (for context) |
| 76 | return renderToString(createApp({ render: () => input }), context) |
| 77 | } |
| 78 | |
| 79 | // rendering an app |
| 80 | const vnode = createVNode(input._component, input._props) |
| 81 | vnode.appContext = input._context |
| 82 | // provide the ssr context to the tree |
| 83 | input.provide(ssrContextKey, context) |
| 84 | const buffer = await renderComponentVNode(vnode) |
| 85 | |
| 86 | const result = await unrollBuffer(buffer as SSRBuffer) |
| 87 | |
| 88 | await resolveTeleports(context) |
| 89 | |
| 90 | if (context.__watcherHandles) { |
| 91 | for (const unwatch of context.__watcherHandles) { |
| 92 | unwatch() |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return result |
| 97 | } |
| 98 | |
| 99 | export async function resolveTeleports(context: SSRContext): Promise<void> { |
| 100 | if (context.__teleportBuffers) { |