MCPcopy
hub / github.com/vuejs/core / renderToString

Function renderToString

packages/server-renderer/src/renderToString.ts:70–97  ·  view source on GitHub ↗
(
  input: App | VNode,
  context: SSRContext = {},
)

Source from the content-addressed store, hash-verified

68}
69
70export 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
99export async function resolveTeleports(context: SSRContext): Promise<void> {
100 if (context.__teleportBuffers) {

Callers 15

testRenderFunction · 0.90
ssrSlot.spec.tsFile · 0.90
ssrScopeId.spec.tsFile · 0.90
ssrWatch.spec.tsFile · 0.90
renderOnceFunction · 0.90

Calls 5

renderComponentVNodeFunction · 0.90
isVNodeFunction · 0.85
resolveTeleportsFunction · 0.85
provideMethod · 0.80
unrollBufferFunction · 0.70

Tested by 3

testRenderFunction · 0.72
renderOnceFunction · 0.72
runOnServerFunction · 0.72